[Avida-SVN] r3554 - in branches/biounit/source: . classification cpu main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Tue Dec 15 12:39:00 PST 2009


Author: brysonda
Date: 2009-12-15 15:39:00 -0500 (Tue, 15 Dec 2009)
New Revision: 3554

Modified:
   branches/biounit/source/classification/cBGGenotype.cc
   branches/biounit/source/classification/cBGGenotype.h
   branches/biounit/source/classification/cBGGenotypeManager.cc
   branches/biounit/source/cpu/cTestCPU.cc
   branches/biounit/source/defs.h
   branches/biounit/source/main/avida.cc
   branches/biounit/source/main/cBirthChamber.cc
   branches/biounit/source/main/cOrganism.cc
   branches/biounit/source/main/cOrganism.h
   branches/biounit/source/main/cPhenotype.cc
   branches/biounit/source/main/cPhenotype.h
   branches/biounit/source/main/cPopulation.cc
Log:
Add generation born tracking to cBGGenotype.  Output genotype source.  Properly adjust genotypes that have organisms breed into the genotype.

Modified: branches/biounit/source/classification/cBGGenotype.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotype.cc	2009-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/classification/cBGGenotype.cc	2009-12-15 20:39:00 UTC (rev 3554)
@@ -39,6 +39,7 @@
   , m_threshold(false)
   , m_active(true)
   , m_id(in_id)
+  , m_generation_born(founder->GetPhenotype().GetGeneration())
   , m_update_born(update)
   , m_update_deactivated(-1)
   , m_depth(0)
