[Avida-SVN] r2757 - in development/source: actions analyze cpu main tools

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Fri Aug 22 17:42:17 PDT 2008


Author: brysonda
Date: 2008-08-22 20:42:17 -0400 (Fri, 22 Aug 2008)
New Revision: 2757

Modified:
   development/source/actions/PrintActions.cc
   development/source/analyze/cAnalyze.cc
   development/source/analyze/cAnalyzeGenotype.cc
   development/source/analyze/cAnalyzeGenotype.h
   development/source/cpu/cCPUTestInfo.cc
   development/source/cpu/cCPUTestInfo.h
   development/source/cpu/cHardwareManager.cc
   development/source/cpu/cHardwareManager.h
   development/source/cpu/cTestCPU.cc
   development/source/main/cLandscape.cc
   development/source/main/cOrganism.cc
   development/source/main/cOrganism.h
   development/source/main/cPhenPlastGenotype.cc
   development/source/main/cPhenPlastGenotype.h
   development/source/main/cPhenotype.cc
   development/source/main/cPhenotype.h
   development/source/tools/cDataFileManager.cc
Log:
Fix cDataFileManager automatic output path creation to properly create the path as expected.  Also ignore relative path prefixes.

Enhance the test cpu and cCPUTestInfo to allow for changing the instruction set used in the test cpu without altering the rest of the world.

