[Avida-cvs] [avida-svn] r931 - in development/source: actions cpu main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Thu Sep 7 16:30:03 PDT 2006


Author: brysonda
Date: 2006-09-07 19:30:03 -0400 (Thu, 07 Sep 2006)
New Revision: 931

Modified:
   development/source/actions/LandscapeActions.cc
   development/source/actions/PrintActions.cc
   development/source/cpu/cTestCPU.cc
   development/source/cpu/cTestCPU.h
   development/source/main/cPopulation.cc
   development/source/main/cPopulation.h
Log:
Update cPopulation methods to use cDataFile.  Remove out of date, incorrect ParasiteDebug method.  Add a new cDataFile based version of PrintGenome to cTestCPU.

Modified: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc	2006-09-07 02:22:38 UTC (rev 930)
+++ development/source/actions/LandscapeActions.cc	2006-09-07 23:30:03 UTC (rev 931)
@@ -1007,6 +1007,7 @@
       }
 
       cDataFile& df = m_world->GetDataFile(filename);
+      cTestCPU* testcpu = (m_save_genotypes) ? m_world->GetHardwareManager().CreateTestCPU() : NULL;
       while (orgdata = batch.Pop()) {
         cOrganism* organism = orgdata->GetOrganism();
         cGenotype* genotype = organism->GetGenotype();
@@ -1030,9 +1031,10 @@
         // save into archive
         if (m_save_genotypes) {
           name.Set("archive/%s.org", static_cast<const char *>(name));
-          cTestUtil::PrintGenome(m_world, organism->GetGenome(), name);
+          testcpu->PrintGenome(ctx, organism->GetGenome(), name);
         }
       }
+      delete testcpu;
       m_world->GetDataFileManager().Remove(filename);
     }
   }

Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2006-09-07 02:22:38 UTC (rev 930)
+++ development/source/actions/PrintActions.cc	2006-09-07 23:30:03 UTC (rev 931)
@@ -438,7 +438,6 @@
   
   void Process(cAvidaContext& ctx)
   {
-    m_world->GetPopulation().ParasiteDebug();
   }
 };
 

Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc	2006-09-07 02:22:38 UTC (rev 930)
+++ development/source/cpu/cTestCPU.cc	2006-09-07 23:30:03 UTC (rev 931)
@@ -14,6 +14,7 @@
 #include "cCPUTestInfo.h"
 #include "cEnvironment.h"
 #include "functions.h"
+#include "cGenotype.h"
 #include "cHardwareBase.h"
 #include "cHardwareManager.h"
 #include "cHardwareStatusPrinter.h"
@@ -249,3 +250,79 @@
   // All options have failed; just return false.
   return false;
 }
