[Avida-SVN] r3533 - in branches/biounit: Avida.xcodeproj source source/actions source/classification source/cpu source/main source/tools
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Wed Nov 18 11:28:02 PST 2009
Author: brysonda
Date: 2009-11-18 14:28:01 -0500 (Wed, 18 Nov 2009)
New Revision: 3533
Added:
branches/biounit/source/tools/tArraySet.h
Modified:
branches/biounit/Avida.xcodeproj/project.pbxproj
branches/biounit/source/actions/PopulationActions.cc
branches/biounit/source/classification/cBGGenotype.cc
branches/biounit/source/classification/cBGGenotype.h
branches/biounit/source/classification/cBioGroup.h
branches/biounit/source/classification/cBioGroupManager.h
branches/biounit/source/classification/cBioUnit.cc
branches/biounit/source/classification/cBioUnit.h
branches/biounit/source/classification/cClassificationManager.cc
branches/biounit/source/cpu/cTestCPU.cc
branches/biounit/source/defs.h
branches/biounit/source/main/cBirthChamber.cc
branches/biounit/source/main/cOrganism.cc
branches/biounit/source/main/cOrganism.h
branches/biounit/source/main/cPopulation.cc
branches/biounit/source/main/cPopulation.h
branches/biounit/source/tools/tArray.h
branches/biounit/source/tools/tArrayMap.h
branches/biounit/source/tools/tKVPair.h
Log:
A whole bunch of work on bio unit:
- Setting cOrganism eBioUnitSource from many locations
- Moved eBioUnitSource to defs.h (from cBioUnit::eUnitSource)
- Added additional unit sources
- Implemented cBioUnit::SelfClassify to handle both asexual and sexual classification
- Added a tArraySet tool
Modified: branches/biounit/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/biounit/Avida.xcodeproj/project.pbxproj 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/Avida.xcodeproj/project.pbxproj 2009-11-18 19:28:01 UTC (rev 3533)
@@ -890,6 +890,7 @@
70B3984E0947B29D0018F09D /* tManagedPointerArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tManagedPointerArray.h; sourceTree = "<group>"; };
70B547FA10AB22920013E999 /* cBGGenotypeManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cBGGenotypeManager.h; sourceTree = "<group>"; };
70B547FB10AB22920013E999 /* cBGGenotypeManager.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cBGGenotypeManager.cc; sourceTree = "<group>"; };
+ 70B549ED10B4791B0013E999 /* tArraySet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tArraySet.h; sourceTree = "<group>"; };
70B6514C0BEA6FAD002472ED /* unit-tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "unit-tests"; sourceTree = BUILT_PRODUCTS_DIR; };
70B984220EBB5B7F00A828B1 /* tDMSingleton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tDMSingleton.h; sourceTree = "<group>"; };
70B9842B0EBB5D4C00A828B1 /* cDMObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cDMObject.h; sourceTree = "<group>"; };
@@ -1745,6 +1746,7 @@
DCC314D8076253A2008F7A48 /* tools */ = {
isa = PBXGroup;
children = (
+ 70B549ED10B4791B0013E999 /* tArraySet.h */,
7020828D0FB9F2DF00637AD6 /* cBitArray.cc */,
7020828E0FB9F2DF00637AD6 /* cBitArray.h */,
2A57A3FD0D6B954D00FC54C7 /* cProbDemeProbSchedule.cc */,
Modified: branches/biounit/source/actions/PopulationActions.cc
===================================================================
--- branches/biounit/source/actions/PopulationActions.cc 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/actions/PopulationActions.cc 2009-11-18 19:28:01 UTC (rev 3533)
@@ -87,7 +87,7 @@
void Process(cAvidaContext& ctx)
{
cGenome genome = cGenomeUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
- m_world->GetPopulation().Inject(genome, m_cell_id, m_merit, m_lineage_label, m_neutral_metric);
+ m_world->GetPopulation().Inject(genome, SRC_ORGANISM_FILE_LOAD, m_cell_id, m_merit, m_lineage_label, m_neutral_metric);
}
};
@@ -131,7 +131,7 @@
void Process(cAvidaContext& ctx)
{
cGenome genome = cGenomeUtil::RandomGenome(ctx, m_length, m_world->GetHardwareManager().GetInstSet());
- m_world->GetPopulation().Inject(genome, m_cell_id, m_merit, m_lineage_label, m_neutral_metric);
+ m_world->GetPopulation().Inject(genome, SRC_ORGANISM_RANDOM, m_cell_id, m_merit, m_lineage_label, m_neutral_metric);
}
};
@@ -181,7 +181,7 @@
genome = cGenomeUtil::RandomGenomeWithoutZeroRedundantsPlusReproSex(ctx, m_length, m_world->GetHardwareManager().GetInstSet());
else
genome = cGenomeUtil::RandomGenomeWithoutZeroRedundantsPlusRepro(ctx, m_length, m_world->GetHardwareManager().GetInstSet());
- m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
+ m_world->GetPopulation().Inject(genome, SRC_ORGANISM_RANDOM, i, m_merit, m_lineage_label, m_neutral_metric);
}
}
};
@@ -226,7 +226,7 @@
{
cGenome genome = cGenomeUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
for (int i = 0; i < m_world->GetPopulation().GetSize(); i++)
- m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
+ m_world->GetPopulation().Inject(genome, SRC_ORGANISM_FILE_LOAD, i, m_merit, m_lineage_label, m_neutral_metric);
}
};
@@ -283,7 +283,7 @@
} else {
cGenome genome = cGenomeUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
for (int i = m_cell_start; i < m_cell_end; i++) {
- m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
+ m_world->GetPopulation().Inject(genome, SRC_ORGANISM_FILE_LOAD, i, m_merit, m_lineage_label, m_neutral_metric);
}
m_world->GetPopulation().SetSyncEvents(true);
}
@@ -341,7 +341,7 @@
} else {
cGenome genome(m_sequence);
for (int i = m_cell_start; i < m_cell_end; i++) {
- m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
+ m_world->GetPopulation().Inject(genome, SRC_ORGANISM_FILE_LOAD, i, m_merit, m_lineage_label, m_neutral_metric);
}
m_world->GetPopulation().SetSyncEvents(true);
}
@@ -402,7 +402,7 @@
} else {
cGenome genome(m_sequence);
for (int i = m_cell_start; i < m_cell_end; i++) {
- m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
+ m_world->GetPopulation().Inject(genome, SRC_ORGANISM_FILE_LOAD, i, m_merit, m_lineage_label, m_neutral_metric);
m_world->GetPopulation().GetCell(i).GetOrganism()->MutationRates().SetDivMutProb(m_div_mut_rate);
}
m_world->GetPopulation().SetSyncEvents(true);
@@ -518,7 +518,7 @@
cGenome genome = cGenomeUtil::LoadGenome(m_filename_genome, m_world->GetHardwareManager().GetInstSet());
cGenome parasite = cGenomeUtil::LoadGenome(m_filename_parasite, m_world->GetHardwareManager().GetInstSet());
for (int i = m_cell_start; i < m_cell_end; i++) {
- m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
+ m_world->GetPopulation().Inject(genome, SRC_ORGANISM_FILE_LOAD, i, m_merit, m_lineage_label, m_neutral_metric);
m_world->GetPopulation().InjectParasite(m_label, parasite, i);
}
m_world->GetPopulation().SetSyncEvents(true);
@@ -569,7 +569,7 @@
cGenome genome = cGenomeUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
for(int i=1; i<m_world->GetPopulation().GetNumDemes(); ++i) { // first org has already been injected
- m_world->GetPopulation().Inject(genome,
+ m_world->GetPopulation().Inject(genome, SRC_ORGANISM_FILE_LOAD,
m_world->GetPopulation().GetDeme(i).GetCellID(0),
m_merit, m_lineage_label, m_neutral_metric);
m_world->GetPopulation().GetDeme(i).IncInjectedCount();
@@ -578,7 +578,7 @@
for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
// WARNING: initial ancestor has already be injected into the population
// calling this will overwrite it.
- m_world->GetPopulation().Inject(genome,
+ m_world->GetPopulation().Inject(genome, SRC_ORGANISM_FILE_LOAD,
m_world->GetPopulation().GetDeme(i).GetCellID(0),
m_merit, m_lineage_label, m_neutral_metric);
m_world->GetPopulation().GetDeme(i).IncInjectedCount();
@@ -650,7 +650,7 @@
}
if(m_world->GetPopulation().GetDeme(i).GetInjectedCount() < m_num_orgs) {
- m_world->GetPopulation().Inject(m_world->GetPopulation().GetDeme(i).GetGermline().GetLatest(),
+ m_world->GetPopulation().Inject(m_world->GetPopulation().GetDeme(i).GetGermline().GetLatest(), SRC_DEME_GERMLINE,
m_world->GetPopulation().GetDeme(i).GetCellID(m_nest_cellid),
m_merit, m_lineage_label, m_neutral_metric);
m_world->GetPopulation().GetDeme(i).IncInjectedCount();
@@ -734,7 +734,7 @@
assert(target_cell > -1);
assert(target_cell < m_world->GetPopulation().GetSize());
- m_world->GetPopulation().Inject(m_world->GetPopulation().GetDeme(i).GetGermline().GetLatest(),
+ m_world->GetPopulation().Inject(m_world->GetPopulation().GetDeme(i).GetGermline().GetLatest(), SRC_DEME_GERMLINE,
target_cell, m_merit,
m_lineage_label, m_neutral_metric);
m_world->GetPopulation().GetDeme(i).IncInjectedCount();
@@ -2494,7 +2494,7 @@
// This is probably only compatible with the "old-style" germline
for(cAssignRandomCellData::CellIDList::iterator i=cell_ids.begin(); i!=cell_ids.end(); ++i) {
m_world->GetPopulation().KillOrganism(deme.GetCell(*i));
- m_world->GetPopulation().InjectGenome(*i, deme.GetGermline().GetLatest(), 0);
+ m_world->GetPopulation().InjectGenome(*i, deme.GetGermline().GetLatest(), 0, SRC_DEME_GERMLINE);
m_world->GetPopulation().DemePostInjection(deme, deme.GetCell(*i));
}
}
@@ -2543,7 +2543,7 @@
// Kill any organism in that cell, re-seed the from the germline, and do the post-injection magic:
m_world->GetPopulation().KillOrganism(cell);
- m_world->GetPopulation().InjectGenome(cell.GetID(), deme.GetGermline().GetLatest(), 0);
+ m_world->GetPopulation().InjectGenome(cell.GetID(), deme.GetGermline().GetLatest(), 0, SRC_DEME_GERMLINE);
m_world->GetPopulation().DemePostInjection(deme, cell);
}
}
Modified: branches/biounit/source/classification/cBGGenotype.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotype.cc 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/classification/cBGGenotype.cc 2009-11-18 19:28:01 UTC (rev 3533)
@@ -87,15 +87,23 @@
{
// Handle source branching
switch (m_src) {
- case cBioUnit::SRC_ORGANISM_FILE_LOAD:
- case cBioUnit::SRC_ORGANISM_DIVIDE:
+ case SRC_DEME_GERMLINE:
+ case SRC_DEME_REPLICATE:
+ case SRC_ORGANISM_COMPETE:
+ case SRC_ORGANISM_DIVIDE:
+ case SRC_ORGANISM_FILE_LOAD:
+ case SRC_ORGANISM_RANDOM:
switch (bu->GetUnitSource()) {
- case cBioUnit::SRC_ORGANISM_FILE_LOAD:
- case cBioUnit::SRC_ORGANISM_DIVIDE:
+ case SRC_DEME_GERMLINE:
+ case SRC_DEME_REPLICATE:
+ case SRC_ORGANISM_COMPETE:
+ case SRC_ORGANISM_DIVIDE:
+ case SRC_ORGANISM_FILE_LOAD:
+ case SRC_ORGANISM_RANDOM:
break;
- case cBioUnit::SRC_PARASITE_FILE_LOAD:
- case cBioUnit::SRC_PARASITE_INJECT:
+ case SRC_PARASITE_FILE_LOAD:
+ case SRC_PARASITE_INJECT:
return false;
break;
@@ -105,16 +113,20 @@
}
break;
- case cBioUnit::SRC_PARASITE_FILE_LOAD:
- case cBioUnit::SRC_PARASITE_INJECT:
+ case SRC_PARASITE_FILE_LOAD:
+ case SRC_PARASITE_INJECT:
switch (bu->GetUnitSource()) {
- case cBioUnit::SRC_ORGANISM_FILE_LOAD:
- case cBioUnit::SRC_ORGANISM_DIVIDE:
+ case SRC_DEME_GERMLINE:
+ case SRC_DEME_REPLICATE:
+ case SRC_ORGANISM_COMPETE:
+ case SRC_ORGANISM_DIVIDE:
+ case SRC_ORGANISM_FILE_LOAD:
+ case SRC_ORGANISM_RANDOM:
return false;
break;
- case cBioUnit::SRC_PARASITE_FILE_LOAD:
- case cBioUnit::SRC_PARASITE_INJECT:
+ case SRC_PARASITE_FILE_LOAD:
+ case SRC_PARASITE_INJECT:
// Verify that the parasite inject label matches
if (m_src_args != bu->GetUnitSourceArgs()) return false;
break;
Modified: branches/biounit/source/classification/cBGGenotype.h
===================================================================
--- branches/biounit/source/classification/cBGGenotype.h 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/classification/cBGGenotype.h 2009-11-18 19:28:01 UTC (rev 3533)
@@ -51,7 +51,7 @@
private:
cBGGenotypeManager* m_mgr;
- cBioUnit::eUnitSource m_src;
+ eBioUnitSource m_src;
cString m_src_args;
cMetaGenome m_genome;
cString m_name;
@@ -99,7 +99,7 @@
// Genotype Specific Methods
- inline const cBioUnit::eUnitSource GetSource() const { return m_src; }
+ inline const eBioUnitSource GetSource() const { return m_src; }
inline const cString& GetSourceArgs() const { return m_src_args; }
inline const cMetaGenome& GetMetaGenome() const { return m_genome; }
Modified: branches/biounit/source/classification/cBioGroup.h
===================================================================
--- branches/biounit/source/classification/cBioGroup.h 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/classification/cBioGroup.h 2009-11-18 19:28:01 UTC (rev 3533)
@@ -43,6 +43,9 @@
cBioGroup() : m_refs(0) { ; }
virtual ~cBioGroup() = 0;
+ virtual int GetRoleID() const;
+ virtual const cString& GetRole() const;
+
virtual cBioGroup* ClassifyNewBioUnit(cBioUnit* bu, tArray<cBioGroup*>* parents = NULL) = 0;
virtual void RemoveBioUnit(cBioUnit* bu) = 0;
Modified: branches/biounit/source/classification/cBioGroupManager.h
===================================================================
--- branches/biounit/source/classification/cBioGroupManager.h 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/classification/cBioGroupManager.h 2009-11-18 19:28:01 UTC (rev 3533)
@@ -37,6 +37,7 @@
{
friend class cClassificationManager;
private:
+ int m_role_id;
cString m_role;
@@ -45,14 +46,13 @@
virtual ~cBioGroupManager() = 0;
virtual cBioGroup* ClassifyNewBioUnit(cBioUnit* bu) = 0;
-
-
-protected:
+
+ inline int GetRoleID() const { return m_role_id; }
inline const cString& GetRole() const { return m_role; }
private:
- void SetRole(const cString& role) { m_role = role; }
+ void SetRole(int role_id, const cString& role) { m_role_id = role_id; m_role = role; }
};
Modified: branches/biounit/source/classification/cBioUnit.cc
===================================================================
--- branches/biounit/source/classification/cBioUnit.cc 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/classification/cBioUnit.cc 2009-11-18 19:28:01 UTC (rev 3533)
@@ -24,4 +24,51 @@
#include "cBioUnit.h"
-cBioUnit::~cBioUnit() { ; }
+#include "cBioGroup.h"
+#include "tArrayMap.h"
+#include "tArraySet.h"
+
+
+cBioUnit::~cBioUnit()
+{
+ // Notify all groups that this bio unit has been terminated
+ for (int i = 0; i < m_bio_groups.GetSize(); i++) m_bio_groups[i]->RemoveBioUnit(this);
+}
+
+
+void cBioUnit::SelfClassify(tArray<tArray<cBioGroup*>*>& parents)
+{
+ assert(parents.GetSize() > 0);
+
+ if (parents.GetSize() == 1) {
+ // Handle Asexual Organisms
+ tArray<cBioGroup*> parent_group(1);
+
+ // Loop through all parental groups and classify this bio unit with each one
+ for (int i = 0; i < parents[0]->GetSize(); i++) {
+ parent_group[0] = (*parents[0])[i];
+ cBioGroup* group = (*parents[0])[i]->ClassifyNewBioUnit(this, &parent_group);
+ if (group) m_bio_groups.Push(group);
+ }
+ } else {
+ // Handle Sexual Organisms (multi-parent)
+ tArraySet<int> group_roles;
+ tArrayMap<int, tArray<cBioGroup*> > parent_groups;
+
+ // Sort groups into sets of parental groups by role_id
+ for (int p = 0; p < parents.GetSize(); p++) {
+ for (int g = 0; g < parents[p]->GetSize(); g++) {
+ cBioGroup* group = (*parents[p])[g];
+ parent_groups[group->GetRoleID()].Push(group);
+ group_roles.Add(group->GetRoleID());
+ }
+ }
+
+ // Classify this bio unit with all distinct parental group roles
+ for (int r = 0; r < group_roles.GetSize(); r++) {
+ tArray<cBioGroup*>& pgrps = parent_groups[r];
+ cBioGroup* group = pgrps[0]->ClassifyNewBioUnit(this, &pgrps);
+ if (group) m_bio_groups.Push(group);
+ }
+ }
+}
Modified: branches/biounit/source/classification/cBioUnit.h
===================================================================
--- branches/biounit/source/classification/cBioUnit.h 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/classification/cBioUnit.h 2009-11-18 19:28:01 UTC (rev 3533)
@@ -25,28 +25,33 @@
#ifndef cBioUnit_h
#define cBioUnit_h
+#ifndef defs_h
+#include "defs.h"
+#endif
+#ifndef tArray_h
+#include "tArray.h"
+#endif
+
+class cBioGroup;
class cMetaGenome;
class cString;
+
class cBioUnit
{
-public:
- enum eUnitSource {
- SRC_ORGANISM_FILE_LOAD,
- SRC_ORGANISM_DIVIDE,
- SRC_PARASITE_FILE_LOAD,
- SRC_PARASITE_INJECT,
- SRC_TEST_CPU
- };
+protected:
+ tArray<cBioGroup*> m_bio_groups;
+
-
public:
cBioUnit() { ; }
- virtual ~cBioUnit() = 0;
+ virtual ~cBioUnit();
- virtual eUnitSource GetUnitSource() const = 0;
+ virtual eBioUnitSource GetUnitSource() const = 0;
virtual const cString& GetUnitSourceArgs() const = 0;
virtual const cMetaGenome& GetMetaGenome() const = 0;
+
+ void SelfClassify(tArray<tArray<cBioGroup*>*>& parents);
};
#endif
Modified: branches/biounit/source/classification/cClassificationManager.cc
===================================================================
--- branches/biounit/source/classification/cClassificationManager.cc 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/classification/cClassificationManager.cc 2009-11-18 19:28:01 UTC (rev 3533)
@@ -75,8 +75,7 @@
bool cClassificationManager::RegisterBioGroupManager(cBioGroupManager* bgm, const cString& role)
{
// @TODO - verify that this role is not already in use -- maybe hash managers by role
- m_bgms.Push(bgm);
- bgm->SetRole(role);
+ bgm->SetRole(m_bgms.Push(bgm), role);
return true;
}
Modified: branches/biounit/source/cpu/cTestCPU.cc
===================================================================
--- branches/biounit/source/cpu/cTestCPU.cc 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/cpu/cTestCPU.cc 2009-11-18 19:28:01 UTC (rev 3533)
@@ -288,8 +288,8 @@
}
cOrganism* organism = NULL;
- if (test_info.GetInstSet()) organism = new cOrganism(m_world, ctx, genome, test_info.GetInstSet());
- else organism = new cOrganism(m_world, ctx, genome);
+ if (test_info.GetInstSet()) organism = new cOrganism(m_world, ctx, genome, test_info.GetInstSet(), SRC_TEST_CPU);
+ else organism = new cOrganism(m_world, ctx, genome, SRC_TEST_CPU);
// Copy the test mutation rates
organism->MutationRates().Copy(test_info.MutationRates());
Modified: branches/biounit/source/defs.h
===================================================================
--- branches/biounit/source/defs.h 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/defs.h 2009-11-18 19:28:01 UTC (rev 3533)
@@ -196,6 +196,17 @@
};
+enum eBioUnitSource {
+ SRC_DEME_GERMLINE,
+ SRC_DEME_REPLICATE,
+ SRC_ORGANISM_COMPETE,
+ SRC_ORGANISM_DIVIDE,
+ SRC_ORGANISM_FILE_LOAD,
+ SRC_ORGANISM_RANDOM,
+ SRC_PARASITE_FILE_LOAD,
+ SRC_PARASITE_INJECT,
+ SRC_TEST_CPU
+};
#endif
Modified: branches/biounit/source/main/cBirthChamber.cc
===================================================================
--- branches/biounit/source/main/cBirthChamber.cc 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/main/cBirthChamber.cc 2009-11-18 19:28:01 UTC (rev 3533)
@@ -165,7 +165,7 @@
// This is asexual who doesn't need to wait in the birth chamber
// just build the child and return.
child_array.Resize(1);
- child_array[0] = new cOrganism(m_world, ctx, offspring);
+ child_array[0] = new cOrganism(m_world, ctx, offspring, SRC_ORGANISM_DIVIDE);
merit_array.Resize(1);
if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
@@ -206,8 +206,8 @@
{
// Build both child organisms...
child_array.Resize(2);
- child_array[0] = new cOrganism(m_world, ctx, old_entry.genome);
- child_array[1] = new cOrganism(m_world, ctx, new_genome);
+ child_array[0] = new cOrganism(m_world, ctx, old_entry.genome, SRC_ORGANISM_DIVIDE);
+ child_array[1] = new cOrganism(m_world, ctx, new_genome, SRC_ORGANISM_DIVIDE);
// Setup the merits for both children...
merit_array.Resize(2);
@@ -473,8 +473,8 @@
if (two_fold_cost == 0) { // Build the two organisms.
child_array.Resize(2);
- child_array[0] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome0);
- child_array[1] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome1);
+ child_array[0] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome0, SRC_ORGANISM_DIVIDE);
+ child_array[1] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome1, SRC_ORGANISM_DIVIDE);
if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
child_array[0]->GetPhenotype().SetEnergy(meritOrEnergy0);
@@ -497,7 +497,7 @@
merit_array.Resize(1);
if (ctx.GetRandom().GetDouble() < 0.5) {
- child_array[0] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome0);
+ child_array[0] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome0, SRC_ORGANISM_DIVIDE);
if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
child_array[0]->GetPhenotype().SetEnergy(meritOrEnergy0);
meritOrEnergy0 = child_array[0]->GetPhenotype().ConvertEnergyToMerit(child_array[0]->GetPhenotype().GetStoredEnergy());
@@ -508,7 +508,7 @@
SetupGenotypeInfo(child_array[0], parent0_genotype, parent1_genotype);
}
else {
- child_array[0] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome1);
+ child_array[0] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome1, SRC_ORGANISM_DIVIDE);
if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
child_array[0]->GetPhenotype().SetEnergy(meritOrEnergy1);
meritOrEnergy1 = child_array[1]->GetPhenotype().ConvertEnergyToMerit(child_array[1]->GetPhenotype().GetStoredEnergy());
Modified: branches/biounit/source/main/cOrganism.cc
===================================================================
--- branches/biounit/source/main/cOrganism.cc 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/main/cOrganism.cc 2009-11-18 19:28:01 UTC (rev 3533)
@@ -54,10 +54,13 @@
using namespace std;
-cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome)
+cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, eBioUnitSource src,
+ const cString& src_args)
: m_world(world)
, m_genotype(NULL)
, m_phenotype(world)
+ , m_src(src)
+ , m_src_args(src_args)
, m_initial_genome(genome)
, m_mut_info(world->GetEnvironment().GetMutationLib(), genome.GetSize())
, m_interface(NULL)
@@ -95,10 +98,13 @@
initialize(ctx);
}
-cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, int hw_type, int inst_set_id, const cGenome& genome)
+cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, int hw_type, int inst_set_id, const cGenome& genome,
+ eBioUnitSource src, const cString& src_args)
: m_world(world)
, m_genotype(NULL)
, m_phenotype(world)
+ , m_src(src)
+ , m_src_args(src_args)
, m_initial_genome(hw_type, inst_set_id, genome)
, m_mut_info(world->GetEnvironment().GetMutationLib(), genome.GetSize())
, m_interface(NULL)
@@ -136,10 +142,13 @@
initialize(ctx);
}
-cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, cInstSet* inst_set)
+cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, cInstSet* inst_set,
+ eBioUnitSource src, const cString& src_args)
: m_world(world)
, m_genotype(NULL)
, m_phenotype(world)
+ , m_src(src)
+ , m_src_args(src_args)
, m_initial_genome(genome)
, m_mut_info(world->GetEnvironment().GetMutationLib(), genome.GetSize())
, m_interface(NULL)
@@ -207,10 +216,7 @@
delete m_interface;
if(m_net) delete m_net;
if(m_msg) delete m_msg;
- if(m_opinion) delete m_opinion;
-
- // Notify all groups that this bio unit has been terminated
- for (int i = 0; i < m_bio_groups.GetSize(); i++) m_bio_groups[i]->RemoveBioUnit(this);
+ if(m_opinion) delete m_opinion;
}
cOrganism::cNetSupport::~cNetSupport()
Modified: branches/biounit/source/main/cOrganism.h
===================================================================
--- branches/biounit/source/main/cOrganism.h 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/main/cOrganism.h 2009-11-18 19:28:01 UTC (rev 3533)
@@ -98,10 +98,9 @@
private:
cWorld* m_world;
cHardwareBase* m_hardware; // The actual machinery running this organism.
- tArray<cBioGroup*> m_bio_groups;
cGenotype* m_genotype; // Information about organisms with this genome.
cPhenotype m_phenotype; // Descriptive attributes of organism.
- cBioUnit::eUnitSource m_src;
+ eBioUnitSource m_src;
cString m_src_args;
const cMetaGenome m_initial_genome; // Initial genome; can never be changed!
tArray<cInjectGenotype*> m_parasites; // List of all parasites associated with this organism.
@@ -163,13 +162,15 @@
cOrganism& operator=(const cOrganism&); // @not_implemented
public:
- cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome);
- cOrganism(cWorld* world, cAvidaContext& ctx, int hw_type, int inst_set_id, const cGenome& genome);
- cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, cInstSet* inst_set);
+ cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, eBioUnitSource src, const cString& src_args = "");
+ cOrganism(cWorld* world, cAvidaContext& ctx, int hw_type, int inst_set_id, const cGenome& genome,
+ eBioUnitSource src, const cString& src_args = "");
+ cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, cInstSet* inst_set,
+ eBioUnitSource src, const cString& src_args = "");
~cOrganism();
// -------- cBioUnit Methods --------
- cBioUnit::eUnitSource GetUnitSource() const { return m_src; }
+ eBioUnitSource GetUnitSource() const { return m_src; }
const cString& GetUnitSourceArgs() const { return m_src_args; }
const cMetaGenome& GetMetaGenome() const { return m_initial_genome; }
Modified: branches/biounit/source/main/cPopulation.cc
===================================================================
--- branches/biounit/source/main/cPopulation.cc 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/main/cPopulation.cc 2009-11-18 19:28:01 UTC (rev 3533)
@@ -312,7 +312,7 @@
exit(-1);
}
if (start_org.GetSize() != 0) {
- Inject(start_org);
+ Inject(start_org, SRC_ORGANISM_FILE_LOAD);
}
else cerr << "Warning: Zero length start organism, not injecting into initial population." << endl;
} else {
@@ -1531,7 +1531,7 @@
if (GetCell(cellid).IsOccupied()) {
int lineage = GetCell(cellid).GetOrganism()->GetLineageLabel();
cGenome genome = GetCell(cellid).GetOrganism()->GetGenome();
- InjectGenome(cellid, genome, lineage);
+ InjectGenome(cellid, genome, lineage, SRC_DEME_REPLICATE);
}
}
}
@@ -1679,13 +1679,13 @@
m_world->GetStats().GermlineReplication(source_deme.GetGermline(), target_deme.GetGermline());
// All done with the germline manipulation; seed each deme.
- SeedDeme(source_deme, source_deme.GetGermline().GetLatest());
+ SeedDeme(source_deme, source_deme.GetGermline().GetLatest(), SRC_DEME_GERMLINE);
/* MJM - source and target deme could be the same!
* Seeding the same deme twice probably shouldn't happen.
*/
if (source_deme.GetDemeID() != target_deme.GetDemeID()) {
- SeedDeme(target_deme, target_deme.GetGermline().GetLatest());
+ SeedDeme(target_deme, target_deme.GetGermline().GetLatest(), SRC_DEME_GERMLINE);
}
} else if(m_world->GetConfig().DEMES_USE_GERMLINE.Get() == 2) {
@@ -1725,8 +1725,8 @@
cGenotype * new_germline_genotype = m_world->GetClassificationManager().GetGenotype(new_genome, germline_genotype, NULL);
source_deme.ReplaceGermline(*new_germline_genotype);
target_deme.ReplaceGermline(*new_germline_genotype);
- SeedDeme(source_deme, *new_germline_genotype);
- SeedDeme(target_deme, *new_germline_genotype);
+ SeedDeme(source_deme, *new_germline_genotype, SRC_DEME_GERMLINE);
+ SeedDeme(target_deme, *new_germline_genotype, SRC_DEME_GERMLINE);
} else {
// Not using germlines; things are much simpler. Seed the target from the source.
@@ -1790,19 +1790,19 @@
@todo Fix lineage label on injected genomes.
@todo Different strategies for non-random placement.
*/
-void cPopulation::SeedDeme(cDeme& deme, cGenome& genome) {
+void cPopulation::SeedDeme(cDeme& deme, cGenome& genome, eBioUnitSource src) {
// Kill all the organisms in the deme.
deme.KillAll();
// Create the specified number of organisms in the deme.
for(int i=0; i< m_world->GetConfig().DEMES_REPLICATE_SIZE.Get(); ++i) {
int cellid = DemeSelectInjectionCell(deme, i);
- InjectGenome(cellid, genome, 0);
+ InjectGenome(cellid, genome, 0, src);
DemePostInjection(deme, cell_array[cellid]);
}
}
-void cPopulation::SeedDeme(cDeme& _deme, cGenotype& _genotype) {
+void cPopulation::SeedDeme(cDeme& _deme, cGenotype& _genotype, eBioUnitSource src) {
// Kill all the organisms in the deme.
_deme.KillAll();
_deme.ClearFounders();
@@ -1810,7 +1810,7 @@
// Create the specified number of organisms in the deme.
for(int i=0; i< m_world->GetConfig().DEMES_REPLICATE_SIZE.Get(); ++i) {
int cellid = DemeSelectInjectionCell(_deme, i);
- InjectGenotype(cellid, &_genotype);
+ InjectGenotype(cellid, &_genotype, src);
DemePostInjection(_deme, cell_array[cellid]);
_deme.AddFounder(_genotype);
}
@@ -1889,11 +1889,11 @@
int j=0;
for(std::vector<std::pair<cGenome,int> >::iterator i=xfer.begin(); i!=xfer.end(); ++i, ++j) {
int cellid = DemeSelectInjectionCell(source_deme, j);
- InjectGenome(cellid, i->first, i->second);
+ InjectGenome(cellid, i->first, i->second, SRC_DEME_REPLICATE);
DemePostInjection(source_deme, cell_array[cellid]);
cellid = DemeSelectInjectionCell(target_deme, j);
- InjectGenome(cellid, i->first, i->second);
+ InjectGenome(cellid, i->first, i->second, SRC_DEME_REPLICATE);
DemePostInjection(target_deme, cell_array[cellid]);
}
@@ -2204,7 +2204,7 @@
// we wanted to re-seed from the original founders.
for(int i=0; i<target_founders.GetSize(); i++) {
int cellid = DemeSelectInjectionCell(target_deme, i);
- InjectDemeFounder(cellid, *target_founders[i]->GetGenotype(), &target_founders[i]->GetPhenotype());
+ SeedDeme_InjectDemeFounder(cellid, *target_founders[i]->GetGenotype(), &target_founders[i]->GetPhenotype());
target_deme.AddFounder(*target_founders[i]->GetGenotype(), &target_founders[i]->GetPhenotype());
DemePostInjection(target_deme, cell_array[cellid]);
}
@@ -2222,7 +2222,7 @@
for(int i=0; i<source_founders.GetSize(); i++) {
int cellid = DemeSelectInjectionCell(source_deme, i);
- InjectDemeFounder(cellid, *source_founders[i]->GetGenotype(), &source_founders[i]->GetPhenotype());
+ SeedDeme_InjectDemeFounder(cellid, *source_founders[i]->GetGenotype(), &source_founders[i]->GetPhenotype());
source_deme.AddFounder(*source_founders[i]->GetGenotype(), &source_founders[i]->GetPhenotype());
DemePostInjection(source_deme, cell_array[cellid]);
}
@@ -2243,7 +2243,7 @@
int cellid = DemeSelectInjectionCell(source_deme, i);
//cout << "founder: " << source_founders[i] << endl;
cGenotype * genotype = m_world->GetClassificationManager().FindGenotype(source_founders[i]);
- InjectDemeFounder(cellid, *genotype, &source_founder_phenotypes[i]);
+ SeedDeme_InjectDemeFounder(cellid, *genotype, &source_founder_phenotypes[i]);
DemePostInjection(source_deme, cell_array[cellid]);
}
@@ -2359,7 +2359,7 @@
// And inject it into target deme.
int target_cellid = DemeSelectInjectionCell(target_deme, j++);
- InjectGenome(target_cellid, genome, lineage);
+ InjectGenome(target_cellid, genome, lineage, SRC_DEME_REPLICATE);
DemePostInjection(target_deme, cell_array[target_cellid]);
}
//else {
@@ -2371,11 +2371,11 @@
return successfully_seeded;
}
-void cPopulation::InjectDemeFounder(int _cell_id, cGenotype& _genotype, cPhenotype* _phenotype)
+void cPopulation::SeedDeme_InjectDemeFounder(int _cell_id, cGenotype& _genotype, cPhenotype* _phenotype)
{
// phenotype can be NULL
- InjectGenotype(_cell_id, &_genotype);
+ InjectGenotype(_cell_id, &_genotype, SRC_DEME_REPLICATE);
// At this point, the cell had better be occupied...
assert(GetCell(_cell_id).IsOccupied());
@@ -4513,7 +4513,7 @@
}
assert(genotype_index != -1);
- InjectGenome(i, genotype_array[genotype_index]->GetGenome(), 0);
+ InjectGenome(i, genotype_array[genotype_index]->GetGenome(), 0, SRC_ORGANISM_FILE_LOAD);
}
sync_events = true;
@@ -4617,7 +4617,7 @@
soup_full = true;
break;
}
- InjectGenotype( current_cell, (*it).genotype );
+ InjectGenotype(current_cell, (*it).genotype, SRC_ORGANISM_FILE_LOAD);
cPhenotype & phenotype = GetCell(current_cell).GetOrganism()->GetPhenotype();
if ( (*it).merit > 0) phenotype.SetMerit( cMerit((*it).merit) );
AdjustSchedule(GetCell(current_cell), phenotype.GetMerit());
@@ -4834,7 +4834,7 @@
for (int cell_i = 0; cell_i < tmp.num_cpus; cell_i++) {
int cell_id = tmp.cells[cell_i];
- InjectGenotype(cell_id, tmp.genotype);
+ InjectGenotype(cell_id, tmp.genotype, SRC_ORGANISM_FILE_LOAD);
cPhenotype& phenotype = GetCell(cell_id).GetOrganism()->GetPhenotype();
@@ -4913,7 +4913,7 @@
* this organism.
**/
-void cPopulation::Inject(const cGenome & genome, int cell_id, double merit, int lineage_label, double neutral)
+void cPopulation::Inject(const cGenome & genome, eBioUnitSource src, int cell_id, double merit, int lineage_label, double neutral)
{
// If an invalid cell was given, choose a new ID for it.
if (cell_id < 0) {
@@ -4925,7 +4925,7 @@
}
}
- InjectGenome(cell_id, genome, lineage_label);
+ InjectGenome(cell_id, genome, lineage_label, src);
cPhenotype& phenotype = GetCell(cell_id).GetOrganism()->GetPhenotype();
phenotype.SetNeutralMetric(neutral);
@@ -5088,7 +5088,7 @@
// This function injects a new organism into the population at cell_id based
// on the genotype passed in.
-void cPopulation::InjectGenotype(int cell_id, cGenotype* new_genotype)
+void cPopulation::InjectGenotype(int cell_id, cGenotype* new_genotype, eBioUnitSource src)
{
assert(cell_id >= 0 && cell_id < cell_array.GetSize());
if (cell_id < 0 || cell_id >= cell_array.GetSize()) {
@@ -5098,7 +5098,7 @@
cAvidaContext& ctx = m_world->GetDefaultContext();
cMetaGenome tmp_genome(m_world->GetConfig().HARDWARE_TYPE.Get(), 1, new_genotype->GetGenome()); // @TODO - genotypes need metagenomes
- cOrganism* new_organism = new cOrganism(m_world, ctx, tmp_genome);
+ cOrganism* new_organism = new cOrganism(m_world, ctx, tmp_genome, src);
//Coalescense Clade Setup
new_organism->SetCCladeLabel(-1);
@@ -5166,7 +5166,7 @@
cAvidaContext& ctx = m_world->GetDefaultContext();
- cOrganism* new_organism = new cOrganism(m_world, ctx, orig_org.GetMetaGenome());
+ cOrganism* new_organism = new cOrganism(m_world, ctx, orig_org.GetMetaGenome(), SRC_ORGANISM_FILE_LOAD);
// Set the genotype...
new_organism->SetGenotype(orig_org.GetGenotype());
@@ -5195,9 +5195,9 @@
ActivateOrganism(ctx, new_organism, cell_array[cell_id]);
}
-// This function injects the child genome of an organism into the population at cell_id.
+// This function injects the offspring genome of an organism into the population at cell_id.
// Takes care of divide mutations.
-void cPopulation::InjectChild(int cell_id, cOrganism& parent)
+void cPopulation::CompeteOrganisms_ConstructOffspring(int cell_id, cOrganism& parent)
{
assert(cell_id >= 0 && cell_id < cell_array.GetSize());
@@ -5209,7 +5209,7 @@
cMetaGenome child_genome = parent.OffspringGenome();
parent.GetHardware().Divide_TestFitnessMeasures(ctx);
parent.OffspringGenome() = save_child;
- cOrganism* new_organism = new cOrganism(m_world, ctx, child_genome);
+ cOrganism* new_organism = new cOrganism(m_world, ctx, child_genome, SRC_ORGANISM_COMPETE);
// Set the genotype...
assert(parent.GetGenotype());
@@ -5242,13 +5242,12 @@
}
-void cPopulation::InjectGenome(int cell_id, const cGenome& genome, int lineage_label)
+void cPopulation::InjectGenome(int cell_id, const cGenome& genome, int lineage_label, eBioUnitSource src)
{
// Setup the genotype...
cGenotype* new_genotype = m_world->GetClassificationManager().GetGenotypeInjected(genome, lineage_label);
- // The rest is done by InjectGenotype();
- InjectGenotype( cell_id, new_genotype );
+ InjectGenotype( cell_id, new_genotype, src);
}
// Note: cPopulation::SerialTransfer does not respect deme boundaries and only acts on a single population.
@@ -5771,8 +5770,8 @@
cOrganism* organism = GetCell(from_cell_id).GetOrganism();
organism->OffspringGenome() = organism->GetMetaGenome();
- if (m_world->GetVerbosity() >= VERBOSE_DETAILS) cout << "Injecting Child " << from_cell_id << " to " << to_cell_id << endl;
- InjectChild( to_cell_id, *organism );
+ if (m_world->GetVerbosity() >= VERBOSE_DETAILS) cout << "Injecting Offspring " << from_cell_id << " to " << to_cell_id << endl;
+ CompeteOrganisms_ConstructOffspring(to_cell_id, *organism);
is_init[to_cell_id] = true;
}
@@ -5786,7 +5785,7 @@
cOrganism* organism = GetCell(cell_id).GetOrganism();
organism->OffspringGenome() = organism->GetMetaGenome();
if (m_world->GetVerbosity() >= VERBOSE_DETAILS) cout << "Re-injecting Self " << cell_id << " to " << cell_id << endl;
- InjectChild( cell_id, *organism );
+ CompeteOrganisms_ConstructOffspring(cell_id, *organism);
}
}
}
Modified: branches/biounit/source/main/cPopulation.h
===================================================================
--- branches/biounit/source/main/cPopulation.h 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/main/cPopulation.h 2009-11-18 19:28:01 UTC (rev 3533)
@@ -82,6 +82,7 @@
class cSaleItem;
+
class cPopulation
{
#if USE_tMemTrack
@@ -118,65 +119,28 @@
// Group formation information
std::map<int, int> m_groups; //<! Maps the group id to the number of orgs in the group
- ///////////////// Private Methods ////////////////////
- void BuildTimeSlicer(cChangeList* change_list); // Build the schedule object
-
- // Methods to place offspring in the population.
- cPopulationCell& PositionOffspring(cPopulationCell& parent_cell, bool parent_ok = true);
- void PositionAge(cPopulationCell& parent_cell, tList<cPopulationCell>& found_list, bool parent_ok);
- void PositionMerit(cPopulationCell & parent_cell, tList<cPopulationCell>& found_list, bool parent_ok);
- void PositionEnergyUsed(cPopulationCell & parent_cell, tList<cPopulationCell>& found_list, bool parent_ok);
- cPopulationCell& PositionDemeMigration(cPopulationCell& parent_cell, bool parent_ok = true);
- cPopulationCell& PositionDemeRandom(int deme_id, cPopulationCell& parent_cell, bool parent_ok = true);
- int UpdateEmptyCellIDArray(int deme_id = -1);
- void FindEmptyCell(tList<cPopulationCell>& cell_list, tList<cPopulationCell>& found_list);
-
- // Update statistics collecting...
- void UpdateDemeStats();
- void UpdateOrganismStats();
- void UpdateGenotypeStats();
- void UpdateSpeciesStats();
- void UpdateDominantStats();
- void UpdateDominantParaStats();
-
- /**
- * Attention: InjectGenotype does *not* add the genotype to the archive.
- * It assumes that's where you got the genotype from.
- **/
- void InjectGenotype(int cell_id, cGenotype* genotype);
-public:
- // This needs to be public so it can be used over in PopulationActions.cc...
- void InjectGenome(int cell_id, const cGenome& genome, int lineage_label);
-private:
- void InjectClone(int cell_id, cOrganism& orig_org);
- void InjectChild(int cell_id, cOrganism& parent);
-
- void LineageSetupOrganism(cOrganism* organism, cLineage* lineage, int lin_label, cGenotype* parent_genotype = NULL);
- void CCladeSetupOrganism(cOrganism* organism);
-
- // Must be called to activate *any* organism in the population.
- void ActivateOrganism(cAvidaContext& ctx, cOrganism* in_organism, cPopulationCell& target_cell);
+ int m_hgt_resid; //!< HGT resource ID.
- inline void AdjustSchedule(const cPopulationCell& cell, const cMerit& merit);
-
cPopulation(); // @not_implemented
cPopulation(const cPopulation&); // @not_implemented
cPopulation& operator=(const cPopulation&); // @not_implemented
+
public:
cPopulation(cWorld* world);
~cPopulation();
void InitiatePop();
+ void InjectGenome(int cell_id, const cGenome& genome, int lineage_label, eBioUnitSource src);
+
// Activate the offspring of an organism in the population
bool ActivateOffspring(cAvidaContext& ctx, const cMetaGenome& offspring_genome, cOrganism* parent_organism);
bool ActivateParasite(cOrganism& parent, const cCodeLabel& label, const cGenome& injected_code);
// Inject an organism from the outside world.
- void Inject(const cGenome& genome, int cell_id = -1, double merit = -1, int lineage_label = 0,
- double neutral_metric = 0);
+ void Inject(const cGenome& genome, eBioUnitSource src, int cell_id = -1, double merit = -1, int lineage_label = 0, double neutral_metric = 0);
void InjectParasite(const cCodeLabel& label, const cGenome& injected_code, int cell_id);
// Deactivate an organism in the population (required for deactivations)
@@ -209,17 +173,14 @@
void ReplaceDeme(cDeme& source_deme, cDeme& target_deme);
//! Helper method that seeds a deme from the given genome.
- void SeedDeme(cDeme& deme, cGenome& genome);
+ void SeedDeme(cDeme& deme, cGenome& genome, eBioUnitSource src);
//! Helper method that seeds a deme from the given genotype.
- void SeedDeme(cDeme& _deme, cGenotype& _genotype);
+ void SeedDeme(cDeme& _deme, cGenotype& _genotype, eBioUnitSource src);
//! Helper method that seeds a target deme from the organisms in the source deme.
bool SeedDeme(cDeme& source_deme, cDeme& target_deme);
- //! Helper method that adds a founder organism to a deme, and sets up its phenotype
- void InjectDemeFounder(int _cell_id, cGenotype& _genotype, cPhenotype* _phenotype = NULL);
-
//! Helper method that determines the cell into which an organism will be placed during deme replication.
int DemeSelectInjectionCell(cDeme& deme, int sequence=0);
@@ -346,7 +307,56 @@
// Get the group information
map<int, int> GetFormedGroups() { return m_groups; }
+ // -------- HGT support --------
+ //! Modify current level of the HGT resource.
+ void AdjustHGTResource(double delta);
+
+ // -------- Population mixing support --------
+ //! Mix all organisms in the population.
+ void MixPopulation();
+
private:
+ void BuildTimeSlicer(cChangeList* change_list); // Build the schedule object
+
+ // Methods to place offspring in the population.
+ cPopulationCell& PositionOffspring(cPopulationCell& parent_cell, bool parent_ok = true);
+ void PositionAge(cPopulationCell& parent_cell, tList<cPopulationCell>& found_list, bool parent_ok);
+ void PositionMerit(cPopulationCell & parent_cell, tList<cPopulationCell>& found_list, bool parent_ok);
+ void PositionEnergyUsed(cPopulationCell & parent_cell, tList<cPopulationCell>& found_list, bool parent_ok);
+ cPopulationCell& PositionDemeMigration(cPopulationCell& parent_cell, bool parent_ok = true);
+ cPopulationCell& PositionDemeRandom(int deme_id, cPopulationCell& parent_cell, bool parent_ok = true);
+ int UpdateEmptyCellIDArray(int deme_id = -1);
+ void FindEmptyCell(tList<cPopulationCell>& cell_list, tList<cPopulationCell>& found_list);
+
+ // Update statistics collecting...
+ void UpdateDemeStats();
+ void UpdateOrganismStats();
+ void UpdateGenotypeStats();
+ void UpdateSpeciesStats();
+ void UpdateDominantStats();
+ void UpdateDominantParaStats();
+
+ /**
+ * Attention: InjectGenotype does *not* add the genotype to the archive.
+ * It assumes that's where you got the genotype from.
+ **/
+ void InjectGenotype(int cell_id, cGenotype* genotype, eBioUnitSource src);
+
+ void InjectClone(int cell_id, cOrganism& orig_org);
+ void CompeteOrganisms_ConstructOffspring(int cell_id, cOrganism& parent);
+
+ //! Helper method that adds a founder organism to a deme, and sets up its phenotype
+ void SeedDeme_InjectDemeFounder(int _cell_id, cGenotype& _genotype, cPhenotype* _phenotype = NULL);
+
+ void LineageSetupOrganism(cOrganism* organism, cLineage* lineage, int lin_label, cGenotype* parent_genotype = NULL);
+ void CCladeSetupOrganism(cOrganism* organism);
+
+ // Must be called to activate *any* organism in the population.
+ void ActivateOrganism(cAvidaContext& ctx, cOrganism* in_organism, cPopulationCell& target_cell);
+
+ inline void AdjustSchedule(const cPopulationCell& cell, const cMerit& merit);
+
+
struct sTmpGenotype
{
public:
@@ -370,18 +380,6 @@
inline bool operator<=(const sTmpGenotype& rhs) const { return id_num <= rhs.id_num; }
inline bool operator>=(const sTmpGenotype& rhs) const { return id_num >= rhs.id_num; }
};
-
- // -------- HGT support --------
-private:
- int m_hgt_resid; //!< HGT resource ID.
-public:
- //! Modify current level of the HGT resource.
- void AdjustHGTResource(double delta);
-
- // -------- Population mixing support --------
-public:
- //! Mix all organisms in the population.
- void MixPopulation();
};
Modified: branches/biounit/source/tools/tArray.h
===================================================================
--- branches/biounit/source/tools/tArray.h 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/tools/tArray.h 2009-11-18 19:28:01 UTC (rev 3533)
@@ -26,23 +26,15 @@
#ifndef tArray_h
#define tArray_h
-#if USE_tMemTrack
-# ifndef tMemTrack_h
-# include "tMemTrack.h"
-# endif
-#endif
-
#include <cassert>
#ifndef NULL
#define NULL 0
#endif
+
template <class T> class tArray
{
-#if USE_tMemTrack
- tMemTrack<tArray<T> > mt;
-#endif
private:
T* m_data; // Data Elements
int m_size; // Number of Elements
Modified: branches/biounit/source/tools/tArrayMap.h
===================================================================
--- branches/biounit/source/tools/tArrayMap.h 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/tools/tArrayMap.h 2009-11-18 19:28:01 UTC (rev 3533)
@@ -72,6 +72,32 @@
return m_map[m_map.GetSize() - 1].Value();
}
+ ValueType& ValueFor(const KeyType& key)
+ {
+ for (int i = 0; i < m_map.GetSize(); i++) {
+ if (m_map[i].Key() == key) {
+ return m_map[i].Value();
+ }
+ }
+ m_map.Push(tKVPair<KeyType, ValueType>(key));
+ return m_map[m_map.GetSize() - 1].Value();
+ }
+
+ const ValueType& ValueFor(const KeyType& key) const
+ {
+ for (int i = 0; i < m_map.GetSize(); i++) {
+ if (m_map[i].Key() == key) {
+ return m_map[i].Value();
+ }
+ }
+ m_map.Push(tKVPair<KeyType, ValueType>(key));
+ return m_map[m_map.GetSize() - 1].Value();
+ }
+
+ ValueType& operator[](const KeyType& key) { return ValueFor(key); }
+ const ValueType& operator[](const KeyType& key) const { return ValueFor(key); }
+
+
void Remove(const KeyType& key)
{
for (int i = 0; i < m_map.GetSize(); i++) {
Added: branches/biounit/source/tools/tArraySet.h
===================================================================
--- branches/biounit/source/tools/tArraySet.h (rev 0)
+++ branches/biounit/source/tools/tArraySet.h 2009-11-18 19:28:01 UTC (rev 3533)
@@ -0,0 +1,116 @@
+/*
+ * tArraySet.h
+ * Avida
+ *
+ * Created by David on 11/18/09.
+ * Copyright 2009 Michigan State University. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef tArraySet_h
+#define tArraySet_h
+
+template <class T> class tArraySet
+{
+private:
+ T* m_data; // Data Elements
+ int m_size; // Number of Elements
+
+public:
+ typedef T* iterator; //!< STL-compatible iterator.
+ typedef const T* const_iterator; //!< STL-compatible const_iterator.
+
+ tArraySet() : m_data(NULL), m_size(0) { ; }
+ tArraySet(const tArraySet& rhs) : m_data(NULL), m_size(0) { this->operator=(rhs); }
+
+ ~tArraySet() { delete [] m_data; }
+
+ inline iterator begin() { return m_data; }
+ inline iterator end() { return m_data + m_size; }
+ inline const_iterator begin() const { return m_data; }
+ inline const_iterator end() const { return m_data + m_size; }
+
+ inline tArraySet& operator=(const tArraySet& rhs) {
+ if (m_size != rhs.GetSize()) ResizeClear(rhs.GetSize());
+ for(int i = 0; i < m_size; i++) m_data[i] = rhs[i];
+ return *this;
+ }
+
+ inline tArraySet operator+(const tArraySet& in_array) const {
+ tArraySet tmp;
+
+ if (m_size >= in_array.m_size) {
+ for(int i = 0; i < m_size; i++) tmp.m_data[i] = m_data[i];
+ for(int i = 0; i < in_array.m_size; i++) tmp.Add(in_array[i]);
+ } else {
+ for(int i = 0; i < in_array.m_size; i++) tmp[i] = in_array[i];
+ for(int i = 0; i < m_size; i++) tmp.Add(m_data[i]);
+ }
+
+ return tmp;
+ }
+
+ inline int GetSize() const { return m_size; }
+
+
+ inline const T& operator[](const int index) const
+ {
+ assert(index >= 0); // Lower Bounds Error
+ assert(index < m_size); // Upper Bounds Error
+ return m_data[index];
+ }
+
+ inline void Add(const T& value)
+ {
+ for (int i = 0; i < m_size; i++) if (m_data[i] == value) return;
+ int osize = m_size++;
+ T* new_data = new T[m_size];
+ for (int i = 0; i < osize; i++) new_data[i] = m_data[i];
+ new_data[osize] = value;
+ delete [] m_data;
+ m_data = new_data;
+ }
+
+ inline bool Has(const T& value) const
+ {
+ for (int i = 0; i < m_size; i++) if (m_data[i] == value) return true;
+ return false;
+ }
+
+ inline void Remove(const T& value)
+ {
+ int found = -1;
+ for (int i = 0; i < m_size; i++) {
+ if (m_data[i] == value) {
+ found = i;
+ break;
+ }
+ }
+
+ if (found > -1) {
+ int osize = m_size--;
+ T* new_data = new T[m_size];
+ for (int i = 0; i < found; i++) new_data[i] = m_data[i];
+ for (int i = found + 1; i < osize; i++) new_data[i - 1] = m_data[i];
+ delete [] m_data;
+ m_data = new_data;
+ }
+ }
+};
+
+#endif
Modified: branches/biounit/source/tools/tKVPair.h
===================================================================
--- branches/biounit/source/tools/tKVPair.h 2009-11-18 18:31:24 UTC (rev 3532)
+++ branches/biounit/source/tools/tKVPair.h 2009-11-18 19:28:01 UTC (rev 3533)
@@ -32,6 +32,7 @@
public:
inline tKVPair() { ; }
+ inline tKVPair(const K& key) : m_key(key) { ; }
inline tKVPair(const K& key, const V& value) : m_key(key), m_value(value) { ; }
inline tKVPair(const tKVPair& p) : m_key(p.m_key), m_value(p.m_value) { ; }
More information about the Avida-cvs
mailing list