[Avida-SVN] r2980 - in development/source: actions cpu main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Wed Nov 26 18:44:11 PST 2008


Author: brysonda
Date: 2008-11-26 21:44:11 -0500 (Wed, 26 Nov 2008)
New Revision: 2980

Modified:
   development/source/actions/PopulationActions.cc
   development/source/cpu/cCPUTestInfo.h
   development/source/cpu/cHardwareBase.cc
   development/source/cpu/cHardwareBase.h
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/cpu/cHardwareExperimental.cc
   development/source/cpu/cHardwareExperimental.h
   development/source/cpu/cHardwareGX.cc
   development/source/cpu/cHardwareGX.h
   development/source/cpu/cHardwareManager.cc
   development/source/cpu/cHardwareManager.h
   development/source/cpu/cHardwareSMT.cc
   development/source/cpu/cHardwareSMT.h
   development/source/cpu/cHardwareTransSMT.cc
   development/source/cpu/cHardwareTransSMT.h
   development/source/cpu/cTestCPU.cc
   development/source/cpu/cTestCPU.h
   development/source/cpu/cTestCPUInterface.cc
   development/source/cpu/cTestCPUInterface.h
   development/source/main/cOrgInterface.h
   development/source/main/cOrganism.cc
   development/source/main/cOrganism.h
   development/source/main/cPopulation.cc
   development/source/main/cPopulation.h
   development/source/main/cPopulationInterface.cc
   development/source/main/cPopulationInterface.h
Log:
Implement state grid selection.  The default population behavior selects a random state grid from the available pool.  The test cpu objects support the appropriate calls to set the state grid as well.  However, currently cCPUTestInfo, which is responsible for setting the desired state grid, is hard coded to the first one in the environment.

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/actions/PopulationActions.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -1913,7 +1913,7 @@
   
   void Process(cAvidaContext& ctx)
   {
-    m_world->GetPopulation().NewTrial();
+    m_world->GetPopulation().NewTrial(ctx);
   }
 };
 
@@ -1934,7 +1934,7 @@
   
   void Process(cAvidaContext& ctx)
   {
-    m_world->GetPopulation().CompeteOrganisms(m_type, m_parents_survive);
+    m_world->GetPopulation().CompeteOrganisms(ctx, m_type, m_parents_survive);
   }
 };
 

Modified: development/source/cpu/cCPUTestInfo.h
===================================================================
--- development/source/cpu/cCPUTestInfo.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cCPUTestInfo.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -128,6 +128,8 @@
   // And just because these are so commonly used...
   double GetGenotypeFitness();
   double GetColonyFitness();
+  
+  int GetStateGridID() const { return 0; } // @TODO - state grid - support setting cCPUTestInfo's state grid id
 };
 
 

Modified: development/source/cpu/cHardwareBase.cc
===================================================================
--- development/source/cpu/cHardwareBase.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareBase.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -48,9 +48,9 @@
 #include "functions.h"
 
 
