[Avida-SVN] r3574 - in branches/biounit/source: actions classification cpu main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Tue Dec 22 08:56:54 PST 2009


Author: brysonda
Date: 2009-12-22 11:56:54 -0500 (Tue, 22 Dec 2009)
New Revision: 3574

Modified:
   branches/biounit/source/actions/LandscapeActions.cc
   branches/biounit/source/actions/PopulationActions.cc
   branches/biounit/source/actions/PrintActions.cc
   branches/biounit/source/classification/cClassificationManager.cc
   branches/biounit/source/classification/cGenotype.cc
   branches/biounit/source/classification/cGenotype.h
   branches/biounit/source/classification/cLineage.cc
   branches/biounit/source/cpu/cTestCPUInterface.cc
   branches/biounit/source/cpu/cTestCPUInterface.h
   branches/biounit/source/main/cDeme.cc
   branches/biounit/source/main/cDeme.h
   branches/biounit/source/main/cOrgInterface.h
   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/main/cPopulationInterface.cc
   branches/biounit/source/main/cPopulationInterface.h
   branches/biounit/source/main/cStats.cc
   branches/biounit/source/main/cStats.h
Log:
Begin the work of excising the old cGenotype class.

Modified: branches/biounit/source/actions/LandscapeActions.cc
===================================================================
--- branches/biounit/source/actions/LandscapeActions.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/actions/LandscapeActions.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -1071,7 +1071,7 @@
         df.Write(orgdata->GetCellID(), "Cell ID");
         df.Write(name, "Organism Name");
         df.Write(genotype->GetLength(),"Genome Length");
-        df.Write(genotype->GetTestFitness(ctx), "Fitness (test-cpu)");
+        df.Write(organism->GetTestFitness(ctx), "Fitness (test-cpu)");
         df.Write(phenotype.GetFitness(), "Fitness (actual)");
         df.Write(genotype->GetBreedTrue(), "Breed True");
         df.Write(organism->GetLineageLabel(), "Lineage Label");

Modified: branches/biounit/source/actions/PopulationActions.cc
===================================================================
--- branches/biounit/source/actions/PopulationActions.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/actions/PopulationActions.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -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, SRC_DEME_GERMLINE);
+				m_world->GetPopulation().InjectGenome(*i, SRC_DEME_GERMLINE, deme.GetGermline().GetLatest());
 				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, SRC_DEME_GERMLINE);
+					m_world->GetPopulation().InjectGenome(cell.GetID(), SRC_DEME_GERMLINE, deme.GetGermline().GetLatest());
 					m_world->GetPopulation().DemePostInjection(deme, cell);
 				}
 			}

Modified: branches/biounit/source/actions/PrintActions.cc
===================================================================
--- branches/biounit/source/actions/PrintActions.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/actions/PrintActions.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -2034,11 +2034,11 @@
       
       // now output
       
-      sum_fitness += cur_genotype->GetTestFitness(ctx) * num_orgs;
+      sum_fitness += cur_genotype->GetFitness() * num_orgs;
       sum_num_organisms += num_orgs;
       
       df.Write(cur_genotype->GetName(), "Genotype Name");
-      df.Write(cur_genotype->GetTestFitness(ctx), "Fitness (test-cpu)");
+      df.Write(cur_genotype->GetFitness(), "Fitness");
       df.Write(num_orgs, "Abundance");
       df.Write(cGenomeUtil::FindHammingDistance(reference_genome, genome), "Hamming distance to reference");
       df.Write(cGenomeUtil::FindEditDistance(reference_genome, genome), "Levenstein distance to reference");