@@ -115,6 +116,7 @@
 void cBGGenotype::Save(cDataFile& df)
 {
   df.Write(m_id, "ID");
+  df.Write(Avida::BioUnitSourceMap[m_src], "Source");
   cString parent_str("");
   if (m_parents.GetSize()) {
     parent_str += cStringUtil::Stringf("%d", m_parents[0]->GetID());
@@ -129,6 +131,7 @@
   df.Write(m_merit.Average(), "Average Merit");
   df.Write(m_gestation_time.Average(), "Average Gestation Time");
   df.Write(m_fitness.Average(), "Average Fitness");
+  df.Write(m_generation_born, "Generation Born");
   df.Write(m_update_born, "Update Born");
   df.Write(m_update_deactivated, "Update Deactivated");
   df.Write(m_depth, "Phylogenetic Depth");
@@ -142,15 +145,21 @@
 {
   // Handle source branching
   switch (m_src) {
+    case SRC_DEME_COMPETE:
+    case SRC_DEME_COPY:
     case SRC_DEME_GERMLINE:
     case SRC_DEME_REPLICATE:
+    case SRC_DEME_SPAWN:
     case SRC_ORGANISM_COMPETE:
     case SRC_ORGANISM_DIVIDE:
     case SRC_ORGANISM_FILE_LOAD:
     case SRC_ORGANISM_RANDOM:
       switch (bu->GetUnitSource()) {
+        case SRC_DEME_COMPETE:
+        case SRC_DEME_COPY:
         case SRC_DEME_GERMLINE:
         case SRC_DEME_REPLICATE:
+        case SRC_DEME_SPAWN:
         case SRC_ORGANISM_COMPETE:
         case SRC_ORGANISM_DIVIDE:
         case SRC_ORGANISM_FILE_LOAD:
@@ -171,8 +180,11 @@
     case SRC_PARASITE_FILE_LOAD:
     case SRC_PARASITE_INJECT:
       switch (bu->GetUnitSource()) {
+        case SRC_DEME_COMPETE:
+        case SRC_DEME_COPY:
         case SRC_DEME_GERMLINE:
         case SRC_DEME_REPLICATE:
+        case SRC_DEME_SPAWN:
         case SRC_ORGANISM_COMPETE:
         case SRC_ORGANISM_DIVIDE:
         case SRC_ORGANISM_FILE_LOAD:
@@ -202,6 +214,16 @@
   return (m_genome == bu->GetMetaGenome());
 }
 
+void cBGGenotype::NotifyNewBioUnit(cBioUnit* bu)
+{
+  m_breed_in.Inc();
+  m_total_organisms++;
+  m_num_organisms++;
+  m_mgr->AdjustGenotype(this, m_num_organisms - 1, m_num_organisms);
+  AddActiveReference();
+}
+
+
 void cBGGenotype::UpdateReset()
 {
   m_last_num_organisms = m_num_organisms;

Modified: branches/biounit/source/classification/cBGGenotype.h
===================================================================
--- branches/biounit/source/classification/cBGGenotype.h	2009-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/classification/cBGGenotype.h	2009-12-15 20:39:00 UTC (rev 3554)
@@ -62,6 +62,7 @@
   };
   
   int m_id;
+  int m_generation_born;
   int m_update_born;
   int m_update_deactivated;
   int m_depth;
@@ -127,7 +128,7 @@
   inline const tArray<cBGGenotype*> GetParents() const { return m_parents; }
 
   bool Matches(cBioUnit* bu);
-  inline void NotifyNewBioUnit(cBioUnit* bu) { m_total_organisms++; m_num_organisms++; m_breed_in.Inc(); AddActiveReference(); }
+  void NotifyNewBioUnit(cBioUnit* bu);
   void UpdateReset();
 };
 

Modified: branches/biounit/source/classification/cBGGenotypeManager.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotypeManager.cc	2009-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/classification/cBGGenotypeManager.cc	2009-12-15 20:39:00 UTC (rev 3554)
@@ -69,7 +69,7 @@
 
 void cBGGenotypeManager::SaveBioGroups(cDataFile& df)
 {
-  // @TODO - Just dump historic for now.  Need structure output format to support top down save
+  // @TODO - Just dump historic for now.  Need structured output format to support top down save
   //         With a structured save (and save params passed through), a "structured population save" could be attained
   //         by simply calling the bio group save.  As it stands right now, cPopulation must decorate columns with additional
   //         data about active genotypes, yet the bio group interface really shouldn't know about active/inactive genotypes.

Modified: branches/biounit/source/cpu/cTestCPU.cc
===================================================================
--- branches/biounit/source/cpu/cTestCPU.cc	2009-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/cpu/cTestCPU.cc	2009-12-15 20:39:00 UTC (rev 3554)
@@ -288,8 +288,8 @@
   }
   cOrganism* organism = NULL;
   
-  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);
+  if (test_info.GetInstSet()) organism = new cOrganism(m_world, ctx, genome, test_info.GetInstSet(), -1, SRC_TEST_CPU);
+  else organism = new cOrganism(m_world, ctx, genome, -1, 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-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/defs.h	2009-12-15 20:39:00 UTC (rev 3554)
@@ -211,5 +211,9 @@
   SRC_TEST_CPU
 };
 
+namespace Avida {
+  extern const char* const BioUnitSourceMap[];
+};
 
+
 #endif

Modified: branches/biounit/source/main/avida.cc
===================================================================
--- branches/biounit/source/main/avida.cc	2009-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/main/avida.cc	2009-12-15 20:39:00 UTC (rev 3554)
@@ -49,6 +49,22 @@
 
 namespace Avida {
   
+
+const char* const BioUnitSourceMap[] = {
+  "deme:compete", // SRC_DEME_COMPETE
+  "deme:copy", // SRC_DEME_COPY
+  "deme:germline", // SRC_DEME_GERMLINE
+  "deme:replicate", // SRC_DEME_REPLICATE
+  "deme:spawn", // SRC_DEME_SPAWN
+  "org:compete", // SRC_ORGANISM_COMPETE
+  "org:divide", // SRC_ORGANISM_DIVIDE
+  "org:file_load", // SRC_ORGANISM_FILE_LOAD
+  "org:random", // SRC_ORGANISM_RANDOM
+  "para:file_load", // SRC_PARASITE_FILE_LOAD
+  "para:inject", // SRC_PARASITE_INJECT
+  "testcpu", // SRC_TEST_CPU
+};
+  
 void Initialize()
 {
   cActionLibrary::Initialize();

Modified: branches/biounit/source/main/cBirthChamber.cc
===================================================================
--- branches/biounit/source/main/cBirthChamber.cc	2009-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/main/cBirthChamber.cc	2009-12-15 20:39:00 UTC (rev 3554)
@@ -182,7 +182,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, SRC_ORGANISM_DIVIDE);
+  child_array[0] = new cOrganism(m_world, ctx, offspring, parent.GetPhenotype().GetGeneration(), SRC_ORGANISM_DIVIDE);
   merit_array.Resize(1);
   
   if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
@@ -227,8 +227,8 @@
 {
   // Build both child organisms...
   child_array.Resize(2);
-  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);
+  child_array[0] = new cOrganism(m_world, ctx, old_entry.genome, parent.GetPhenotype().GetGeneration(), SRC_ORGANISM_DIVIDE);
+  child_array[1] = new cOrganism(m_world, ctx, new_genome, parent.GetPhenotype().GetGeneration(), SRC_ORGANISM_DIVIDE);
 
   // Setup the merits for both children...
   merit_array.Resize(2);
@@ -503,8 +503,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, SRC_ORGANISM_DIVIDE);
-    child_array[1] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome1, SRC_ORGANISM_DIVIDE);
+    child_array[0] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome0, parent_phenotype.GetGeneration(), SRC_ORGANISM_DIVIDE);
+    child_array[1] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome1, parent_phenotype.GetGeneration(), SRC_ORGANISM_DIVIDE);
     
     if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
       child_array[0]->GetPhenotype().SetEnergy(meritOrEnergy0);