Fix cAnalyzeGenotype's usage of its internal instruction set to properly change the test cpu's inst set for all calculations.  This fixes a bug whereby map tasks crashed if not column arguments were specified.

Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/actions/PrintActions.cc	2008-08-23 00:42:17 UTC (rev 2757)
@@ -1579,6 +1579,8 @@
     
     void Process(cAvidaContext& ctx)
     {
+      cCPUTestInfo test_info;
+      
       if (ctx.GetAnalyzeMode()){ // Analyze mode
         cString this_path = m_filename;
         ofstream& fot = m_world->GetDataFileOFStream(this_path);
@@ -1586,7 +1588,7 @@
         tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
         cAnalyzeGenotype* genotype = NULL;
         while((genotype = batch_it.Next())){
-          const cPhenPlastGenotype* ppgen = new cPhenPlastGenotype(genotype->GetGenome(), m_num_trials, m_world, ctx);
+          const cPhenPlastGenotype* ppgen = new cPhenPlastGenotype(genotype->GetGenome(), m_num_trials, test_info, m_world, ctx);
           PrintPPG(fot, ppgen, genotype->GetID(), genotype->GetParentID());
           delete ppgen;
         }
@@ -1597,7 +1599,7 @@
         PrintHeader(fot);
         cGenotype* genotype = m_world->GetClassificationManager().GetBestGenotype();
         for (int k = 0; k < m_world->GetClassificationManager().GetGenotypeCount(); k++){
-          const cPhenPlastGenotype* ppgen = new cPhenPlastGenotype(genotype->GetGenome(), m_num_trials, m_world, ctx);
+          const cPhenPlastGenotype* ppgen = new cPhenPlastGenotype(genotype->GetGenome(), m_num_trials, test_info, m_world, ctx);
           PrintPPG(fot, ppgen, genotype->GetID(), genotype->GetParentID());
           delete ppgen;
           genotype = genotype->GetNext();

Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/analyze/cAnalyze.cc	2008-08-23 00:42:17 UTC (rev 2757)
@@ -4723,7 +4723,7 @@
       fp << endl;
       
     } else { // if (file_type == FILE_TYPE_HTML) {
-             // Mark file as html
+      // Mark file as html
       fp << "<html>" << endl;
       
       // Setup any javascript macros needed...
@@ -4743,16 +4743,10 @@
       fp << "</head>" << endl;
       
       // Setup the body...
-      fp << "<body bgcolor=\"#FFFFFF\"" << endl
-        << " text=\"#000000\"" << endl
-        << " link=\"#0000AA\"" << endl
-        << " alink=\"#0000FF\"" << endl
-        << " vlink=\"#000044\">" << endl
-        << endl
-        << "<h1 align=center>Run " << batch[cur_batch].Name()
-        << ", ID " << genotype->GetID() << "</h1>" << endl
-        << "<center>" << endl
-        << endl;
+      fp << "<body>" << endl
+      << "<div align=\"center\">" << endl
+      << "<h1 align=\"center\">Run " << batch[cur_batch].Name() << ", ID " << genotype->GetID() << "</h1>" << endl
+      << endl;
       
       // Links?
       fp << "<table width=90%><tr><td align=left>";
@@ -4836,7 +4830,7 @@
       
       // Print the individual columns...
       output_it.Reset();
-      tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+      tDataEntryCommand<cAnalyzeGenotype>* data_command = NULL;
       int cur_col = 0;
       while ((data_command = output_it.Next()) != NULL) {
         data_command->SetTarget(&test_genotype);
@@ -4844,9 +4838,6 @@
         const cFlexVar test_value = data_command->GetValue();
         int compare = CompareFlexStat(test_value, data_command->GetValue(genotype), data_command->GetCompareType());
         
-        // BUG! Either of the next two conditional print commands can
-        // cause landscaping to be triggered in a context that causes a crash, 
-        // notably, if you don't provide any column parameters to MapTasks.. @JEB
         if (file_type == FILE_TYPE_HTML) {
           HTMLPrintStat(test_value, fp, compare, data_command->GetHtmlCellFlags(), data_command->GetNull(),
                         !(data_command->HasArg("blank")));
@@ -4882,14 +4873,14 @@
       
       // And close everything up...
       fp << "</table>" << endl
-        << "</center>" << endl;
+      << "</div>" << endl;
     }
     
     delete [] col_pass_count;
     delete [] col_fail_count;
     m_world->GetDataFileManager().Remove(filename);  // Close the data file object
-    }
-    }
+  }
+}
 
 void cAnalyze::CommandAverageModularity(cString cur_string)
 {

Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/analyze/cAnalyzeGenotype.cc	2008-08-23 00:42:17 UTC (rev 2757)
@@ -40,13 +40,15 @@
 #include "cWorld.h"
 #include "cWorldDriver.h"
 
+#include "tAutoRelease.h"
+
 #include <cmath>
 using namespace std;
 
 cAnalyzeGenotype::cAnalyzeGenotype(cWorld* world, cString symbol_string, cInstSet& in_inst_set)
   : m_world(world)
   , genome(symbol_string)
-  , inst_set(in_inst_set)
+  , m_inst_set(in_inst_set)
   , name("")
   , aligned_sequence("")
   , tag("")
@@ -81,11 +83,11 @@
     
   // Make sure that the sequences jive with the inst_set
   for (int i = 0; i < genome.GetSize(); i++) {
-    if (genome[i].GetOp() >= inst_set.GetSize()) {
+    if (genome[i].GetOp() >= m_inst_set.GetSize()) {
       cString msg("Trying to load instruction ");
       msg += genome[i].GetOp();
       msg += ".  Max in set is";
-      msg += (inst_set.GetSize() - 1);
+      msg += (m_inst_set.GetSize() - 1);
       m_world->GetDriver().RaiseException(msg);
     }
   }
@@ -94,7 +96,7 @@
 cAnalyzeGenotype::cAnalyzeGenotype(cWorld* world, const cGenome& _genome, cInstSet& in_inst_set)
   : m_world(world)
   , genome(_genome)
-  , inst_set(in_inst_set)
+  , m_inst_set(in_inst_set)
   , name("")
   , aligned_sequence("")
   , tag("")
@@ -131,7 +133,7 @@
 cAnalyzeGenotype::cAnalyzeGenotype(const cAnalyzeGenotype& _gen)
   : m_world(_gen.m_world)
   , genome(_gen.genome)
-  , inst_set(_gen.inst_set)
+  , m_inst_set(_gen.m_inst_set)
   , name(_gen.name)
   , aligned_sequence(_gen.aligned_sequence)
   , tag(_gen.tag)
@@ -212,7 +214,7 @@
   // Calculate the base fitness for the genotype we're working with...
   // (This may not have been run already, and cost negligiably more time
   // considering the number of knockouts we need to do.
-  cAnalyzeGenotype base_genotype(m_world, genome, inst_set);
+  cAnalyzeGenotype base_genotype(m_world, genome, m_inst_set);
   base_genotype.Recalculate(ctx);
   double base_fitness = base_genotype.GetFitness();
   const tArray<int> base_task_counts( base_genotype.GetTaskCounts() );
@@ -227,7 +229,7 @@
   cGenome mod_genome(genome);
   
   // Setup a NULL instruction in a special inst set.
-  cInstSet ko_inst_set(inst_set);
+  cInstSet ko_inst_set(m_inst_set);
   const cInstruction null_inst = ko_inst_set.ActivateNullInst();
   
   // If we are keeping track of the specific effects on tasks from the
@@ -347,7 +349,7 @@
 void cAnalyzeGenotype::CheckLand() const
 {
   if (m_land == NULL) {
-    m_land = new cLandscape(m_world, genome, inst_set);
+    m_land = new cLandscape(m_world, genome, m_inst_set);
     m_land->SetDistance(1);
     m_land->Process(m_world->GetDefaultContext());
   }
@@ -356,8 +358,11 @@
 void cAnalyzeGenotype::CheckPhenPlast() const
 {
   // Implicit genotype recalculation if required
-  if (m_phenplast_stats == NULL){
-    cPhenPlastGenotype pp(genome, 1000, m_world, m_world->GetDefaultContext());
+  if (m_phenplast_stats == NULL) {
+    cCPUTestInfo test_info;
+    test_info.SetInstSet(&m_inst_set);
+    
+    cPhenPlastGenotype pp(genome, 1000, test_info, m_world, m_world->GetDefaultContext());
     SummarizePhenotypicPlasticity(pp);
   }
 }
@@ -381,34 +386,26 @@
 
 void cAnalyzeGenotype::CalcLandscape(cAvidaContext& ctx)
 {
-  if (m_land == NULL) m_land = new cLandscape(m_world, genome, inst_set);
+  if (m_land == NULL) m_land = new cLandscape(m_world, genome, m_inst_set);
   m_land->SetDistance(1);
   m_land->Process(ctx);
 }
 
 void cAnalyzeGenotype::Recalculate(cAvidaContext& ctx, cCPUTestInfo* test_info, cAnalyzeGenotype* parent_genotype, int num_trials)
 {  
-  //Allocate our own test info if it wasn't provided
-  cCPUTestInfo* temp_test_info = NULL;
+  // Allocate our own test info if it wasn't provided
+  tAutoRelease<cCPUTestInfo> local_test_info;
   if (!test_info)
   {
-      temp_test_info = new cCPUTestInfo();
-      test_info = temp_test_info;
+    test_info = new cCPUTestInfo();
+    local_test_info.Set(test_info);
   }
 
-  // @DMB - This does some 'interesting' things with the instruction set
-  // Use the inst lib for this genotype... and syncrhonize environment
-  
-  // Backup old instruction set, update with new
-  cInstSet env_inst_set_backup = m_world->GetHardwareManager().GetInstSet();
-  m_world->GetHardwareManager().GetInstSet() = inst_set;
+  test_info->SetInstSet(&m_inst_set);
 
   // Handling recalculation here
   cPhenPlastGenotype recalc_data(genome, num_trials, *test_info, m_world, ctx);
  
-  // Restore the instruction set
-  m_world->GetHardwareManager().GetInstSet() = env_inst_set_backup;
-  
   // The most likely phenotype will be assigned to the phenotype stats
   const cPlasticPhenotype* likely_phenotype = recalc_data.GetMostLikelyPhenotype();
   
@@ -432,17 +429,12 @@
     fitness_ratio = GetFitness() / parent_genotype->GetFitness();
     efficiency_ratio = GetEfficiency() / parent_genotype->GetEfficiency();
     comp_merit_ratio = GetCompMerit() / parent_genotype->GetCompMerit();
-    parent_dist = cStringUtil::EditDistance(genome.AsString(),
-        parent_genotype->GetGenome().AsString(), parent_muts);
+    parent_dist = cStringUtil::EditDistance(genome.AsString(), parent_genotype->GetGenome().AsString(), parent_muts);
     ancestor_dist = parent_genotype->GetAncestorDist() + parent_dist;
   }
 
   // Summarize plasticity information if multiple recalculations performed
-  if (num_trials > 1)
-    SummarizePhenotypicPlasticity(recalc_data);
-  
-  //Deallocate if we created
-  if (temp_test_info) delete temp_test_info;
+  if (num_trials > 1) SummarizePhenotypicPlasticity(recalc_data);
 }
 
 

Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/analyze/cAnalyzeGenotype.h	2008-08-23 00:42:17 UTC (rev 2757)
@@ -103,7 +103,7 @@
 private:
   cWorld* m_world;
   cGenome genome;            // Full Genome
-  cInstSet& inst_set;       // Instruction set used in this genome
+  cInstSet& m_inst_set;       // Instruction set used in this genome
   cString name;              // Name, if one was provided in loading
   cString aligned_sequence;  // Sequence (in ASCII) after alignment
   cString tag;               // All genotypes in a batch can be tagged

Modified: development/source/cpu/cCPUTestInfo.cc
===================================================================
--- development/source/cpu/cCPUTestInfo.cc	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/cpu/cCPUTestInfo.cc	2008-08-23 00:42:17 UTC (rev 2757)
@@ -33,11 +33,11 @@
 
 cCPUTestInfo::cCPUTestInfo(int max_tests)
   : generation_tests(max_tests)  // These vars not reset on Clear()
-  , trace_execution(false)
   , trace_task_order(false)
   , use_random_inputs(false)
   , use_manual_inputs(false)
   , m_tracer(NULL)
+  , m_inst_set(NULL)
   , org_array(max_tests)
   , m_res_method(RES_INITIAL)
   , m_res(NULL)
@@ -73,13 +73,6 @@
 }
  
 
-void cCPUTestInfo::SetTraceExecution(cHardwareTracer *tracer)
-{
-  trace_execution = (tracer)?(true):(false);
-  m_tracer = tracer;
-}
-
-
 double cCPUTestInfo::GetGenotypeFitness()
 {
   if (org_array[0] != NULL) return org_array[0]->GetPhenotype().GetFitness();

Modified: development/source/cpu/cCPUTestInfo.h
===================================================================
--- development/source/cpu/cCPUTestInfo.h	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/cpu/cCPUTestInfo.h	2008-08-23 00:42:17 UTC (rev 2757)
@@ -39,6 +39,7 @@
 #endif
 
 class cHardwareTracer;
+class cInstSet;
 class cOrganism;
 class cPhenotype;
 class cString;
@@ -57,12 +58,12 @@
 private:
   // Inputs...
   const int generation_tests; // Maximum depth in generations to test
-  bool trace_execution;       // Should we trace this CPU?
   bool trace_task_order;      // Should we keep track of ordering of tasks?
   bool use_random_inputs;     // Should we give the organism random inputs?
 	bool use_manual_inputs;     // Do we have inputs that we must use?
 	tArray<int> manual_inputs;  //   if so, use these.
   cHardwareTracer* m_tracer;
+  cInstSet* m_inst_set;
 
   // Outputs...
   bool is_viable;         // Is this organism colony forming?
@@ -94,7 +95,8 @@
   void UseRandomInputs(bool _rand=true) { use_random_inputs = _rand; use_manual_inputs = false; }
 	void UseManualInputs(tArray<int> inputs) {use_manual_inputs = true; use_random_inputs = false; manual_inputs = inputs;}
 	void ResetInputMode() {use_manual_inputs = false; use_random_inputs = false;}
-  void SetTraceExecution(cHardwareTracer *tracer = NULL);
+  void SetTraceExecution(cHardwareTracer* tracer = NULL) { m_tracer = tracer; }
+  void SetInstSet(cInstSet* inst_set = NULL) { m_inst_set = inst_set; }
   void SetResourceOptions(int res_method = RES_INITIAL, std::vector<std::pair<int, std::vector<double> > > * res = NULL, int update = 0, int cpu_cycle_offset = 0)
     { m_res_method = (eTestCPUResourceMethod)res_method; m_res = res; m_res_update = update; m_res_cpu_cycle_offset = cpu_cycle_offset; }
 
@@ -103,7 +105,8 @@
   int GetGenerationTests() const { return generation_tests; }
   bool GetTraceTaskOrder() const { return trace_task_order; }
   bool GetUseRandomInputs() const { return use_random_inputs; }
-  bool GetTraceExecution() const { return trace_execution; }
+  bool GetTraceExecution() const { return (m_tracer); }
+  cInstSet* GetInstSet() const { return m_inst_set; }
 	bool GetUseManualInputs() const { return use_manual_inputs; }
 	tArray<int> GetTestCPUInputs() const { return used_inputs; }
   cHardwareTracer *GetTracer() { return m_tracer; }

Modified: development/source/cpu/cHardwareManager.cc
===================================================================
--- development/source/cpu/cHardwareManager.cc	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/cpu/cHardwareManager.cc	2008-08-23 00:42:17 UTC (rev 2757)
@@ -82,22 +82,22 @@
   
 }
 
-cHardwareBase* cHardwareManager::Create(cOrganism* in_org)
+cHardwareBase* cHardwareManager::Create(cOrganism* in_org, cInstSet* inst_set)
 {
   assert(in_org != NULL);
   
   switch (m_type)
   {
     case HARDWARE_TYPE_CPU_ORIGINAL:
-      return new cHardwareCPU(m_world, in_org, m_inst_set);
+      return new cHardwareCPU(m_world, in_org, inst_set);
     case HARDWARE_TYPE_CPU_SMT:
-      return new cHardwareSMT(m_world, in_org, m_inst_set);
+      return new cHardwareSMT(m_world, in_org, inst_set);
     case HARDWARE_TYPE_CPU_TRANSSMT:
-      return new cHardwareTransSMT(m_world, in_org, m_inst_set);
+      return new cHardwareTransSMT(m_world, in_org, inst_set);
     case HARDWARE_TYPE_CPU_EXPERIMENTAL:
-      return new cHardwareExperimental(m_world, in_org, m_inst_set);
+      return new cHardwareExperimental(m_world, in_org, inst_set);
     case HARDWARE_TYPE_CPU_GX:
-      return new cHardwareGX(m_world, in_org, m_inst_set);
+      return new cHardwareGX(m_world, in_org, inst_set);
     default:
       return NULL;
   }

Modified: development/source/cpu/cHardwareManager.h
===================================================================
--- development/source/cpu/cHardwareManager.h	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/cpu/cHardwareManager.h	2008-08-23 00:42:17 UTC (rev 2757)
@@ -61,7 +61,8 @@
   cHardwareManager(cWorld* world);
   ~cHardwareManager() { ; }
   
-  cHardwareBase* Create(cOrganism* in_org);
+  cHardwareBase* Create(cOrganism* in_org, cInstSet* inst_set);
+  inline cHardwareBase* Create(cOrganism* in_org) { return Create(in_org, m_inst_set); }
   cTestCPU* CreateTestCPU() { return new cTestCPU(m_world); }
 
   const cInstSet& GetInstSet() const { return *m_inst_set; }

Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/cpu/cTestCPU.cc	2008-08-23 00:42:17 UTC (rev 2757)
@@ -359,10 +359,13 @@
   if (test_info.org_array[cur_depth] != NULL) {
     delete test_info.org_array[cur_depth];
   }
-  test_info.org_array[cur_depth] = new cOrganism(m_world, ctx, genome);
-  cOrganism & organism = *( test_info.org_array[cur_depth] );
-  organism.SetOrgInterface(new cTestCPUInterface(this));
-  organism.GetPhenotype().SetupInject(genome);
+  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);
+  test_info.org_array[cur_depth] = organism;
+  organism->SetOrgInterface(new cTestCPUInterface(this));
+  organism->GetPhenotype().SetupInject(genome);
 
   // Run the current organism.
   ProcessGestation(ctx, test_info, cur_depth);
@@ -377,10 +380,10 @@
   //  4: It copied false => we must check the child.
 
   // Case 1:  ////////////////////////////////////
-  if (organism.GetPhenotype().GetNumDivides() == 0)  return false;
+  if (organism->GetPhenotype().GetNumDivides() == 0)  return false;
 
   // Case 2:  ////////////////////////////////////
-  if (organism.GetPhenotype().CopyTrue() == true) {
+  if (organism->GetPhenotype().CopyTrue() == true) {
     test_info.depth_found = cur_depth;
     test_info.is_viable = true;
     return true;
@@ -389,7 +392,7 @@
   // Case 3:  ////////////////////////////////////
   bool is_ancestor = false;
   for (int anc_depth = 0; anc_depth < cur_depth; anc_depth++) {
-    if (organism.ChildGenome() == test_info.org_array[anc_depth]->GetGenome()){
+    if (organism->ChildGenome() == test_info.org_array[anc_depth]->GetGenome()){
       is_ancestor = true;
       const int cur_cycle = cur_depth - anc_depth;
       if (test_info.max_cycle < cur_cycle) test_info.max_cycle = cur_cycle;
@@ -406,7 +409,7 @@
   // If we haven't reached maximum depth yet, check out the child.
   if (cur_depth+1 < test_info.generation_tests) {
     // Run the child's genome.
-    return TestGenome_Body(ctx, test_info, organism.ChildGenome(), cur_depth+1);
+    return TestGenome_Body(ctx, test_info, organism->ChildGenome(), cur_depth+1);
   }
 
   // All options have failed; just return false.

Modified: development/source/main/cLandscape.cc
===================================================================
--- development/source/main/cLandscape.cc	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/main/cLandscape.cc	2008-08-23 00:42:17 UTC (rev 2757)
@@ -38,11 +38,12 @@
 #include "cWorld.h"
 
 
-cLandscape::cLandscape(cWorld* world, const cGenome & in_genome, const cInstSet & in_inst_set)
+cLandscape::cLandscape(cWorld* world, const cGenome& in_genome, const cInstSet& in_inst_set)
 : m_world(world), inst_set(in_inst_set), base_genome(1), peak_genome(1), trials(1), m_min_found(0),
   m_max_trials(0), site_count(NULL)
 {
   Reset(in_genome);
+  test_info.SetInstSet(const_cast<cInstSet*>(&inst_set));
 }
 
 cLandscape::~cLandscape()
@@ -777,7 +778,6 @@
     pos_frac = GetProbPos();
     
     // Print the information on the current best.
-    cCPUTestInfo test_info;
     testcpu->TestGenome(ctx, test_info, cur_genome);
     cPhenotype& colony_phenotype = test_info.GetColonyOrganism()->GetPhenotype();
     df.Write(gen, "Generation");

Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/main/cOrganism.cc	2008-08-23 00:42:17 UTC (rev 2757)
@@ -77,10 +77,47 @@
   , m_msg(0)
   , m_opinion(0)
 {
-  // Initialization of structures...
   m_hardware = m_world->GetHardwareManager().Create(this);
-//  m_cpu_stats.Setup();
 
+  initialize(ctx);
+}
+
+cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome, cInstSet* inst_set)
+  : m_world(world)
+  , m_genotype(NULL)
+  , m_phenotype(world)
+  , m_initial_genome(in_genome)
+  , m_mut_info(world->GetEnvironment().GetMutationLib(), in_genome.GetSize())
+  , m_interface(NULL)
+  , m_lineage_label(-1)
+  , m_lineage(NULL)
+  , m_input_pointer(0)
+  , m_input_buf(world->GetEnvironment().GetInputSize())
+  , m_output_buf(world->GetEnvironment().GetOutputSize())
+  , m_received_messages(RECEIVED_MESSAGES_SIZE)
+  , m_sent_value(0)
+  , m_sent_active(false)
+  , m_test_receive_pos(0)
+  , m_pher_drop(false)
+  , m_max_executed(-1)
+  , m_is_running(false)
+  , m_is_sleeping(false)
+  , m_is_dead(false)
+  , killed_event(false)
+  , m_net(NULL)
+  , m_msg(0)
+  , m_opinion(0)
+{
+  m_hardware = m_world->GetHardwareManager().Create(this, inst_set);
+  
+  initialize(ctx);
+}
+
+
+void cOrganism::initialize(cAvidaContext& ctx)
+{
+  m_phenotype.SetInstSetSize(m_hardware->GetInstSet().GetSize());
+  
   if (m_world->GetConfig().DEATH_METHOD.Get() > DEATH_METHOD_OFF) {
     m_max_executed = m_world->GetConfig().AGE_LIMIT.Get();
     if (m_world->GetConfig().AGE_DEVIATION.Get() > 0.0) {
@@ -89,13 +126,13 @@
     if (m_world->GetConfig().DEATH_METHOD.Get() == DEATH_METHOD_MULTIPLE) {
       m_max_executed *= m_initial_genome.GetSize();
     }
-
+    
     // m_max_executed must be positive or an organism will not die!
     if (m_max_executed < 1) m_max_executed = 1;
   }
   
   if (m_world->GetConfig().NET_ENABLED.Get()) m_net = new cNetSupport();
-  m_id = m_world->GetStats().GetTotCreatures();
+  m_id = m_world->GetStats().GetTotCreatures();  
 }
 
 

Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/main/cOrganism.h	2008-08-23 00:42:17 UTC (rev 2757)
@@ -80,6 +80,7 @@
 class cGenotype;
 class cHardwareBase;
 class cInjectGenotype;
+class cInstSet;
 class cLineage;
 class cOrgSinkMessage;
 class cSaleItem;
@@ -104,8 +105,7 @@
 	int cclade_id;				                  // @MRR Coalescence clade information (set in cPopulation)
  
 	// Other stats
-  cCPUMemory m_child_genome; // Child genome, while under construction.
-//  sCPUStats m_cpu_stats;     // Info for statistics
+  cCPUMemory m_child_genome;              // Child genome, while under construction.
 
   // Input and Output with the environment
   int m_input_pointer;
@@ -143,12 +143,16 @@
   };
   cNetSupport* m_net;
   
+  
+  void initialize(cAvidaContext& ctx);
+  
   cOrganism(); // @not_implemented
   cOrganism(const cOrganism&); // @not_implemented
   cOrganism& operator=(const cOrganism&); // @not_implemented
   
 public:
   cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome);
+  cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome, cInstSet* inst_set);
   ~cOrganism();
 
   // --------  Accessor Methods  --------
@@ -181,7 +185,6 @@
   int GetMaxExecuted() const { return m_max_executed; }
   
   cCPUMemory& ChildGenome() { return m_child_genome; }
-//  sCPUStats& CPUStats() { return m_cpu_stats; }
 
   void SetRunning(bool in_running) { m_is_running = in_running; }
   bool IsRunning() { return m_is_running; }
@@ -432,16 +435,5 @@
 };
 
 
-#ifdef ENABLE_UNIT_TESTS
-namespace nOrganism {
-  /**
-   * Run unit tests
-   *
-   * @param full Run full test suite; if false, just the fast tests.
-   **/
-  void UnitTests(bool full = false);
-}
-#endif  
-
 #endif
 

Modified: development/source/main/cPhenPlastGenotype.cc
===================================================================
--- development/source/main/cPhenPlastGenotype.cc	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/main/cPhenPlastGenotype.cc	2008-08-23 00:42:17 UTC (rev 2757)
@@ -26,14 +26,6 @@
 #include <iostream>
 #include <cmath>
 
-cPhenPlastGenotype::cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cWorld* world, cAvidaContext& ctx)
-: m_genome(in_genome), m_num_trials(num_trials), m_world(world)
-{
-  cCPUTestInfo test_info;
-  test_info.UseRandomInputs(true);
-  Process(test_info, world, ctx);
-}
-
 cPhenPlastGenotype::cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cCPUTestInfo& test_info,  cWorld* world, cAvidaContext& ctx)
 : m_genome(in_genome), m_num_trials(num_trials), m_world(world)
 {

Modified: development/source/main/cPhenPlastGenotype.h
===================================================================
--- development/source/main/cPhenPlastGenotype.h	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/main/cPhenPlastGenotype.h	2008-08-23 00:42:17 UTC (rev 2757)
@@ -82,7 +82,6 @@
     void Process(cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx);
 
   public:
-      cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cWorld* world, cAvidaContext& ctx);
     cPhenPlastGenotype(const cGenome& in_genome, int num_trails, cCPUTestInfo& test_info,  cWorld* world, cAvidaContext& ctx);
     ~cPhenPlastGenotype();
     

Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/main/cPhenotype.cc	2008-08-23 00:42:17 UTC (rev 2757)
@@ -28,7 +28,6 @@
 #include "cEnvironment.h"
 #include "cDeme.h"
 #include "cHardwareManager.h"
-#include "cInstSet.h"
 #include "cReactionResult.h"
 #include "cTaskState.h"
 #include "cTools.h"
@@ -49,7 +48,6 @@
   , cur_task_value(m_world->GetEnvironment().GetNumTasks())  
   , cur_reaction_count(m_world->GetEnvironment().GetReactionLib().GetSize())
   , cur_reaction_add_reward(m_world->GetEnvironment().GetReactionLib().GetSize())
-  , cur_inst_count(world->GetHardwareManager().GetInstSet().GetSize())
   , cur_sense_count(m_world->GetStats().GetSenseSize())
   , sensed_resources(m_world->GetEnvironment().GetResourceLib().GetSize())
   , cur_task_time(m_world->GetEnvironment().GetNumTasks())   // Added for tracking time; WRE 03-18-07
@@ -58,7 +56,6 @@
   , last_task_value(m_world->GetEnvironment().GetNumTasks())
   , last_reaction_count(m_world->GetEnvironment().GetReactionLib().GetSize())
   , last_reaction_add_reward(m_world->GetEnvironment().GetReactionLib().GetSize())  
-  , last_inst_count(world->GetHardwareManager().GetInstSet().GetSize())
   , last_sense_count(m_world->GetStats().GetSenseSize())
 {
 }
@@ -244,7 +241,7 @@
   assert(age >= 0);
   assert(child_copied_size >= 0);
   // assert(to_die == false);
-  return true;
+  return (m_world);
 }
 
 