@@ -2245,7 +2245,7 @@
     
     for (int i = 0; i < pop.GetSize(); i++) {
       if (!pop.GetCell(i).IsOccupied()) continue;
-      if (pop.GetCell(i).GetOrganism()->GetGenotype()->GetTestFitness(ctx) > 0.0) {
+      if (pop.GetCell(i).GetOrganism()->GetTestFitness(ctx) > 0.0) {
         cPhenotype& phenotype = pop.GetCell(i).GetOrganism()->GetPhenotype();
         for (int j = 0; j < num_tasks; j++) if (phenotype.GetCurTaskCount()[j] > 0) tasks[j]++;
       }
@@ -2265,45 +2265,7 @@
 };
 
 
-class cActionPrintTreeDepths : public cAction
-{
-private:
-  cString m_filename;
-  
-public:
-  cActionPrintTreeDepths(cWorld* world, const cString& args) : cAction(world, args), m_filename("")
-  {
-    cString largs(args);
-    if (largs.GetSize()) m_filename = largs.PopWord();  
-  }
-  static const cString GetDescription() { return "Arguments: [string fname='']"; }
-  void Process(cAvidaContext& ctx)
-  {
-    cString filename(m_filename);
-    if (filename == "") filename.Set("tree_depth.%d.dat", m_world->GetStats().GetUpdate());
-    cDataFile& df = m_world->GetDataFile(filename);
-    
-    //    cPopulation& pop = m_world->GetPopulation();
-    cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
-    
-    cGenotype* genotype = m_world->GetClassificationManager().GetBestGenotype();
-    for (int i = 0; i < m_world->GetClassificationManager().GetGenotypeCount(); i++) {
-      df.Write(genotype->GetID(), "Genotype ID");
-      df.Write(genotype->GetTestFitness(ctx), "Fitness");
-      df.Write(genotype->GetNumOrganisms(), "Abundance");
-      df.Write(genotype->GetDepth(), "Tree Depth");
-      df.Endl();
-      
-      // ...and advance to the next genotype...
-      genotype = genotype->GetNext();
-    }
-    
-    m_world->GetDataFileManager().Remove(filename);
-    delete testcpu;
-  }
-};
 
-
 class cActionCalcConsensus : public cAction
 {
 private:
@@ -3263,7 +3225,6 @@
   action_lib->Register<cActionPrintTaskSnapshot>("PrintTaskSnapshot");
   action_lib->Register<cActionPrintViableTasksData>("PrintViableTasksData");
   action_lib->Register<cActionPrintAveNumTasks>("PrintAveNumTasks");
-  action_lib->Register<cActionPrintTreeDepths>("PrintTreeDepths");
   
   action_lib->Register<cActionPrintGenomicSiteEntropy>("PrintGenomicSiteEntropy");
   
@@ -3331,7 +3292,6 @@
   action_lib->Register<cActionTestDominant>("test_dom");
   action_lib->Register<cActionPrintTaskSnapshot>("task_snapshot");
   action_lib->Register<cActionPrintViableTasksData>("print_viable_tasks_data");
-  action_lib->Register<cActionPrintTreeDepths>("print_tree_depths");
 
   action_lib->Register<cActionDumpMemory>("dump_memory");
   action_lib->Register<cActionDumpFitnessGrid>("dump_fitness_grid");

Modified: branches/biounit/source/classification/cClassificationManager.cc
===================================================================
--- branches/biounit/source/classification/cClassificationManager.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/classification/cClassificationManager.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -907,9 +907,11 @@
   
   if (parent_genotype != NULL) {
     assert( parent_genotype->GetNumOrganisms() > 0 );
-    parent_fitness = parent_genotype->GetTestColonyFitness(ctx);
+// @TODO    parent_fitness = parent_genotype->GetTestColonyFitness(ctx);
+    parent_fitness = parent_genotype->GetFitness();
   }
-  double child_fitness = child_genotype->GetTestColonyFitness(ctx);
+// @TODO  double child_fitness = child_genotype->GetTestColonyFitness(ctx);
+  double child_fitness = child_genotype->GetFitness();
   cLineage * child_lineage = parent_lineage;
   bool create_lineage = false;
   double lineage_stat1 = child_fitness;
@@ -963,10 +965,12 @@
         break;
       case 4: // new lineage whenever a new child exceeds the
               // fitness of the dominant creature (and the fitness of its own lineage)
-        if (child_fitness > m_world->GetClassificationManager().GetBestGenotype()->GetTestColonyFitness(ctx)
+// @TODO        if (child_fitness > m_world->GetClassificationManager().GetBestGenotype()->GetTestColonyFitness(ctx)
+        if (child_fitness > m_world->GetClassificationManager().GetBestGenotype()->GetFitness()
             && child_fitness > parent_lineage->GetMaxFitness() ){
           create_lineage = true;
-          lineage_stat1=m_world->GetClassificationManager().GetBestGenotype()->GetTestColonyFitness(ctx);
+// @TODO          lineage_stat1=m_world->GetClassificationManager().GetBestGenotype()->GetTestColonyFitness(ctx);
+          lineage_stat1=m_world->GetClassificationManager().GetBestGenotype()->GetFitness();
           lineage_stat2=parent_lineage->GetMaxFitness();
         }
         break;

Modified: branches/biounit/source/classification/cGenotype.cc
===================================================================
--- branches/biounit/source/classification/cGenotype.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/classification/cGenotype.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -223,28 +223,8 @@
   name.Set("%03d-no_name", genome.GetSize());
 }
 
-void cGenotype::CalcTestStats(cAvidaContext& ctx) const
-{
-  cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
 
-  cCPUTestInfo test_info;
-  testcpu->TestGenome(ctx, test_info, genome);
-  test_data.is_viable = test_info.IsViable();
-  delete testcpu;
 
-  // Setup all possible test values.
-  cPhenotype & phenotype = test_info.GetTestPhenotype();
-  test_data.fitness = test_info.GetGenotypeFitness();
-  test_data.merit = phenotype.GetMerit().GetDouble();
-  test_data.gestation_time = phenotype.GetGestationTime();
-  test_data.executed_size = phenotype.GetExecutedSize();
-  test_data.copied_size = phenotype.GetCopiedSize();
-  test_data.colony_fitness = test_info.GetColonyFitness();
-  test_data.generations = test_info.GetMaxDepth();
-}
-
-
-
 double cGenotype::GetTaskProbability(cAvidaContext& ctx, int task_id) const{
   CheckPhenPlast(ctx);
   assert(task_id >= 0 && task_id < m_phenplast_stats->m_task_probabilities.GetSize());

Modified: branches/biounit/source/classification/cGenotype.h
===================================================================
--- branches/biounit/source/classification/cGenotype.h	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/classification/cGenotype.h	2009-12-22 16:56:54 UTC (rev 3574)
@@ -91,22 +91,7 @@
     tArray<int> ancestor_ids;
   };  
 
-  class cTestData {
-  public:
-    cTestData() : fitness(-1) { ; }
-    ~cTestData() { ; }
-    
-    bool is_viable;
-    
-    double fitness;
-    double merit;
-    int gestation_time;
-    int executed_size;
-    int copied_size;
-    double colony_fitness;
-    int generations;
-  };
-    
+   
   
 private:  
   cWorld* m_world;
@@ -124,7 +109,6 @@
   char symbol;
   int map_color_id;
 
-  mutable cTestData test_data;
   cBirthData birth_data;
   mutable cPhenPlastSummary* m_phenplast_stats;
   
@@ -187,15 +171,6 @@
   void SetSpecies(cSpecies * in_species) { species = in_species; }
 
  
-  // Test CPU info -- only used with limited options on.
-  inline bool GetTestViable(cAvidaContext& ctx) const;
-  inline double GetTestFitness(cAvidaContext& ctx) const;
-  inline double GetTestMerit(cAvidaContext& ctx) const;
-  inline int GetTestGestationTime(cAvidaContext& ctx) const;
-  inline int GetTestExecutedSize(cAvidaContext& ctx) const;
-  inline int GetTestCopiedSize(cAvidaContext& ctx) const;
-  inline double GetTestColonyFitness(cAvidaContext& ctx) const;
-  inline int GetTestGenerations(cAvidaContext& ctx) const;
   
   inline void CheckPhenPlast(cAvidaContext& ctx) const{ if (m_phenplast_stats == NULL) TestPlasticity(ctx);}
   int    GetNumPhenotypes(cAvidaContext& ctx)     const { CheckPhenPlast(ctx); return m_phenplast_stats->m_num_phenotypes; }
@@ -374,53 +349,6 @@
   }
 }
 