@@ -527,7 +527,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, SRC_ORGANISM_DIVIDE);
+      child_array[0] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome0, parent_phenotype.GetGeneration(), 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());
@@ -538,7 +538,7 @@
       SetupGenotypeInfo(child_array[0], parent0_genotype, parent0_groups, parent1_genotype, parent1_groups);
     } 
     else {
-      child_array[0] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome1, SRC_ORGANISM_DIVIDE);
+      child_array[0] = new cOrganism(m_world, ctx, hw_type, inst_set_id, genome1, parent_phenotype.GetGeneration(), 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-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/main/cOrganism.cc	2009-12-15 20:39:00 UTC (rev 3554)
@@ -54,11 +54,11 @@
 using namespace std;
 
 
-cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, eBioUnitSource src,
+cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, int parent_generation, eBioUnitSource src,
                      const cString& src_args)
   : m_world(world)
   , m_genotype(NULL)
-  , m_phenotype(world)
+  , m_phenotype(world, parent_generation)
   , m_src(src)
   , m_src_args(src_args)
   , m_initial_genome(genome)
@@ -99,10 +99,10 @@
   initialize(ctx);
 }
 cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, int hw_type, int inst_set_id, const cGenome& genome,
-                     eBioUnitSource src, const cString& src_args)
+                     int parent_generation, eBioUnitSource src, const cString& src_args)
   : m_world(world)
   , m_genotype(NULL)
-  , m_phenotype(world)
+  , m_phenotype(world, parent_generation)
   , m_src(src)
   , m_src_args(src_args)
   , m_initial_genome(hw_type, inst_set_id, genome)
@@ -142,11 +142,11 @@
   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, int parent_generation,
                      eBioUnitSource src, const cString& src_args)
   : m_world(world)
   , m_genotype(NULL)
-  , m_phenotype(world)
+  , m_phenotype(world, parent_generation)
   , m_src(src)
   , m_src_args(src_args)
   , m_initial_genome(genome)

Modified: branches/biounit/source/main/cOrganism.h
===================================================================
--- branches/biounit/source/main/cOrganism.h	2009-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/main/cOrganism.h	2009-12-15 20:39:00 UTC (rev 3554)
@@ -162,11 +162,12 @@
   cOrganism& operator=(const cOrganism&); // @not_implemented
   
 public:
-  cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, eBioUnitSource src, const cString& src_args = "");
+  cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, int parent_generation,
+            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 = "");
+            int parent_generation, eBioUnitSource src, const cString& src_args = "");
   cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, cInstSet* inst_set,
-            eBioUnitSource src, const cString& src_args = "");
+            int parent_generation, eBioUnitSource src, const cString& src_args = "");
   ~cOrganism();
   
   // --------  cBioUnit Methods  --------

Modified: branches/biounit/source/main/cPhenotype.cc
===================================================================
--- branches/biounit/source/main/cPhenotype.cc	2009-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/main/cPhenotype.cc	2009-12-15 20:39:00 UTC (rev 3554)
@@ -40,7 +40,7 @@
 using namespace std;
 
 