@@ -1087,222 +1084,8 @@
 }
 
 
-///// For Loading and Saving State: /////
 
 
-bool cPhenotype::SaveState(ofstream& fp)
-{
-  assert(fp.good());
-  fp << "cPhenotype" << endl;
-
-  fp << merit.GetDouble()   << " ";
-  fp << genome_length       << " ";
-  fp << copied_size         << " ";
-  fp << executed_size       << " ";
-  fp << gestation_time      << " ";
-  fp << gestation_start     << " ";
-  fp << fitness             << " ";
-  fp << div_type            << " ";
-
-  fp << cur_bonus           << " ";
-  fp << cur_num_errors      << " ";
-  fp << cur_num_donates      << " ";
-  for (int i = 0; i < cur_task_count.GetSize(); i++) {
-    fp << cur_task_count[i] << " ";
-  }
-  for (int i = 0; i < cur_reaction_count.GetSize(); i++) {
-    fp << cur_reaction_count[i] << " ";
-  }
-  for (int i = 0; i < cur_inst_count.GetSize(); i++) {
-    fp << cur_inst_count[i] << " ";
-  }
-
-  fp << last_merit_base     << " ";
-  fp << last_bonus          << " ";
-  fp << last_num_errors     << " ";
-  fp << last_num_donates    << " ";
-  for (int i = 0; i < last_task_count.GetSize(); i++) {
-    fp << last_task_count[i] << " ";
-  }
-  for (int i = 0; i < last_reaction_count.GetSize(); i++) {
-    fp << last_reaction_count[i] << " ";
-  }
-  for (int i = 0; i < last_inst_count.GetSize(); i++) {
-    fp << last_inst_count[i] << " ";
-  }
-
-  fp << num_divides         << " ";
-  fp << generation          << " ";
-  fp << cpu_cycles_used     << " ";
-  fp << time_used           << " ";
-  fp << age                 << " ";
-  fp << neutral_metric      << " ";
-  fp << life_fitness        << " ";
-
-  fp << is_injected         << " ";
-  fp << is_donor_last       << " ";
-  fp << is_donor_cur        << " ";
-  fp << is_donor_rand_last       << " ";
-  fp << is_donor_rand        << " ";
-  fp << is_donor_null_last       << " ";
-  fp << is_donor_null        << " ";
-  fp << is_donor_kin_last       << " ";
-  fp << is_donor_kin        << " ";
-  fp << is_donor_edit_last       << " ";
-  fp << is_donor_edit        << " ";
-  fp << is_donor_gbg_last       << " ";
-  fp << is_donor_gbg        << " ";
-  fp << is_donor_truegb_last       << " ";
-  fp << is_donor_truegb        << " ";
-  fp << is_donor_threshgb_last       << " ";
-  fp << is_donor_threshgb        << " ";
-  fp << is_donor_quanta_threshgb_last       << " ";
-  fp << is_donor_quanta_threshgb        << " ";
-  fp << num_thresh_gb_donations_last       << " ";
-  fp << num_thresh_gb_donations        << " ";
-  fp << num_quanta_thresh_gb_donations_last       << " ";
-  fp << num_quanta_thresh_gb_donations        << " ";
-
-  fp << is_receiver_last         << " ";
-  fp << is_receiver         << " ";
-  fp << is_receiver_rand         << " ";
-  fp << is_receiver_kin         << " ";
-  fp << is_receiver_kin_last         << " ";
-  fp << is_receiver_edit         << " ";
-  fp << is_receiver_edit_last         << " ";
-  fp << is_receiver_gbg         << " ";
-  fp << is_receiver_truegb_last         << " ";
-  fp << is_receiver_truegb         << " ";
-  fp << is_receiver_threshgb_last         << " ";
-  fp << is_receiver_threshgb         << " ";
-  fp << is_receiver_quanta_threshgb_last         << " ";
-  fp << is_receiver_quanta_threshgb         << " ";
-  fp << is_modifier         << " ";
-  fp << is_modified         << " ";
-  fp << is_fertile          << " ";
-  fp << is_mutated          << " ";
-  fp << parent_true         << " ";
-  fp << parent_sex          << " ";
-  fp << parent_cross_num    << " ";
-
-  fp << copy_true           << " ";
-  fp << divide_sex          << " ";
-  fp << mate_select_id      << " ";
-  fp << cross_num           << " ";
-  fp << child_fertile       << " ";
-  fp << last_child_fertile  << " ";
-
-  fp << endl;
-  return true;
-}
-
-
-bool cPhenotype::LoadState(ifstream & fp)
-{
-  double tmp_merit;
-  assert(fp.good());
-  if( !fp.good() ) return false;
-
-  fp >> tmp_merit;  merit = tmp_merit;
-  fp >> genome_length;
-  fp >> copied_size;
-  fp >> executed_size;
-  fp >> gestation_time;
-  fp >> gestation_start;
-  fp >> fitness;
-  fp >> div_type;
-
-  fp >> cur_bonus;
-  fp >> cur_num_errors;
-  fp >> cur_num_donates;
-
-  for (int i = 0; i < cur_task_count.GetSize(); i++) {
-    fp >> cur_task_count[i];
-  }
-  for (int i = 0; i < cur_reaction_count.GetSize(); i++) {
-    fp >> cur_reaction_count[i];
-  }
-  for (int i = 0; i < cur_inst_count.GetSize(); i++) {
-    fp >> cur_inst_count[i];
-  }
-
-  fp >> last_merit_base;
-  fp >> last_bonus;
-  fp >> last_num_errors;
-  fp >> last_num_donates;
-  for (int i = 0; i < last_task_count.GetSize(); i++) {
-    fp >> last_task_count[i];
-  }
-  for (int i = 0; i < last_reaction_count.GetSize(); i++) {
-    fp >> last_reaction_count[i];
-  }
-  for (int i = 0; i < last_inst_count.GetSize(); i++) {
-    fp >> last_inst_count[i];
-  }
-
-  fp >> num_divides;
-  fp >> generation;
-  fp >> cpu_cycles_used;
-  fp >> time_used;
-  fp >> age;
-  fp >> neutral_metric;
-  fp >> life_fitness;
-
-  fp >> is_injected;
-  fp >> is_donor_last;
-  fp >> is_donor_cur;
-  fp >> is_donor_rand_last;
-  fp >> is_donor_rand;
-  fp >> is_donor_null_last;
-  fp >> is_donor_null;
-  fp >> is_donor_kin_last;
-  fp >> is_donor_kin;
-  fp >> is_donor_edit_last;
-  fp >> is_donor_edit;
-  fp >> is_donor_gbg_last;
-  fp >> is_donor_gbg;
-  fp >> is_donor_truegb_last;
-  fp >> is_donor_truegb;
-  fp >> is_donor_threshgb_last;
-  fp >> is_donor_threshgb;
-  fp >> is_donor_quanta_threshgb_last;
-  fp >> is_donor_quanta_threshgb;
-  fp >> num_thresh_gb_donations_last;
-  fp >> num_thresh_gb_donations;
-  fp >> num_quanta_thresh_gb_donations_last;
-  fp >> num_quanta_thresh_gb_donations;
-  fp >> is_receiver_last;
-  fp >> is_receiver;
-  fp >> is_receiver_rand;
-  fp >> is_receiver_kin;
-  fp >> is_receiver_kin_last;
-  fp >> is_receiver_edit;
-  fp >> is_receiver_edit_last;
-  fp >> is_receiver_gbg;
-  fp >> is_receiver_truegb_last;
-  fp >> is_receiver_truegb;
-  fp >> is_receiver_threshgb_last;
-  fp >> is_receiver_threshgb;
-  fp >> is_receiver_quanta_threshgb_last;
-  fp >> is_receiver_quanta_threshgb;
-  fp >> is_modifier;
-  fp >> is_modified;
-  fp >> is_fertile;
-  fp >> is_mutated;
-  fp >> parent_true;
-  fp >> parent_sex;
-  fp >> parent_cross_num;
-
-  fp >> copy_true;
-  fp >> divide_sex;
-  fp >> mate_select_id;
-  fp >> cross_num;
-  fp >> child_fertile;
-  fp >> last_child_fertile;
-
-  return true;
-}
-
 void cPhenotype::PrintStatus(ostream& fp) const
 {
   fp << "  MeritBase:"

Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/main/cPhenotype.h	2008-08-23 00:42:17 UTC (rev 2757)
@@ -86,6 +86,7 @@
 
 class cPhenotype
 {
+  friend class cOrganism;
 private:
   cWorld* m_world;
   bool initialized;
@@ -218,12 +219,20 @@
   // 7. Information that is set once (when organism was born)
   double permanent_germline_propensity;
   
+
+  inline void SetInstSetSize(int inst_set_size);
+
+  
+  cPhenotype(cWorld* world);
+
+  
 public:
-  cPhenotype() { ; } // @not_implemented
-  cPhenotype(cWorld* world);
+  cPhenotype() : m_world(NULL) { ; } // Will not construct a valid cPhenotype! Only exists to support incorrect cDeme tArray usage.
+
   cPhenotype(const cPhenotype&); 
   cPhenotype& operator=(const cPhenotype&); 
   ~cPhenotype();
+  
 
   bool OK();
 
@@ -250,8 +259,6 @@
                   tArray<int>& insts_triggered);
 
   // State saving and loading, and printing...
-  bool SaveState(std::ofstream& fp);
-  bool LoadState(std::ifstream & fp);
   void PrintStatus(std::ostream& fp) const;
 
   // Some useful methods...
@@ -480,15 +487,10 @@
 };
 
 