-inline bool cGenotype::GetTestViable(cAvidaContext& ctx) const {
-  if (test_data.fitness == -1) CalcTestStats(ctx);
-  return test_data.is_viable;
-}
-
-
-inline double cGenotype::GetTestFitness(cAvidaContext& ctx) const {
-  if (test_data.fitness == -1) CalcTestStats(ctx);
-  return test_data.fitness;
-}
-
-
-inline double cGenotype::GetTestMerit(cAvidaContext& ctx) const {
-  if (test_data.fitness == -1) CalcTestStats(ctx);
-  return test_data.merit;
-}
-
-
-inline int cGenotype::GetTestGestationTime(cAvidaContext& ctx) const {
-  if (test_data.fitness == -1) CalcTestStats(ctx);
-  return test_data.gestation_time;
-}
-
-
-inline int cGenotype::GetTestExecutedSize(cAvidaContext& ctx) const {
-  if (test_data.fitness == -1) CalcTestStats(ctx);
-  return test_data.executed_size;
-}
-
-
-inline int cGenotype::GetTestCopiedSize(cAvidaContext& ctx) const {
-  if (test_data.fitness == -1) CalcTestStats(ctx);
-  return test_data.copied_size;
-}
-
-
-inline double cGenotype::GetTestColonyFitness(cAvidaContext& ctx) const {
-  if (test_data.fitness == -1) CalcTestStats(ctx);
-  return test_data.colony_fitness;
-}
-
-
-inline int cGenotype::GetTestGenerations(cAvidaContext& ctx) const {
-  if (test_data.fitness == -1) CalcTestStats(ctx);
-  return test_data.generations;
-}
-
 inline void cGenotype::Deactivate(int update, int org_id)
 {
   m_is_active = false;

Modified: branches/biounit/source/classification/cLineage.cc
===================================================================
--- branches/biounit/source/classification/cLineage.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/classification/cLineage.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -70,7 +70,8 @@
   //     m_genotype_map[ genotype ] += 1;
   // if we didn't want to count how often we add a new genotype
 
-  double fitness = genotype->GetTestColonyFitness(ctx);
+// @TODO  double fitness = genotype->GetTestColonyFitness(ctx);
+  double fitness = genotype->GetFitness();
 
   // adjust the current maximum fitness
   if (fitness > m_max_fitness) m_max_fitness = fitness;
@@ -104,7 +105,8 @@
   // and adjust the average fitness
   m_ave_fitness_changed = true;
 
-  double fitness = genotype->GetTestColonyFitness(ctx);
+// @TODO  double fitness = genotype->GetTestColonyFitness(ctx);
+  double fitness = genotype->GetFitness();
 
   // did we reach zero?
   if ((*cur).second == 0) {
@@ -140,7 +142,8 @@
   // we calculate the average fitness as well, since it is so easy.
   m_ave_fitness = 0;
   for (; it!=m_genotype_map.end(); it++) {
-    double fitness = (*it).first->GetTestColonyFitness(ctx);
+// @TODO    double fitness = (*it).first->GetTestColonyFitness(ctx);
+    double fitness = (*it).first->GetFitness();
     if (fitness > m_max_fitness) m_max_fitness = fitness;
     if (fitness > m_max_fitness_ever) m_max_fitness_ever = fitness;
     m_ave_fitness += fitness * (*it).second;

Modified: branches/biounit/source/cpu/cTestCPUInterface.cc
===================================================================
--- branches/biounit/source/cpu/cTestCPUInterface.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/cpu/cTestCPUInterface.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -24,7 +24,6 @@
 
 #include "cTestCPUInterface.h"
 
-#include "cGenotype.h"
 #include "cOrganism.h"
 #include "cTestCPU.h"
 
@@ -74,11 +73,6 @@
   return m_testcpu->GetInputs();
 }
 
-int cTestCPUInterface::Debug()
-{
-  return -1;
-}
-
 const tArray<double>& cTestCPUInterface::GetResources()
 {
   return m_testcpu->GetResources();  

Modified: branches/biounit/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/biounit/source/cpu/cTestCPUInterface.h	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/cpu/cTestCPUInterface.h	2009-12-22 16:56:54 UTC (rev 3574)
@@ -75,7 +75,6 @@
   int GetInputAt(int& input_pointer);
   void ResetInputs(cAvidaContext& ctx);
   const tArray<int>& GetInputs() const;
-  int Debug();
   const tArray<double>& GetResources();
   const tArray<double>& GetDemeResources(int deme_id);
   const tArray< tArray<int> >& GetCellIdLists();  

Modified: branches/biounit/source/main/cDeme.cc
===================================================================
--- branches/biounit/source/main/cDeme.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/main/cDeme.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -143,6 +143,22 @@
   return GetCell(pos).GetOrganism();
 }
 
+std::vector<int> cDeme::GetGenotypeIDs()
+{
+  std::vector<int> genotype_ids;
+  for (int i = 0; i < GetSize(); i++) {
+    cPopulationCell& cell = GetCell(i);
+    if (cell.IsOccupied()) genotype_ids.push_back(cell.GetOrganism()->GetGenotype()->GetID());
+  }
+
+  //assert(genotype_ids.size()>0); // How did we get to replication otherwise?
+  //@JEB some germline methods can result in empty source demes if they didn't produce a germ)
+  
+  return genotype_ids;
+}
+
+
+
 int cDeme::GetNumOrgsWithOpinion() const {
 	int demeSize = GetSize();
 	int count = 0;

Modified: branches/biounit/source/main/cDeme.h
===================================================================
--- branches/biounit/source/main/cDeme.h	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/main/cDeme.h	2009-12-22 16:56:54 UTC (rev 3574)
@@ -161,6 +161,8 @@
   cPopulationCell& GetCell(int pos) const;
 	cPopulationCell& GetCell(int x, int y) const;
   cOrganism* GetOrganism(int pos) const;
+  
+  std::vector<int> GetGenotypeIDs();
 
   int GetWidth() const { return width; }
   int GetHeight() const { return cell_ids.GetSize() / width; }

Modified: branches/biounit/source/main/cOrgInterface.h
===================================================================
--- branches/biounit/source/main/cOrgInterface.h	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/main/cOrgInterface.h	2009-12-22 16:56:54 UTC (rev 3574)
@@ -87,7 +87,6 @@
   virtual int GetInputAt(int& input_pointer) = 0;
   virtual void ResetInputs(cAvidaContext& ctx) = 0;
   virtual const tArray<int>& GetInputs() const = 0;
-  virtual int Debug() = 0;
   virtual const tArray<double>& GetResources() = 0;
   virtual const tArray<double>& GetDemeResources(int deme_id) = 0;  
   virtual const tArray< tArray<int> >& GetCellIdLists() = 0; 

Modified: branches/biounit/source/main/cOrganism.cc
===================================================================
--- branches/biounit/source/main/cOrganism.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/main/cOrganism.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -32,7 +32,6 @@
 #include "functions.h"
 #include "cGenome.h"
 #include "cGenomeUtil.h"
-#include "cGenotype.h"
 #include "cHardwareBase.h"
 #include "cHardwareManager.h"
 #include "cInstSet.h"
@@ -268,12 +267,23 @@
   m_phenotype.SetCurCollectSpecCount(spec_id, current_count + 1);
 }
 
-double cOrganism::GetTestFitness(cAvidaContext& ctx)
+void cOrganism::calcTestData(cAvidaContext& ctx) const
 {
-  assert(m_interface);
-  return m_genotype->GetTestFitness(ctx);
+  cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
+  
+  cCPUTestInfo test_info;
+  testcpu->TestGenome(ctx, test_info, m_initial_genome.GetGenome());
+  delete testcpu;
+  
+  // Setup all possible test values.
+  cPhenotype & phenotype = test_info.GetTestPhenotype();
+  m_test_data.fitness = test_info.GetGenotypeFitness();
+  m_test_data.merit = phenotype.GetMerit().GetDouble();
+  m_test_data.colony_fitness = test_info.GetColonyFitness();
 }
-  
+
+
+
 int cOrganism::ReceiveValue()
 {
   assert(m_interface);

Modified: branches/biounit/source/main/cOrganism.h
===================================================================
--- branches/biounit/source/main/cOrganism.h	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/main/cOrganism.h	2009-12-22 16:56:54 UTC (rev 3574)
@@ -154,7 +154,16 @@
   };
   cNetSupport* m_net;
   
+  mutable struct sTestData
+  {
+    double fitness;
+    double merit;
+    double colony_fitness;
+
+    sTestData() : fitness(-1) { ; }
+  } m_test_data;
   
+  
   cOrganism(); // @not_implemented
   cOrganism(const cOrganism&); // @not_implemented
   cOrganism& operator=(const cOrganism&); // @not_implemented
@@ -175,7 +184,9 @@
   
 
   // --------  Support Methods  --------
-  double GetTestFitness(cAvidaContext& ctx);
+  inline double GetTestFitness(cAvidaContext& ctx) const;
+  inline double GetTestMerit(cAvidaContext& ctx) const;
+  inline double GetTestColonyFitness(cAvidaContext& ctx) const;
   double CalcMeritRatio();
   
   void HardwareReset(cAvidaContext& ctx);
@@ -271,7 +282,6 @@
   void Die() { m_interface->Die(); m_is_dead = true; }
   void Kaboom(int dist) { m_interface->Kaboom(dist);}
   void SpawnDeme() { m_interface->SpawnDeme(); }
-  int GetDebugInfo() { return m_interface->Debug(); }
   bool GetSentActive() { return m_sent_active; }
   void SendValue(int value) { m_sent_active = true; m_sent_value = value; }
   int RetrieveSentValue() { m_sent_active = false; return m_sent_value; }
@@ -657,8 +667,25 @@
   
   /*! The main DoOutput function.  The DoOutputs above all forward to this function. */
   void doOutput(cAvidaContext& ctx, tBuffer<int>& input_buffer, tBuffer<int>& output_buffer, const bool on_divide);
+  
+  void calcTestData(cAvidaContext& ctx) const;
 };
 
 
+inline double cOrganism::GetTestFitness(cAvidaContext& ctx) const {
+  if (m_test_data.fitness == -1) calcTestData(ctx);
+  return m_test_data.fitness;
+}
+
+inline double cOrganism::GetTestMerit(cAvidaContext& ctx) const {
+  if (m_test_data.fitness == -1) calcTestData(ctx);
+  return m_test_data.merit;
+}
+
+inline double cOrganism::GetTestColonyFitness(cAvidaContext& ctx) const {
+  if (m_test_data.fitness == -1) calcTestData(ctx);
+  return m_test_data.colony_fitness;
+}
+
 #endif
 

Modified: branches/biounit/source/main/cPopulation.cc
===================================================================
--- branches/biounit/source/main/cPopulation.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/main/cPopulation.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -1597,7 +1597,7 @@
         if (GetCell(cellid).IsOccupied()) {          
           int lineage = GetCell(cellid).GetOrganism()->GetLineageLabel();
           cGenome genome = GetCell(cellid).GetOrganism()->GetGenome();
-          InjectGenome(cellid, genome, lineage, SRC_DEME_REPLICATE);
+          InjectGenome(cellid, SRC_DEME_REPLICATE, genome, lineage);
         }
       }
     }
