[Avida-cvs] [avida-svn] r696 - in development/source: analyze classification cpu main

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Mon May 22 06:04:51 PDT 2006


Author: brysonda
Date: 2006-05-22 09:04:51 -0400 (Mon, 22 May 2006)
New Revision: 696

Modified:
   development/source/analyze/cAnalyzeUtil.cc
   development/source/classification/cGenotype.cc
   development/source/cpu/cCPUTestInfo.cc
   development/source/cpu/cCPUTestInfo.h
   development/source/cpu/cTestCPUInterface.cc
   development/source/cpu/cTestCPUInterface.h
   development/source/cpu/cTestUtil.cc
   development/source/main/cMxCodeArray.cc
   development/source/main/cOrgInterface.h
   development/source/main/cOrganism.cc
   development/source/main/cPopulationInterface.cc
   development/source/main/cPopulationInterface.h
Log:
Move GetTestOnDivide into cOrgInterface.   cTestCPUInterface subclass sets this to false, (hopefully) preventing recursive organism testing under Revert* regimes.

Remove unnecessary indirection via cOrgInterface::TestFitness().

Add GetTestPhenotype method into cCPUTestInfo, so that cOrganism could avoid cyclical interface dependency within cGenotype (along with other possibly unnecessary cOrganism dependencies).

Modified: development/source/analyze/cAnalyzeUtil.cc
===================================================================
--- development/source/analyze/cAnalyzeUtil.cc	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/analyze/cAnalyzeUtil.cc	2006-05-22 13:04:51 UTC (rev 696)
@@ -471,14 +471,14 @@
     // We calculate the fitness based on the current merit,
     // but with the true gestation time. Also, we set the fitness
     // to zero if the creature is not viable.
-    const double f = ( test_info.IsViable() ) ? organism->GetPhenotype().GetMerit().CalcFitness(test_info.GetTestOrganism()->GetPhenotype().GetGestationTime()) : 0;
+    const double f = ( test_info.IsViable() ) ? organism->GetPhenotype().GetMerit().CalcFitness(test_info.GetTestPhenotype().GetGestationTime()) : 0;
     const double f_testCPU = test_info.GetColonyFitness();
     
     // Get the maximum fitness in the population
     // Here, we want to count only organisms that can truly replicate,
     // to avoid complications
     if ( f_testCPU > max_fitness &&
-         test_info.GetTestOrganism()->GetPhenotype().CopyTrue() ){
+         test_info.GetTestPhenotype().CopyTrue() ){
       max_fitness = f_testCPU;
       max_f_genotype = genotype;
     }
@@ -688,7 +688,7 @@
     // create a test-cpu for the current creature
     cCPUTestInfo test_info;
     testcpu->TestGenome(ctx, test_info, organism->GetGenome());
-    cPhenotype & test_phenotype = test_info.GetTestOrganism()->GetPhenotype();
+    cPhenotype & test_phenotype = test_info.GetTestPhenotype();
     cPhenotype & phenotype = organism->GetPhenotype();
     
     int num_tasks = world->GetEnvironment().GetTaskLib().GetSize();
@@ -746,7 +746,7 @@
         cOrganism * organism = pop->GetCell(cell_num).GetOrganism();
         cCPUTestInfo test_info;
         testcpu->TestGenome(ctx, test_info, organism->GetGenome());