-#ifdef ENABLE_UNIT_TESTS
-namespace nPhenotype {
-  /**
-   * Run unit tests
-   *
-   * @param full Run full test suite; if false, just the fast tests.
-   **/
-  void UnitTests(bool full = false);
+inline void cPhenotype::SetInstSetSize(int inst_set_size)
+{
+  cur_inst_count.Resize(inst_set_size, 0);
+  last_inst_count.Resize(inst_set_size, 0);
 }
-#endif  
 
 #endif

Modified: development/source/tools/cDataFileManager.cc
===================================================================
--- development/source/tools/cDataFileManager.cc	2008-08-22 21:23:55 UTC (rev 2756)
+++ development/source/tools/cDataFileManager.cc	2008-08-23 00:42:17 UTC (rev 2757)
@@ -96,7 +96,11 @@
     if (d == -1) break;
     
     // If directory name is not null
-    if (d - i > 0) cTools::MkDir(dir_prefix + target.Substring(0, d - i), false);
+    if (d - i > 0) {
+      cString dir = target.Substring(i, d - i);
+      // Create if  that this directory is not a relative path component
+      if (dir.GetSize() > 2 || (dir != "." && dir != "..")) cTools::MkDir(dir_prefix + target.Substring(0, d), false);
+    }
     
     // Adjust next directory name starting point
     i = d + 1;




More information about the Avida-cvs mailing list