@@ -1863,7 +1863,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);
-    InjectGenome(cellid, genome, 0, src);
+    InjectGenome(cellid, src, genome, 0);
     DemePostInjection(deme, cell_array[cellid]);
   }
 }
@@ -1876,7 +1876,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, src);
+    InjectGenome(cellid, src, _genotype.GetGenome());
     DemePostInjection(_deme, cell_array[cellid]);
     _deme.AddFounder(_genotype);
   }
@@ -1955,11 +1955,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, SRC_DEME_REPLICATE);
+        InjectGenome(cellid, SRC_DEME_REPLICATE, i->first, i->second);
         DemePostInjection(source_deme, cell_array[cellid]);
         
         cellid = DemeSelectInjectionCell(target_deme, j);
-        InjectGenome(cellid, i->first, i->second, SRC_DEME_REPLICATE);
+        InjectGenome(cellid, SRC_DEME_REPLICATE, i->first, i->second);
         DemePostInjection(target_deme, cell_array[cellid]);      
         
       }
@@ -2425,7 +2425,7 @@
         
         // And inject it into target deme.
         int target_cellid = DemeSelectInjectionCell(target_deme, j++);
-        InjectGenome(target_cellid, genome, lineage, SRC_DEME_REPLICATE);
+        InjectGenome(target_cellid, SRC_DEME_REPLICATE, genome, lineage);
         DemePostInjection(target_deme, cell_array[target_cellid]);
       } 
       //else {