-        cPhenotype & test_phenotype = test_info.GetTestOrganism()->GetPhenotype();
+        cPhenotype& test_phenotype = test_info.GetTestPhenotype();
         int num_tasks = world->GetEnvironment().GetTaskLib().GetSize();   
         for (int k = 0; k < num_tasks; k++) {
           if (test_phenotype.GetLastTaskCount()[k]>0) {

Modified: development/source/classification/cGenotype.cc
===================================================================
--- development/source/classification/cGenotype.cc	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/classification/cGenotype.cc	2006-05-22 13:04:51 UTC (rev 696)
@@ -15,7 +15,6 @@
 #include "cGenomeUtil.h"
 #include "cHardwareManager.h"
 #include "cMerit.h"
-#include "cOrganism.h"
 #include "cPhenotype.h"
 #include "cTestCPU.h"
 #include "cTools.h"
@@ -197,7 +196,7 @@
   delete testcpu;
 
   // Setup all possible test values.
-  cPhenotype & phenotype = test_info.GetTestOrganism()->GetPhenotype();
+  cPhenotype & phenotype = test_info.GetTestPhenotype();
   test_data.fitness = test_info.GetGenotypeFitness();
   test_data.merit = phenotype.GetMerit().GetDouble();
   test_data.gestation_time = phenotype.GetGestationTime();

Modified: development/source/cpu/cCPUTestInfo.cc
===================================================================
--- development/source/cpu/cCPUTestInfo.cc	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/cpu/cCPUTestInfo.cc	2006-05-22 13:04:51 UTC (rev 696)
@@ -74,3 +74,9 @@
   if (IsViable()) return GetColonyOrganism()->GetPhenotype().GetFitness();
   return 0.0;
 }
+
+cPhenotype& cCPUTestInfo::GetTestPhenotype(int level)
+{
+  assert(org_array[level] != NULL);
+  return org_array[level]->GetPhenotype();
+}

Modified: development/source/cpu/cCPUTestInfo.h
===================================================================
--- development/source/cpu/cCPUTestInfo.h	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/cpu/cCPUTestInfo.h	2006-05-22 13:04:51 UTC (rev 696)
@@ -23,6 +23,7 @@
 
 class cHardwareTracer;
 class cOrganism;
+class cPhenotype;
 class cString;
 
 class cCPUTestInfo
@@ -82,17 +83,10 @@
   int GetCycleTo() const { return cycle_to; }
 
   // Genotype Stats...
-  cOrganism * GetTestOrganism(int level=0) {
-    assert(org_array[level] != NULL);
-    return org_array[level];
-  }
+  inline cOrganism* GetTestOrganism(int level = 0);
+  cPhenotype& GetTestPhenotype(int level = 0);
+  inline cOrganism* GetColonyOrganism();
 
-  cOrganism * GetColonyOrganism() {
-    const int depth_used = (depth_found == -1) ? 0 : depth_found;
-    assert(org_array[depth_used] != NULL);
-    return org_array[depth_used];
-  }
-
   // And just because these are so commonly used...
   double GetGenotypeFitness();
   double GetColonyFitness();
@@ -110,4 +104,18 @@
 }
 #endif  
 
+
+inline cOrganism* cCPUTestInfo::GetTestOrganism(int level)
+{
+  assert(org_array[level] != NULL);
+  return org_array[level];
+}
+
+inline cOrganism* cCPUTestInfo::GetColonyOrganism()
+{
+  const int depth_used = (depth_found == -1) ? 0 : depth_found;
+  assert(org_array[depth_used] != NULL);
+  return org_array[depth_used];
+}
+
 #endif

Modified: development/source/cpu/cTestCPUInterface.cc
===================================================================
--- development/source/cpu/cTestCPUInterface.cc	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/cpu/cTestCPUInterface.cc	2006-05-22 13:04:51 UTC (rev 696)
@@ -36,11 +36,6 @@
 {
 }
 
-double cTestCPUInterface::TestFitness()
-{
-  return -1.0;
-}
-
 int cTestCPUInterface::GetInput()
 {
   return m_testcpu->GetInput();

Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/cpu/cTestCPUInterface.h	2006-05-22 13:04:51 UTC (rev 696)
@@ -37,7 +37,6 @@
   int GetNumNeighbors();
   void Rotate(int direction = 1);
   void Breakpoint() { ; }
-  double TestFitness();
   int GetInput();
   int GetInputAt(int& input_pointer);
   int Debug();
@@ -51,6 +50,7 @@
   int ReceiveValue();
   bool InjectParasite(cOrganism* parent, const cGenome& injected_code);
   bool UpdateMerit(double new_merit);
+  bool TestOnDivide() { return false; }
 };
 
 

Modified: development/source/cpu/cTestUtil.cc
===================================================================
--- development/source/cpu/cTestUtil.cc	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/cpu/cTestUtil.cc	2006-05-22 13:04:51 UTC (rev 696)
@@ -87,9 +87,9 @@
   const int num_levels = test_info.GetMaxDepth() + 1;
   for (int j = 0; j < num_levels; j++) {
     fp << "# Generation: " << j << endl;
-    cOrganism * organism = test_info.GetTestOrganism(j);
+    cOrganism* organism = test_info.GetTestOrganism(j);
     assert(organism != NULL);
-    cPhenotype & phenotype = organism->GetPhenotype();
+    cPhenotype& phenotype = organism->GetPhenotype();
 
     fp << "# Merit...........: "
        << setw(12) << setfill(' ') << phenotype.GetMerit() << endl;
@@ -121,7 +121,7 @@
   }
   
   // Display the tasks performed...