-cPhenotype::cPhenotype(cWorld* world)
+cPhenotype::cPhenotype(cWorld* world, int parent_generation)
   : m_world(world)
   , initialized(false)
   , cur_task_count(m_world->GetEnvironment().GetNumTasks())
@@ -69,7 +69,12 @@
   , last_reaction_count(m_world->GetEnvironment().GetReactionLib().GetSize())
   , last_reaction_add_reward(m_world->GetEnvironment().GetReactionLib().GetSize())  
   , last_sense_count(m_world->GetStats().GetSenseSize())
+  , generation(0)
 {
+  if (parent_generation >= 0) {
+    generation = parent_generation;
+    if (m_world->GetConfig().GENERATION_INC_METHOD.Get() != GENERATION_INC_BOTH) generation++;
+  }
 }
 
 cPhenotype::~cPhenotype()

Modified: branches/biounit/source/main/cPhenotype.h
===================================================================
--- branches/biounit/source/main/cPhenotype.h	2009-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/main/cPhenotype.h	2009-12-15 20:39:00 UTC (rev 3554)
@@ -262,7 +262,7 @@
   inline void SetInstSetSize(int inst_set_size);
 
   
-  cPhenotype(cWorld* world);
+  cPhenotype(cWorld* world, int parent_generation);
 
   
 public:
@@ -400,7 +400,7 @@
   int GetLastCollectSpecCount(int spec_id) const { assert(initialized == true); return last_collect_spec_counts[spec_id]; }
 
   int GetNumDivides() const { assert(initialized == true); return num_divides;}
-  int GetGeneration() const { assert(initialized == true); return generation; }
+  int GetGeneration() const { return generation; }
   int GetCPUCyclesUsed() const { assert(initialized == true); return cpu_cycles_used; }
   int GetTimeUsed()   const { assert(initialized == true); return time_used; }
   int GetTrialTimeUsed()   const { assert(initialized == true); return trial_time_used; }

Modified: branches/biounit/source/main/cPopulation.cc
===================================================================
--- branches/biounit/source/main/cPopulation.cc	2009-12-15 15:40:55 UTC (rev 3553)
+++ branches/biounit/source/main/cPopulation.cc	2009-12-15 20:39:00 UTC (rev 3554)
@@ -5161,8 +5161,12 @@
   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, src);
+  cOrganism* new_organism = new cOrganism(m_world, ctx, tmp_genome, -1, src);
   
+  // Setup the phenotype...
+  cPhenotype & phenotype = new_organism->GetPhenotype();
+  phenotype.SetupInject(new_genotype->GetGenome());  //TODO  sets merit to lenght of genotype
+  
   // Classify this new organism
   m_world->GetClassificationManager().ClassifyNewBioUnit(new_organism);
   
@@ -5172,10 +5176,6 @@
   // Set the genotype...
   new_organism->SetGenotype(new_genotype);
   
-  // Setup the phenotype...
-  cPhenotype & phenotype = new_organism->GetPhenotype();
-  phenotype.SetupInject(new_genotype->GetGenome());  //TODO  sets merit to lenght of genotype
-  
   if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
     phenotype.SetMerit(cMerit(phenotype.ConvertEnergyToMerit(phenotype.GetStoredEnergy())));
   } else {
@@ -5232,7 +5232,7 @@
   
   cAvidaContext& ctx = m_world->GetDefaultContext();
   
-  cOrganism* new_organism = new cOrganism(m_world, ctx, orig_org.GetMetaGenome(), src);
+  cOrganism* new_organism = new cOrganism(m_world, ctx, orig_org.GetMetaGenome(), orig_org.GetPhenotype().GetGeneration(), src);
 
   // Classify the new organism
   m_world->GetClassificationManager().ClassifyNewBioUnit(new_organism);
@@ -5278,7 +5278,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, SRC_ORGANISM_COMPETE);
+  cOrganism* new_organism = new cOrganism(m_world, ctx, child_genome, parent.GetPhenotype().GetGeneration(), SRC_ORGANISM_COMPETE);
   
   // Classify the offspring
   tArray<const tArray<cBioGroup*>*> pgrps(1);




More information about the Avida-cvs mailing list