-void cHardwareBase::Reset()
+void cHardwareBase::Reset(cAvidaContext& ctx)
 {
-  m_organism->HardwareReset();
+  m_organism->HardwareReset(ctx);
 
   m_inst_cost = 0;
   

Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareBase.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -93,7 +93,7 @@
 
   
   // --------  Core Functionality  --------
-  void Reset();
+  void Reset(cAvidaContext& ctx);
   virtual bool SingleProcess(cAvidaContext& ctx, bool speculative = false) = 0;
   virtual void ProcessBonusInst(cAvidaContext& ctx, const cInstruction& inst) = 0;
 

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareCPU.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -516,7 +516,7 @@
   return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
-cHardwareCPU::cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
+cHardwareCPU::cHardwareCPU(cAvidaContext& ctx, cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
 : cHardwareBase(world, in_organism, in_m_inst_set)
 , m_last_cell_data(false, 0)
 {
@@ -534,7 +534,7 @@
   m_constituative_regulation = m_world->GetConfig().CONSTITUTIVE_REGULATION.Get();
   
   m_memory = in_organism->GetGenome();  // Initialize memory...
-  Reset();                            // Setup the rest of the hardware...
+  Reset(ctx);                            // Setup the rest of the hardware...
 }
 
 
@@ -1443,7 +1443,7 @@
       InheritState(*this);  
     }
 
-    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
+    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
   
   return true;
@@ -1533,7 +1533,7 @@
   // birth.
   bool parent_alive = m_organism->ActivateDivide(ctx);
   if (parent_alive) {
-    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
+    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
   
   return true;
@@ -1624,7 +1624,7 @@
   // birth.
   bool parent_alive = m_organism->ActivateDivide(ctx);
   if (parent_alive) {
-    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
+    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
   
   return true;
@@ -1715,7 +1715,7 @@
   // birth.
   bool parent_alive = m_organism->ActivateDivide(ctx);
   if (parent_alive) {
-    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
+    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
   
   return true;
@@ -2716,7 +2716,7 @@
   
   //Reset the parent
   if (parent_alive) {
-    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
+    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
   return true;
 }
@@ -7477,7 +7477,7 @@
 
 
 bool cHardwareCPU::Inst_HardReset(cAvidaContext& ctx) {
-  Reset();
+  Reset(ctx);
   m_advance_ip = false;
   return true;
 }

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareCPU.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -243,7 +243,7 @@
   cHardwareCPU& operator=(const cHardwareCPU&); // @not_implemented
 
 public:
-  cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
+  cHardwareCPU(cAvidaContext& ctx, cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
   ~cHardwareCPU() { ; }
   static tInstLib<tMethod>* GetInstLib() { return s_inst_slib; }
   static cString GetDefaultInstFilename() { return "instset-classic.cfg"; }

Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareExperimental.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -203,7 +203,7 @@
   return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
-cHardwareExperimental::cHardwareExperimental(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
+cHardwareExperimental::cHardwareExperimental(cAvidaContext& ctx, cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
 : cHardwareBase(world, in_organism, in_m_inst_set)
 {
   /* FIXME:  reorganize storage of m_functions.  -- kgn */
@@ -219,7 +219,7 @@
   m_constituative_regulation = m_world->GetConfig().CONSTITUTIVE_REGULATION.Get();
   
   m_memory = in_organism->GetGenome();  // Initialize memory...
-  Reset();                            // Setup the rest of the hardware...
+  Reset(ctx);                            // Setup the rest of the hardware...
 }
 
 
@@ -968,7 +968,7 @@
 
   // Do more work if the parent lives through the birth of the offspring
   if (parent_alive) {
-    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
+    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
   
   return true;
@@ -1832,7 +1832,7 @@
   
   // Do more work if the parent lives through the birth of the offspring
   if (parent_alive) {
-    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
+    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
   
   return true;

Modified: development/source/cpu/cHardwareExperimental.h
===================================================================
--- development/source/cpu/cHardwareExperimental.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareExperimental.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -280,7 +280,7 @@
 
   
 public:
-  cHardwareExperimental(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
+  cHardwareExperimental(cAvidaContext& ctx, cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
   ~cHardwareExperimental() { ; }
   static tInstLib<cHardwareExperimental::tMethod>* GetInstLib() { return s_inst_slib; }
   static cString GetDefaultInstFilename() { return "instset-experimental.cfg"; }

Modified: development/source/cpu/cHardwareGX.cc
===================================================================
--- development/source/cpu/cHardwareGX.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareGX.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -311,12 +311,12 @@
 /*! Construct a cHardwareGX instance from the passed-in cOrganism.  This amounts to
 creating an initial cProgramid from in_organism's genome.
 */
-cHardwareGX::cHardwareGX(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
+cHardwareGX::cHardwareGX(cAvidaContext& ctx, cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
 : cHardwareBase(world, in_organism, in_m_inst_set)
 {
   m_last_unique_id_assigned = 0;
   m_functions = s_inst_slib->GetFunctions();
-  Reset();   // Setup the rest of the hardware...also creates initial programid(s) from genome
+  Reset(ctx);   // Setup the rest of the hardware...also creates initial programid(s) from genome
 }
 
 
@@ -1276,7 +1276,7 @@
 //
 //  // Do more work if the parent lives through the birth of the offspring
 //  if (parent_alive) {
-//    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
+//    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
 //  }
 //  
   return true;
@@ -2107,7 +2107,7 @@
 
   // Do more work if the parent lives through the birth of the offspring
   if (parent_alive) {
-    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
+    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
 
   m_just_divided = true;
@@ -3919,7 +3919,7 @@
 
   // Do more work if the parent lives through the birth of the offspring
   if (parent_alive) {
-    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
+    if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
   
   m_just_divided = true;

Modified: development/source/cpu/cHardwareGX.h
===================================================================
--- development/source/cpu/cHardwareGX.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareGX.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -307,7 +307,7 @@
 
 public:
   //! Main constructor for cHardwareGX; called from cHardwareManager for every organism.
-  cHardwareGX(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
+  cHardwareGX(cAvidaContext& ctx, cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
   virtual ~cHardwareGX(); //!< Destructor; removes all cProgramids.
     
   static tInstLib<tMethod>* GetInstLib() { return s_inst_slib; }

Modified: development/source/cpu/cHardwareManager.cc
===================================================================
--- development/source/cpu/cHardwareManager.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareManager.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -83,7 +83,7 @@
   }
 }
 
-cHardwareBase* cHardwareManager::Create(cOrganism* in_org, cInstSet* inst_set)
+cHardwareBase* cHardwareManager::Create(cAvidaContext& ctx, cOrganism* in_org, cInstSet* inst_set)
 {
   assert(in_org != NULL);
 	
@@ -91,19 +91,19 @@
 	
   switch (m_type) {
     case HARDWARE_TYPE_CPU_ORIGINAL:
-      hw = new cHardwareCPU(m_world, in_org, m_inst_set);
+      hw = new cHardwareCPU(ctx, m_world, in_org, m_inst_set);
       break;
     case HARDWARE_TYPE_CPU_SMT:
-      hw = new cHardwareSMT(m_world, in_org, m_inst_set);
+      hw = new cHardwareSMT(ctx, m_world, in_org, m_inst_set);
       break;
     case HARDWARE_TYPE_CPU_TRANSSMT:
-      hw = new cHardwareTransSMT(m_world, in_org, m_inst_set);
+      hw = new cHardwareTransSMT(ctx, m_world, in_org, m_inst_set);
       break;
     case HARDWARE_TYPE_CPU_EXPERIMENTAL:
-      hw = new cHardwareExperimental(m_world, in_org, m_inst_set);
+      hw = new cHardwareExperimental(ctx, m_world, in_org, m_inst_set);
       break;
     case HARDWARE_TYPE_CPU_GX:
-      hw = new cHardwareGX(m_world, in_org, m_inst_set);
+      hw = new cHardwareGX(ctx, m_world, in_org, m_inst_set);
       break;
     default:
       cDriverManager::Status().SignalError("Unknown/Unsupported HARDWARE_TYPE specified", -1);

Modified: development/source/cpu/cHardwareManager.h
===================================================================
--- development/source/cpu/cHardwareManager.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareManager.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -35,6 +35,7 @@
 # endif
 #endif
 
+class cAvidaContext;
 class cHardwareBase;
 class cInstSet;
 class cOrganism;
@@ -62,8 +63,8 @@
   cHardwareManager(cWorld* world);
   ~cHardwareManager() { ; }
   
-  cHardwareBase* Create(cOrganism* in_org, cInstSet* inst_set);
-  inline cHardwareBase* Create(cOrganism* in_org) { return Create(in_org, m_inst_set); }
+  cHardwareBase* Create(cAvidaContext& ctx, cOrganism* in_org, cInstSet* inst_set);
+  inline cHardwareBase* Create(cAvidaContext& ctx, cOrganism* in_org) { return Create(ctx, in_org, m_inst_set); }
   cTestCPU* CreateTestCPU() { return new cTestCPU(m_world); }
 
   const cInstSet& GetInstSet() const { return *m_inst_set; }

Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareSMT.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -133,7 +133,7 @@
   return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
-cHardwareSMT::cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
+cHardwareSMT::cHardwareSMT(cAvidaContext& ctx, cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
 : cHardwareBase(world, in_organism, in_m_inst_set), m_mem_array(1), m_mem_marks(1)
 , m_mem_lbls(Pow(NUM_NOPS, MAX_MEMSPACE_LABEL) / MEM_LBLS_HASH_FACTOR)
 , m_thread_lbls(Pow(NUM_NOPS, MAX_THREAD_LABEL) / THREAD_LBLS_HASH_FACTOR)
@@ -143,7 +143,7 @@
   m_mem_array[0] = in_organism->GetGenome();  // Initialize memory...
   m_mem_array[0].Resize(m_mem_array[0].GetSize() + 1);
   m_mem_array[0][m_mem_array[0].GetSize() - 1] = cInstruction();
-  Reset();                            // Setup the rest of the hardware...
+  Reset(ctx);                            // Setup the rest of the hardware...
 }
 
 void cHardwareSMT::internalReset()
@@ -950,7 +950,7 @@
 		if (div_method == DIVIDE_METHOD_SPLIT)
 		{
 			//this will wipe out all parasites on a divide.
-			Reset();
+			Reset(ctx);
 			
 		}
 		else if (div_method == DIVIDE_METHOD_BIRTH)

Modified: development/source/cpu/cHardwareSMT.h
===================================================================
--- development/source/cpu/cHardwareSMT.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareSMT.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -200,7 +200,7 @@
   cHardwareSMT& operator=(const cHardwareSMT&); // @not_implemented
   
 public:
-  cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
+  cHardwareSMT(cAvidaContext& ctx, cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
   ~cHardwareSMT() { ; }
   static cInstLib* GetInstLib() { return s_inst_slib; }
   static cString GetDefaultInstFilename() { return "instset-smt.cfg"; }

Modified: development/source/cpu/cHardwareTransSMT.cc
===================================================================
--- development/source/cpu/cHardwareTransSMT.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareTransSMT.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -132,7 +132,7 @@
   return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
-cHardwareTransSMT::cHardwareTransSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
+cHardwareTransSMT::cHardwareTransSMT(cAvidaContext& ctx, cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
 : cHardwareBase(world, in_organism, in_m_inst_set), m_mem_array(1)
 , m_mem_lbls(Pow(NUM_NOPS, MAX_MEMSPACE_LABEL) / MEM_LBLS_HASH_FACTOR)
 , m_thread_lbls(Pow(NUM_NOPS, MAX_THREAD_LABEL) / THREAD_LBLS_HASH_FACTOR)
@@ -142,7 +142,7 @@
   m_mem_array[0] = in_organism->GetGenome();  // Initialize memory...
   m_mem_array[0].Resize(m_mem_array[0].GetSize() + 1);
   m_mem_array[0][m_mem_array[0].GetSize() - 1] = cInstruction();
-  Reset();                            // Setup the rest of the hardware...
+  Reset(ctx);                            // Setup the rest of the hardware...
 }
 
 void cHardwareTransSMT::internalReset()
@@ -951,7 +951,7 @@
   if (parent_alive) { // If the parent is no longer alive, all of this is moot
     switch (m_world->GetConfig().DIVIDE_METHOD.Get()) {
       case DIVIDE_METHOD_SPLIT:
-        Reset();  // This will wipe out all parasites on a divide.
+        Reset(ctx);  // This will wipe out all parasites on a divide.
         break;
       
       case DIVIDE_METHOD_BIRTH:

Modified: development/source/cpu/cHardwareTransSMT.h
===================================================================
--- development/source/cpu/cHardwareTransSMT.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cHardwareTransSMT.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -199,7 +199,7 @@
   cHardwareTransSMT& operator=(const cHardwareTransSMT&); // @not_implemented
   
 public:
-  cHardwareTransSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
+  cHardwareTransSMT(cAvidaContext& ctx, cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
   ~cHardwareTransSMT() { ; }
   static cInstLib* GetInstLib() { return s_inst_slib; }
   static cString GetDefaultInstFilename() { return "instset-transsmt.cfg"; }

Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cTestCPU.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -287,7 +287,7 @@
   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->SetOrgInterface(new cTestCPUInterface(this, test_info));
   organism->GetPhenotype().SetupInject(genome);
 
   // Run the current organism.

Modified: development/source/cpu/cTestCPU.h
===================================================================
--- development/source/cpu/cTestCPU.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cTestCPU.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -73,6 +73,8 @@
   // Actual CPU resources.
   cResourceCount m_resource_count;
   cResourceCount m_deme_resource_count;
+  
+  
 
   bool ProcessGestation(cAvidaContext& ctx, cCPUTestInfo& test_info, int cur_depth);
   bool TestGenome_Body(cAvidaContext& ctx, cCPUTestInfo& test_info, const cGenome& genome, int cur_depth);

Modified: development/source/cpu/cTestCPUInterface.cc
===================================================================
--- development/source/cpu/cTestCPUInterface.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cTestCPUInterface.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -128,3 +128,7 @@
   return false;
 }
 
+int cTestCPUInterface::GetStateGridID(cAvidaContext& ctx)
+{
+  return m_test_info.GetStateGridID();
+}

Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/cpu/cTestCPUInterface.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -29,6 +29,7 @@
 #include "cOrgInterface.h"
 #endif
 
+class cCPUTestInfo;
 class cTestCPU;
 
 #ifndef NULL
@@ -39,9 +40,10 @@
 {
 private:
   cTestCPU* m_testcpu;
+  cCPUTestInfo& m_test_info;
 
 public:
-  cTestCPUInterface(cTestCPU* testcpu) : m_testcpu(testcpu) { ; }
+  cTestCPUInterface(cTestCPU* testcpu, cCPUTestInfo& test_info) : m_testcpu(testcpu), m_test_info(test_info) { ; }
   virtual ~cTestCPUInterface() { ; }
 
   int GetCellID() { return -1; }
@@ -93,6 +95,8 @@
 	bool BcastAlarm(int jump_label, int bcast_range) { return false; }
   void DivideOrgTestamentAmongDeme(double value) {;}
 	void SendFlash() { }
+  
+  int GetStateGridID(cAvidaContext& ctx);
 };
 
 

Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/main/cOrgInterface.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -105,6 +105,8 @@
   virtual bool BcastAlarm(int jump_jabel, int bcast_range) = 0;
   virtual void DivideOrgTestamentAmongDeme(double value) = 0;
 	virtual void SendFlash() = 0;
+  
+  virtual int GetStateGridID(cAvidaContext& ctx) = 0;
 };
 
 #endif

Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/main/cOrganism.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -80,7 +80,7 @@
   , m_msg(0)
   , m_opinion(0)
 {
-  m_hardware = m_world->GetHardwareManager().Create(this);
+  m_hardware = m_world->GetHardwareManager().Create(ctx, this);
 
   initialize(ctx);
 }
@@ -113,7 +113,7 @@
   , m_msg(0)
   , m_opinion(0)
 {
-  m_hardware = m_world->GetHardwareManager().Create(this, inst_set);
+  m_hardware = m_world->GetHardwareManager().Create(ctx, this, inst_set);
   
   initialize(ctx);
 }
@@ -528,10 +528,11 @@
   return true;
 }
 
-void cOrganism::HardwareReset()
+void cOrganism::HardwareReset(cAvidaContext& ctx)
 {
   if (m_world->GetEnvironment().GetNumStateGrids() > 0) {
-    m_cur_sg = 0; // @TODO - state grid select current
+    // Select random state grid in the environment
+    m_cur_sg = m_interface->GetStateGridID(ctx);
     
     const cStateGrid& sg = GetStateGrid();
     

Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/main/cOrganism.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -34,9 +34,6 @@
 #ifndef cCPUMemory_h
 #include "cCPUMemory.h"
 #endif
-//#ifndef sCPUStats_h
-//#include "sCPUStats.h"
-//#endif
 #ifndef cGenome_h
 #include "cGenome.h"
 #endif
@@ -165,7 +162,7 @@
   double GetTestFitness(cAvidaContext& ctx);
   double CalcMeritRatio();
   
-  void HardwareReset();
+  void HardwareReset(cAvidaContext& ctx);
   
   void PrintStatus(std::ostream& fp, const cString& next_name);
   void PrintFinalStatus(std::ostream& fp, int time_used, int time_allocated) const;

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/main/cPopulation.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -4785,7 +4785,7 @@
 }
 
 // Starts a new trial for each organism in the population
-void cPopulation::NewTrial()
+void cPopulation::NewTrial(cAvidaContext& ctx)
 {
   for (int i=0; i< GetSize(); i++)
   {
@@ -4802,7 +4802,7 @@
         p.SetTimeUsed(p.GetTimeUsed() - cell.GetSpeculativeState());
         
         cell.GetOrganism()->NewTrial();
-        cell.GetOrganism()->GetHardware().Reset();
+        cell.GetOrganism()->GetHardware().Reset(ctx);
         
         cell.SetSpeculativeState(0);
       }
@@ -4824,9 +4824,9 @@
  equals a time of 1 unit
  */
 
-void cPopulation::CompeteOrganisms(int competition_type, int parents_survive)
+void cPopulation::CompeteOrganisms(cAvidaContext& ctx, int competition_type, int parents_survive)
 {
-  NewTrial();
+  NewTrial(ctx);
   
   double total_fitness = 0;
   int num_cells = GetSize();
@@ -5142,7 +5142,7 @@
   m_world->GetStats().SetCompetitionFitnesses(average_fitness, lowest_fitness, highest_fitness, average_fitness_copied, lowest_fitness_copied, highest_fitness_copied);
   m_world->GetStats().SetCompetitionOrgsReplicated(different_orgs_copied);
   
-  NewTrial();
+  NewTrial(ctx);
 }
 
 /* This routine is designed to change values in the resource count in the 

Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/main/cPopulation.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -314,8 +314,8 @@
   tVector<pair<int,int> > getCellSleepLog(int i) { return sleep_log[i]; }
 
   // Trials and genetic algorithm @JEB
-  void NewTrial();
-  void CompeteOrganisms(int competition_type, int parents_survive);
+  void NewTrial(cAvidaContext& ctx);
+  void CompeteOrganisms(cAvidaContext& ctx, int competition_type, int parents_survive);
   
   // Let users change environmental variables durning the run @BDB 22-Feb-2008
   void UpdateResourceCount(const int Verbosity);

Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/main/cPopulationInterface.cc	2008-11-27 02:44:11 UTC (rev 2980)
@@ -25,6 +25,7 @@
 
 #include "cPopulationInterface.h"
 
+#include "cEnvironment.h"
 #include "cGenotype.h"
 #include "cHardwareManager.h"
 #include "cOrganism.h"
@@ -390,3 +391,8 @@
     cell.ConnectionList().CircNext();
   }
 }
+
+int cPopulationInterface::GetStateGridID(cAvidaContext& ctx)
+{
+  return ctx.GetRandom().GetUInt(m_world->GetEnvironment().GetNumStateGrids());
+}

Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h	2008-11-27 01:11:58 UTC (rev 2979)
+++ development/source/main/cPopulationInterface.h	2008-11-27 02:44:11 UTC (rev 2980)
@@ -111,6 +111,8 @@
   void DivideOrgTestamentAmongDeme(double value);
 	//! Send a flash to all neighboring organisms.
   void SendFlash();
+
+  int GetStateGridID(cAvidaContext& ctx);
 };
 
 




More information about the Avida-cvs mailing list