-  cPhenotype & phenotype = test_info.GetTestOrganism()->GetPhenotype();
+  cPhenotype& phenotype = test_info.GetTestPhenotype();
   for (int i = 0; i < world->GetEnvironment().GetTaskLib().GetSize(); i++) {
     fp << "# "<< world->GetEnvironment().GetTaskLib().GetTask(i).GetName()
        << "\t" << phenotype.GetLastTaskCount()[i]
@@ -169,12 +169,6 @@
   endl;
   else fp << "# Update Output...: N/A" << endl;
 
-  //fp << "# Is Viable.......: " << test_info.IsViable()
-  //<< endl
-  //   << "# Repro Cycle Size: " << test_info.GetMaxCycle()
-  //   << endl
-  //   << "# Depth to Viable.: " << test_info.GetDepthFound()
-  //   << endl;
 
   if (inject_genotype != NULL) {
     fp << "# Update Created..: " << inject_genotype->GetUpdateBorn()     <<
@@ -185,57 +179,10 @@
        endl
        << "# Tree Depth......: " << inject_genotype->GetDepth()          <<
        endl
-      //<< "# Parent Distance.: " << inject_genotype->GetParentDistance() <<
-      // endl
       ;
   }
   fp << endl;
 
-  //const int num_levels = test_info.GetMaxDepth() + 1;
-  /*for (int j = 0; j < num_levels; j++) {
-    fp << "# Generation: " << j << endl;
-    cOrganism * organism = test_info.GetTestOrganism(j);
-    assert(organism != NULL);
-    cPhenotype & phenotype = organism->GetPhenotype();
-
-    fp << "# Merit...........: "
-       << setw(12) << setfill(' ') << phenotype.GetMerit() << endl;
-    fp << "# Gestation Time..: "
-       << setw(12) << setfill(' ') << phenotype.GetGestationTime() << endl;
-    fp << "# Fitness.........: "
-       << setw(12) << setfill(' ') << phenotype.GetFitness() << endl;
-    fp << "# Errors..........: "
-       << setw(12) << setfill(' ') << phenotype.GetLastNumErrors() << endl;
-    fp << "# Genome Size.....: "
-       << setw(12) << setfill(' ') << organism->GetGenome().GetSize() << endl;
-    fp << "# Copied Size.....: "
-       << setw(12) << setfill(' ') << phenotype.GetCopiedSize() << endl;
-    fp << "# Executed Size...: "
-       << setw(12) << setfill(' ') << phenotype.GetExecutedSize() << endl;
-
-    fp << "# Offspring.......: ";
-    if (phenotype.GetNumDivides() == 0)
-      fp << setw(12) << setfill(' ') << "NONE";
-    else if (phenotype.CopyTrue() == true)
-      fp << setw(12) << setfill(' ') << "SELF";
-    else if (test_info.GetCycleTo() != -1)
-      fp << setw(12) << setfill(' ') << test_info.GetCycleTo();
-    else
-      fp << setw(12) << setfill(' ') << (j+1);
-    fp << endl;
-
-    fp << endl;     // Skip line
-    }
-  
-  // Display the tasks performed...
-  cPhenotype & phenotype = test_info.GetTestOrganism()->GetPhenotype();
-  for (int i = 0; i < phenotype.GetEnvironment().GetTaskLib().GetSize(); i++) {
-    fp << "# "<< phenotype.GetEnvironment().GetTaskLib().GetTask(i).GetName()
-       << "\t" << phenotype.GetLastTaskCount()[i]
-       << endl;
-  }
-  fp << endl; // Skip line
-  */
   // Display the genome
   const cInstSet & inst_set =
     test_info.GetTestOrganism()->GetHardware().GetInstSet();

Modified: development/source/main/cMxCodeArray.cc
===================================================================
--- development/source/main/cMxCodeArray.cc	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/main/cMxCodeArray.cc	2006-05-22 13:04:51 UTC (rev 696)
@@ -15,7 +15,7 @@
 #include "cInstSet.h"
 #include "cHardwareManager.h"
 #include "MyCodeArrayLessThan.h"
-#include "cOrganism.h"
+#include "cPhenotype.h"
 #include "cTestCPU.h"
 #include "cTools.h"
 #include "cWorld.h"
@@ -459,10 +459,9 @@
   testcpu->TestGenome(ctx, test_info, temp);
   delete testcpu;
   
-  if ( test_info.IsViable() )
-    m_gestation_time =
-      test_info.GetTestOrganism()->GetPhenotype().GetGestationTime();
+  if (test_info.IsViable())
+    m_gestation_time = test_info.GetTestPhenotype().GetGestationTime();
   else // if not viable, set a really high gestation time
     m_gestation_time = m_max_gestation_time;
-  m_merit = test_info.GetTestOrganism()->GetPhenotype().GetMerit().GetDouble();
+  m_merit = test_info.GetTestPhenotype().GetMerit().GetDouble();
 }

Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/main/cOrgInterface.h	2006-05-22 13:04:51 UTC (rev 696)
@@ -37,7 +37,6 @@
   virtual int GetNumNeighbors() = 0;
   virtual void Rotate(int direction = 1) = 0;
   virtual void Breakpoint() = 0;