+
+
+void cTestCPU::PrintGenome(cAvidaContext& ctx, const cGenome& genome, cString filename,
+                           cGenotype* genotype, int update)
+{
+  if (filename == "") filename.Set("archive/%03d-unnamed.org", genome.GetSize());
+    
+  cCPUTestInfo test_info;
+  TestGenome(ctx, test_info, genome);
+  
+  // Open the file...
+  cDataFile& df = m_world->GetDataFile(filename);
+  
+  // Print the useful info at the top...
+  df.WriteTimeStamp();  
+  cString c("");
+  
+  df.WriteComment(c.Set("Filename........: %s", static_cast<const char*>(filename)));
+  
+  if (update >= 0) df.WriteComment(c.Set("Update Output...: %d", update));
+  else df.WriteComment("Update Output...: N/A");
+  
+  df.WriteComment(c.Set("Is Viable.......: %d", test_info.IsViable()));
+  df.WriteComment(c.Set("Repro Cycle Size: %d", test_info.GetMaxCycle()));
+  df.WriteComment(c.Set("Depth to Viable.: %d", test_info.GetDepthFound()));
+  
+  if (genotype != NULL) {
+    df.WriteComment(c.Set("Update Created..: %d", genotype->GetUpdateBorn()));
+    df.WriteComment(c.Set("Genotype ID.....: %d", genotype->GetID()));
+    df.WriteComment(c.Set("Parent Gen ID...: %d", genotype->GetParentID()));
+    df.WriteComment(c.Set("Tree Depth......: %d", genotype->GetDepth()));
+    df.WriteComment(c.Set("Parent Distance.: %d", genotype->GetParentDistance()));
+  }
+
+  df.WriteComment("");
+  
+  const int num_levels = test_info.GetMaxDepth() + 1;
+  for (int j = 0; j < num_levels; j++) {
+    df.WriteComment(c.Set("Generation: %d", j));
+
+    cOrganism* organism = test_info.GetTestOrganism(j);
+    assert(organism != NULL);
+    cPhenotype& phenotype = organism->GetPhenotype();
+    
+    df.WriteComment(c.Set("Merit...........: %f", phenotype.GetMerit().GetDouble()));
+    df.WriteComment(c.Set("Gestation Time..: %d", phenotype.GetGestationTime()));
+    df.WriteComment(c.Set("Fitness.........: %f", phenotype.GetFitness()));
+    df.WriteComment(c.Set("Errors..........: %d", phenotype.GetLastNumErrors()));
+    df.WriteComment(c.Set("Genome Size.....: %d", organism->GetGenome().GetSize()));
+    df.WriteComment(c.Set("Copied Size.....: %d", phenotype.GetCopiedSize()));
+    df.WriteComment(c.Set("Executed Size...: %d", phenotype.GetExecutedSize()));
+    
+    if (phenotype.GetNumDivides() == 0) df.WriteComment("Offspring.......: NONE");
+    else if (phenotype.CopyTrue() == true) df.WriteComment("Offspring.......: SELF");
+    else if (test_info.GetCycleTo() != -1) df.WriteComment(c.Set("Offspring.......: %d", test_info.GetCycleTo()));
+    else df.WriteComment(c.Set("Offspring.......: %d", j + 1));
+    
+    df.WriteComment("");
+  }
+  
+  df.WriteComment("Tasks Performed:");
+  cPhenotype& phenotype = test_info.GetTestPhenotype();
+  for (int i = 0; i < m_world->GetEnvironment().GetTaskLib().GetSize(); i++) {
+    df.WriteComment(c.Set("%s %d",
+                          static_cast<const char*>(m_world->GetEnvironment().GetTaskLib().GetTask(i).GetName()),
+                          phenotype.GetLastTaskCount()[i]));
+  }
+
+  df.Endl();
+  
+  // Display the genome
+  cInstUtil::SaveGenome(df.GetOFStream(), test_info.GetTestOrganism()->GetHardware().GetInstSet(), genome);
+  
+  m_world->GetDataFileManager().Remove(filename);
+}
+

Modified: development/source/cpu/cTestCPU.h
===================================================================
--- development/source/cpu/cTestCPU.h	2006-09-07 02:22:38 UTC (rev 930)
+++ development/source/cpu/cTestCPU.h	2006-09-07 23:30:03 UTC (rev 931)
@@ -28,6 +28,7 @@
 class cResourceCount;
 class cCPUTestInfo;
 class cGenome;
+class cGenotype;
 class cWorld;
 
 class cTestResources
@@ -80,7 +81,10 @@
   ~cTestCPU() { if (m_localres) delete m_res; }
   
   bool TestGenome(cAvidaContext& ctx, cCPUTestInfo& test_info, const cGenome& genome);
-  bool TestGenome(cAvidaContext& ctx, cCPUTestInfo& test_info, const cGenome & genome, std::ofstream& out_fp);
+  bool TestGenome(cAvidaContext& ctx, cCPUTestInfo& test_info, const cGenome& genome, std::ofstream& out_fp);
+  
+  void PrintGenome(cAvidaContext& ctx, const cGenome& genome, cString filename,
+                   cGenotype* genotype = NULL, int update = -1);
 
   inline int GetInput();
   inline int GetInputAt(int & input_pointer);

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2006-09-07 02:22:38 UTC (rev 930)
+++ development/source/main/cPopulation.cc	2006-09-07 23:30:03 UTC (rev 931)
@@ -1859,66 +1859,38 @@
   }
 }
 