@@ -2441,7 +2441,7 @@
 {
   // phenotype can be NULL
   
-  InjectGenotype(_cell_id, &_genotype, SRC_DEME_REPLICATE);
+  InjectGenome(_cell_id, SRC_DEME_REPLICATE, _genotype.GetGenome());
   
   // At this point, the cell had better be occupied...
   assert(GetCell(_cell_id).IsOccupied());
@@ -4432,7 +4432,6 @@
   cGenotype * dom_genotype = m_world->GetClassificationManager().GetBestGenotype();
   if (dom_genotype == NULL) return;
   
-  stats.SetDomGenotype(dom_genotype);
   stats.SetDomMerit(dom_genotype->GetMerit());
   stats.SetDomGestation(dom_genotype->GetGestationTime());
   stats.SetDomReproRate(dom_genotype->GetReproRate());
@@ -4564,7 +4563,7 @@
     }
     
     assert(genotype_index != -1);
-    InjectGenome(i, genotype_array[genotype_index]->GetGenome(), 0, SRC_ORGANISM_FILE_LOAD);
+    InjectGenome(i, SRC_ORGANISM_FILE_LOAD, genotype_array[genotype_index]->GetGenome());
   }
   
   sync_events = true;
@@ -4668,7 +4667,7 @@
           soup_full = true;
           break;
         }	  