-  virtual double TestFitness() = 0;
   virtual int GetInput() = 0;
   virtual int GetInputAt(int& input_pointer) = 0;
   virtual int Debug() = 0;
@@ -51,6 +50,7 @@
   virtual int ReceiveValue() = 0;
   virtual bool InjectParasite(cOrganism* parent, const cGenome& injected_code) = 0;
   virtual bool UpdateMerit(double new_merit) = 0;
+  virtual bool TestOnDivide() = 0;
 };
 
 #endif

Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/main/cOrganism.cc	2006-05-22 13:04:51 UTC (rev 696)
@@ -16,6 +16,7 @@
 #include "functions.h"
 #include "cGenome.h"
 #include "cGenomeUtil.h"
+#include "cGenotype.h"
 #include "cHardwareBase.h"
 #include "cHardwareManager.h"
 #include "cInjectGenotype.h"
@@ -101,7 +102,7 @@
 double cOrganism::GetTestFitness()
 {
   assert(m_interface);
-  return m_interface->TestFitness();
+  return genotype->GetTestFitness();
 }
   
 int cOrganism::ReceiveValue()
@@ -387,7 +388,7 @@
 }
 
 
-bool cOrganism::GetTestOnDivide() const { return m_world->GetTestOnDivide();}
+bool cOrganism::GetTestOnDivide() const { return m_interface->TestOnDivide();}
 bool cOrganism::GetFailImplicit() const { return m_world->GetConfig().FAIL_IMPLICIT.Get(); }
 
 bool cOrganism::GetRevertFatal() const { return m_world->GetConfig().REVERT_FATAL.Get(); }

Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/main/cPopulationInterface.cc	2006-05-22 13:04:51 UTC (rev 696)
@@ -59,14 +59,6 @@
   else cell.ConnectionList().CircPrev();
 }
 
-double cPopulationInterface::TestFitness()
-{
-  cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
-  assert(cell.IsOccupied());
-  
-  return cell.GetOrganism()->GetGenotype()->GetTestFitness();
-}
-
 int cPopulationInterface::GetInput()
 {
   cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
@@ -193,3 +185,7 @@
   return m_world->GetPopulation().UpdateMerit(m_cell_id, new_merit);
 }
 
+bool cPopulationInterface::TestOnDivide()
+{
+  return m_world->GetTestOnDivide();
+}

Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h	2006-05-20 15:46:31 UTC (rev 695)
+++ development/source/main/cPopulationInterface.h	2006-05-22 13:04:51 UTC (rev 696)
@@ -46,7 +46,6 @@
   int GetNumNeighbors();
   void Rotate(int direction = 1);
   void Breakpoint() { m_world->GetDriver().SignalBreakpoint(); }
-  double TestFitness();
   int GetInput();
   int GetInputAt(int& input_pointer);
   int Debug();
@@ -60,6 +59,7 @@
   int ReceiveValue();
   bool InjectParasite(cOrganism* parent, const cGenome& injected_code);
   bool UpdateMerit(double new_merit);
+  bool TestOnDivide();
 };
 
 




More information about the Avida-cvs mailing list