-void cPopulation::ParasiteDebug()
-{
-  ofstream& outfile = m_world->GetDataFileOFStream("debug.out");
-  outfile << m_world->GetStats().GetUpdate() << endl;
-  int total=0;
-  cInjectGenotype * temp;
-  for(int x=0; x<cell_array.GetSize(); x++)
-  {
-    if(cell_array[x].GetOrganism()!=NULL)
-    {
-      assert(cell_array[x].GetOrganism()->GetNumParasites()>=0 && 
-             cell_array[x].GetOrganism()->GetNumParasites()<=1);
-      total+=cell_array[x].GetOrganism()->GetNumParasites();
-      if(cell_array[x].GetOrganism()->GetNumParasites())
-	    {
-	      cHardwareBase& cpu = cell_array[x].GetOrganism()->GetHardware();
-	      outfile << x << " ";
-	      outfile << cell_array[x].GetOrganism()->GetGenotype()->GetID() << " ";
-        int prev_thread = cpu.GetCurThread();
-        cpu.ThreadSelect(1);
-	      temp = cpu.ThreadGetOwner();
-        cpu.ThreadSelect(prev_thread);
-	      assert(temp!=NULL);
-	      outfile << temp->GetID() << endl;	      
-	    }
-    }
-  }
-  outfile << total << endl;
-}
 
-void cPopulation::PrintPhenotypeData(const cString & filename)
+void cPopulation::PrintPhenotypeData(const cString& filename)
 {
   set<int> ids;
-  for (int i = 0; i < cell_array.GetSize(); i++) 
-  {
+
+  for (int i = 0; i < cell_array.GetSize(); i++) {
     // Only look at cells with organisms in them.
     if (cell_array[i].IsOccupied() == false) continue;
     
-    cOrganism * organism = cell_array[i].GetOrganism();
-    const cPhenotype & phenotype = organism->GetPhenotype();
+    const cPhenotype& phenotype = cell_array[i].GetOrganism()->GetPhenotype();
     
     int id = 0;
-    for (int j = 0; j < phenotype.GetLastTaskCount().GetSize(); j++)
-    {
-      if (phenotype.GetLastTaskCount()[j] > 0)
-        id += (1 << j);
+    for (int j = 0; j < phenotype.GetLastTaskCount().GetSize(); j++) {
+      if (phenotype.GetLastTaskCount()[j] > 0) id += (1 << j);
     }
     ids.insert(id);
   }
-  m_world->GetDataFileOFStream(filename)
-    << m_world->GetStats().GetUpdate() << "\t" << ids.size() << endl;
+  
+  cDataFile& df = m_world->GetDataFile(filename);
+  df.WriteTimeStamp();
+  df.Write(m_world->GetStats().GetUpdate(), "Update");
+  df.Write(static_cast<int>(ids.size()), "Unique Phenotypes");
+  df.Endl();
 }
 
-void cPopulation::PrintPhenotypeStatus(const cString & filename)
+void cPopulation::PrintPhenotypeStatus(const cString& filename)
 {
-  cDataFile & df_phen = m_world->GetDataFile(filename);
+  cDataFile& df_phen = m_world->GetDataFile(filename);
   
   df_phen.WriteComment("Num orgs doing each task for each deme in population");
   df_phen.WriteTimeStamp();
-  df_phen.Write(m_world->GetStats().GetUpdate(), "update");
+  df_phen.Write(m_world->GetStats().GetUpdate(), "Update");
   
   cString comment;
   
@@ -1927,8 +1899,7 @@
     // Only look at cells with organisms in them.
     if (cell_array[i].IsOccupied() == false) continue;
     
-    cOrganism * organism = cell_array[i].GetOrganism();
-    const cPhenotype & phenotype = organism->GetPhenotype();
+    const cPhenotype& phenotype = cell_array[i].GetOrganism()->GetPhenotype();
     
     comment.Set("cur_merit %d;", i); 
     df_phen.Write(phenotype.GetMerit().GetDouble(), comment); 

Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h	2006-09-07 02:22:38 UTC (rev 930)
+++ development/source/main/cPopulation.h	2006-09-07 23:30:03 UTC (rev 931)
@@ -175,9 +175,8 @@
 
   bool GetSyncEvents() { return sync_events; }
   void SetSyncEvents(bool _in) { sync_events = _in; }
-  void ParasiteDebug();
-  void PrintPhenotypeData(const cString & filename);
-  void PrintPhenotypeStatus(const cString & filename);
+  void PrintPhenotypeData(const cString& filename);
+  void PrintPhenotypeStatus(const cString& filename);
 
   bool UpdateMerit(int cell_id, double new_merit);
 




More information about the Avida-cvs mailing list