-        InjectGenotype(current_cell, (*it).genotype, SRC_ORGANISM_FILE_LOAD);
+        InjectGenome(current_cell, SRC_ORGANISM_FILE_LOAD, (*it).genotype->GetGenome());
         cPhenotype & phenotype = GetCell(current_cell).GetOrganism()->GetPhenotype();
         if ( (*it).merit > 0) phenotype.SetMerit( cMerit((*it).merit) );
         AdjustSchedule(GetCell(current_cell), phenotype.GetMerit());
@@ -4974,7 +4973,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, SRC_ORGANISM_FILE_LOAD);
+        InjectGenome(cell_id, SRC_ORGANISM_FILE_LOAD, tmp.genotype->GetGenome());
         
         cPhenotype& phenotype = GetCell(cell_id).GetOrganism()->GetPhenotype();
         
@@ -5065,7 +5064,7 @@
     }
   }
   
-  InjectGenome(cell_id, genome, lineage_label, src);
+  InjectGenome(cell_id, src, genome, lineage_label);
   cPhenotype& phenotype = GetCell(cell_id).GetOrganism()->GetPhenotype();
   phenotype.SetNeutralMetric(neutral);
   
@@ -5222,80 +5221,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, eBioUnitSource src)
-{
-  assert(cell_id >= 0 && cell_id < cell_array.GetSize());
-  if (cell_id < 0 || cell_id >= cell_array.GetSize()) {
-    m_world->GetDriver().RaiseFatalException(1, "InjectGenotype into nonexistent cell");
-  }
-  
-  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, -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);
-  
-  //Coalescense Clade Setup
-  new_organism->SetCCladeLabel(-1);  
-  
-  // Set the genotype...
-  new_organism->SetGenotype(new_genotype);
-  
-  if (m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
-    phenotype.SetMerit(cMerit(phenotype.ConvertEnergyToMerit(phenotype.GetStoredEnergy())));
-  } else {
-    phenotype.SetMerit(cMerit(new_genotype->GetTestMerit(ctx)));
-  }
-  
-  // @CAO are these really needed?
-  phenotype.SetLinesCopied( new_genotype->GetTestCopiedSize(ctx) );
-  phenotype.SetLinesExecuted( new_genotype->GetTestExecutedSize(ctx) );
-  phenotype.SetGestationTime( new_genotype->GetTestGestationTime(ctx) );
-  
-  // Prep the cell..
-  if (m_world->GetConfig().BIRTH_METHOD.Get() == POSITION_OFFSPRING_FULL_SOUP_ELDEST &&
-      cell_array[cell_id].IsOccupied() == true) {
-    // Have to manually take this cell out of the reaper Queue.
-    reaper_queue.Remove( &(cell_array[cell_id]) );
-  }
-  
-  // Setup the child's mutation rates.  Since this organism is being injected
-  // and has no parent, we should always take the rate from the environment.
-  new_organism->MutationRates().Copy(cell_array[cell_id].MutationRates());
-  
-  
-  // Activate the organism in the population...
-  ActivateOrganism(ctx, new_organism, cell_array[cell_id]);
-  
-  // Log the injection of this organism if LOG_INJECT is set to 1 and
-  // the current update number is >= INJECT_LOG_START
-  if ( (m_world->GetConfig().LOG_INJECT.Get() == 1) &&
-      (m_world->GetStats().GetUpdate() >= m_world->GetConfig().INJECT_LOG_START.Get()) ){
-    
-    cString tmpfilename = cStringUtil::Stringf("injectlog.dat");
-    cDataFile& df = m_world->GetDataFile(tmpfilename);
-    
-    int update = m_world->GetStats().GetUpdate();
-    int orgid = new_organism->GetID();
-    int deme_id = m_world->GetPopulation().GetCell(cell_id).GetDemeID();
-    int facing = new_organism->GetFacing();
-    const char *orgname = (const char *)new_genotype->GetName();
-    
-    cString UpdateStr = cStringUtil::Stringf("%d %d %d %d %d %s", update, orgid, cell_id, deme_id, facing, orgname);
-    df.WriteRaw(UpdateStr);
-  }
-  
-}
 
-
 // This function injects a new organism into the population at cell_id that
 // is an exact clone of the organism passed in.
 
@@ -5389,12 +5315,72 @@
 }
 
 
-void cPopulation::InjectGenome(int cell_id, const cGenome& genome, int lineage_label, eBioUnitSource src)
+void cPopulation::InjectGenome(int cell_id, eBioUnitSource src, const cGenome& genome, int lineage_label)
 {
-  // Setup the genotype...
+  assert(cell_id >= 0 && cell_id < cell_array.GetSize());
+  if (cell_id < 0 || cell_id >= cell_array.GetSize()) {
+    m_world->GetDriver().RaiseFatalException(1, "InjectGenotype into nonexistent cell");
+  }
+  
+  cAvidaContext& ctx = m_world->GetDefaultContext();
+  
+  cMetaGenome tmp_genome(m_world->GetConfig().HARDWARE_TYPE.Get(), 1, genome); // @TODO - genotypes need metagenomes
+  cOrganism* new_organism = new cOrganism(m_world, ctx, tmp_genome, -1, src);
   cGenotype* new_genotype = m_world->GetClassificationManager().GetGenotypeInjected(genome, lineage_label);
   
-  InjectGenotype( cell_id, new_genotype, 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);
+  
+  //Coalescense Clade Setup
+  new_organism->SetCCladeLabel(-1);  
+  
+  // Set the genotype...
+  new_organism->SetGenotype(new_genotype);
+  
+  if (m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
+    phenotype.SetMerit(cMerit(phenotype.ConvertEnergyToMerit(phenotype.GetStoredEnergy())));
+  } else {
+    phenotype.SetMerit(cMerit(new_organism->GetTestMerit(ctx)));
+  }
+  
+  // Prep the cell..
+  if (m_world->GetConfig().BIRTH_METHOD.Get() == POSITION_OFFSPRING_FULL_SOUP_ELDEST &&
+      cell_array[cell_id].IsOccupied() == true) {
+    // Have to manually take this cell out of the reaper Queue.
+    reaper_queue.Remove( &(cell_array[cell_id]) );
+  }
+  
+  // Setup the child's mutation rates.  Since this organism is being injected
+  // and has no parent, we should always take the rate from the environment.
+  new_organism->MutationRates().Copy(cell_array[cell_id].MutationRates());
+  
+  
+  // Activate the organism in the population...
+  ActivateOrganism(ctx, new_organism, cell_array[cell_id]);
+  
+  // Log the injection of this organism if LOG_INJECT is set to 1 and
+  // the current update number is >= INJECT_LOG_START
+  if ( (m_world->GetConfig().LOG_INJECT.Get() == 1) &&
+      (m_world->GetStats().GetUpdate() >= m_world->GetConfig().INJECT_LOG_START.Get()) ){
+    
+    cString tmpfilename = cStringUtil::Stringf("injectlog.dat");
+    cDataFile& df = m_world->GetDataFile(tmpfilename);
+    
+    int update = m_world->GetStats().GetUpdate();
+    int orgid = new_organism->GetID();
+    int deme_id = m_world->GetPopulation().GetCell(cell_id).GetDemeID();
+    int facing = new_organism->GetFacing();
+    const char *orgname = (const char *)new_genotype->GetName();
+    
+    cString UpdateStr = cStringUtil::Stringf("%d %d %d %d %d %s", update, orgid, cell_id, deme_id, facing, orgname);
+    df.WriteRaw(UpdateStr);
+  }
+  
+
 }
 
 // Note: cPopulation::SerialTransfer does not respect deme boundaries and only acts on a single population.

Modified: branches/biounit/source/main/cPopulation.h
===================================================================
--- branches/biounit/source/main/cPopulation.h	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/main/cPopulation.h	2009-12-22 16:56:54 UTC (rev 3574)
@@ -134,7 +134,7 @@
 
   void InitiatePop();
 
-  void InjectGenome(int cell_id, const cGenome& genome, int lineage_label, eBioUnitSource src);
+  void InjectGenome(int cell_id, eBioUnitSource src, const cGenome& genome, int lineage_label = 0);
 
   // Activate the offspring of an organism in the population
   bool ActivateOffspring(cAvidaContext& ctx, const cMetaGenome& offspring_genome, cOrganism* parent_organism);
@@ -337,12 +337,6 @@
   void UpdateSpeciesStats();
   void UpdateDominantStats();
   
-  /**
-   * 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, eBioUnitSource src);
   void CompeteOrganisms_ConstructOffspring(int cell_id, cOrganism& parent);
   

Modified: branches/biounit/source/main/cPopulationInterface.cc
===================================================================
--- branches/biounit/source/main/cPopulationInterface.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/main/cPopulationInterface.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -27,7 +27,6 @@
 
 #include "cDeme.h"
 #include "cEnvironment.h"
-#include "cGenotype.h"
 #include "cHardwareManager.h"
 #include "cOrganism.h"
 #include "cOrgSinkMessage.h"
@@ -142,13 +141,6 @@
   return m_world->GetPopulation().GetCell(m_cell_id).GetInputs();
 }
 
-int cPopulationInterface::Debug()
-{
-  cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
-  assert(cell.IsOccupied());
-  return cell.GetOrganism()->GetGenotype()->GetID();
-}
-
 const tArray<double> & cPopulationInterface::GetResources()
 {
   return m_world->GetPopulation().GetCellResources(m_cell_id);

Modified: branches/biounit/source/main/cPopulationInterface.h
===================================================================
--- branches/biounit/source/main/cPopulationInterface.h	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/main/cPopulationInterface.h	2009-12-22 16:56:54 UTC (rev 3574)
@@ -96,7 +96,6 @@
   int GetInputAt(int& input_pointer);
   void ResetInputs(cAvidaContext& ctx);
   const tArray<int>& GetInputs() const;
-  int Debug();
   const tArray<double>& GetResources();
   const tArray<double>& GetDemeResources(int deme_id);
   const tArray< tArray<int> >& GetCellIdLists();

Modified: branches/biounit/source/main/cStats.cc
===================================================================
--- branches/biounit/source/main/cStats.cc	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/main/cStats.cc	2009-12-22 16:56:54 UTC (rev 3574)
@@ -27,7 +27,6 @@
 
 #include "cDataFile.h"
 #include "cEnvironment.h"
-#include "cGenotype.h"
 #include "cHardwareManager.h"
 #include "cInstSet.h"
 #include "cPopulation.h"
@@ -64,7 +63,6 @@
   , dom_fidelity(0.0)
   , ave_fidelity(0.0)
   , max_viable_fitness(0)
-  , dom_genotype(NULL)
   , dom_merit(0)
   , dom_gestation(0)
   , dom_repro_rate(0)
@@ -1630,16 +1628,7 @@
 */
 void cStats::DemePostReplication(cDeme& source_deme, cDeme& target_deme)
 {
-  std::vector<int> genotype_ids;
-  for(int i=0; i<target_deme.GetSize(); ++i) {
-    cPopulationCell& cell = target_deme.GetCell(i);
-    if(cell.IsOccupied()) {
-      genotype_ids.push_back(cell.GetOrganism()->GetGenotype()->GetID());  
-    }
-  }
-  //assert(genotype_ids.size()>0); // How did we get to replication otherwise?
-  //@JEB some germline methods can result in empty source demes if they didn't produce a germ)
-  m_deme_founders[target_deme.GetID()] = genotype_ids;
+  m_deme_founders[target_deme.GetID()] = target_deme.GetGenotypeIDs();
 }
 
 

Modified: branches/biounit/source/main/cStats.h
===================================================================
--- branches/biounit/source/main/cStats.h	2009-12-21 20:54:35 UTC (rev 3573)
+++ branches/biounit/source/main/cStats.h	2009-12-22 16:56:54 UTC (rev 3574)
@@ -76,7 +76,6 @@
 #endif
 
 
-class cGenotype;
 class cWorld;
 class cOrganism;
 class cOrgMessage;
@@ -171,7 +170,6 @@
   double max_viable_fitness;
 
   // Dominant Genotype
-  cGenotype * dom_genotype;
   double dom_merit;
   double dom_gestation;
   double dom_repro_rate;
@@ -359,7 +357,6 @@
   int GetSubUpdate() const { return sub_update; }
   double GetGeneration() const { return SumGeneration().Average(); }
 
-  cGenotype* GetDomGenotype() const { return dom_genotype; }
   double GetDomMerit() const { return dom_merit; }
   double GetDomGestation() const { return dom_gestation; }
   double GetDomReproRate() const { return dom_repro_rate; }
@@ -381,7 +378,6 @@
   int GetSenseSize() const { return sense_size; }
 
   // Settings...
-  void SetDomGenotype(cGenotype * in_gen) { dom_genotype = in_gen; }
   void SetDomMerit(double in_merit) { dom_merit = in_merit; }
   void SetDomGestation(double in_gest) { dom_gestation = in_gest; }
   void SetDomReproRate(double in_rate) { dom_repro_rate = in_rate; }




More information about the Avida-cvs mailing list