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

barrick at myxo.css.msu.edu barrick at myxo.css.msu.edu
Sun Feb 18 09:14:22 PST 2007


Author: barrick
Date: 2007-02-18 12:14:21 -0500 (Sun, 18 Feb 2007)
New Revision: 1331

Modified:
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/main/cPhenotype.h
   development/source/main/cWorld.cc
Log:

Added a "put" instruction that resets the environmental inputs in a cell AND clears the organism's input buffer. This forces an organism to get new numbers from the environment to complete further tasks.

Added a "recover" instruction that zeros the energy of an organism. This could be triggered by completing a task. Testing some possible uses, more infrastructure for keeping track of energy used stats needed

Fixed an order-of-initialization problem which caused a crash for instructions triggered by reactions.



Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2007-02-18 01:53:22 UTC (rev 1330)
+++ development/source/cpu/cHardwareCPU.cc	2007-02-18 17:14:21 UTC (rev 1331)
@@ -188,7 +188,7 @@
     tInstLibEntry<tMethod>("stk-load", &cHardwareCPU::Inst_TaskStackLoad),
     tInstLibEntry<tMethod>("put", &cHardwareCPU::Inst_TaskPut),
     tInstLibEntry<tMethod>("put-clear", &cHardwareCPU::Inst_TaskPutClearInput), 
-    tInstLibEntry<tMethod>("put-reset", &cHardwareCPU::Inst_TaskPutResetInputs), 
+    tInstLibEntry<tMethod>("put-reset", &cHardwareCPU::Inst_TaskPutResetInputs),
     tInstLibEntry<tMethod>("put-bcost2", &cHardwareCPU::Inst_TaskPutBonusCost2),
     tInstLibEntry<tMethod>("put-mcost2", &cHardwareCPU::Inst_TaskPutMeritCost2),
     tInstLibEntry<tMethod>("IO", &cHardwareCPU::Inst_TaskIO, nInstFlag::DEFAULT, "Output ?BX?, and input new number back into ?BX?"),
@@ -212,6 +212,9 @@
     
     tInstLibEntry<tMethod>("set-cmut", &cHardwareCPU::Inst_SetCopyMut),
     tInstLibEntry<tMethod>("mod-cmut", &cHardwareCPU::Inst_ModCopyMut),
+
+    // Energy instruction
+    tInstLibEntry<tMethod>("recover", &cHardwareCPU::Inst_ZeroEnergyUsed),
     
     // Threading instructions
     tInstLibEntry<tMethod>("fork-th", &cHardwareCPU::Inst_ForkThread),
@@ -2720,6 +2723,8 @@
 {
   bool return_value = Inst_TaskPut(ctx);          // Do a normal put
   organism->GetOrgInterface().ResetInputs(ctx);   // Now re-randomize the inputs this organism sees
+  organism->ClearInput();                         // Also clear their input buffers, or they can still claim
+                                                  // rewards for numbers no longer in their environment!
   return return_value;
 }
 
@@ -3219,7 +3224,15 @@
   return true;
 }
 
+// Energy use
 
+bool cHardwareCPU::Inst_ZeroEnergyUsed(cAvidaContext& ctx)
+{
+  // Typically, this instruction should be triggered by a REACTION
+  organism->GetPhenotype().SetTimeUsed(0); 
+  return true;  
+}
+
 // Multi-threading.
 
 bool cHardwareCPU::Inst_ForkThread(cAvidaContext& ctx)

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2007-02-18 01:53:22 UTC (rev 1330)
+++ development/source/cpu/cHardwareCPU.h	2007-02-18 17:14:21 UTC (rev 1331)
@@ -413,7 +413,7 @@
   bool Inst_TaskStackLoad(cAvidaContext& ctx);
   bool Inst_TaskPut(cAvidaContext& ctx);
   bool Inst_TaskPutClearInput(cAvidaContext& ctx);  
-  bool Inst_TaskPutResetInputs(cAvidaContext& ctx);  
+  bool Inst_TaskPutResetInputs(cAvidaContext& ctx);
   bool Inst_TaskPutBonusCost2(cAvidaContext& ctx);  
   bool Inst_TaskPutMeritCost2(cAvidaContext& ctx); 
   bool Inst_TaskIO(cAvidaContext& ctx);
@@ -445,6 +445,10 @@
   bool Inst_SetCopyMut(cAvidaContext& ctx);
   bool Inst_ModCopyMut(cAvidaContext& ctx);
 
+  // Energy use
+  
+  bool Inst_ZeroEnergyUsed(cAvidaContext& ctx); 
+
   // Multi-threading...
 
   bool Inst_ForkThread(cAvidaContext& ctx);

Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h	2007-02-18 01:53:22 UTC (rev 1330)
+++ development/source/main/cPhenotype.h	2007-02-18 17:14:21 UTC (rev 1331)
@@ -274,6 +274,7 @@
   ////////////////////  Accessors -- Modifying  ///////////////////
   void SetMerit(const cMerit& in_merit) { merit = in_merit; }
   void SetGestationTime(int in_time) { gestation_time = in_time; }
+  void SetTimeUsed(int in_time) { time_used = in_time; }
   void SetFault(const cString& in_fault) { fault_desc = in_fault; }
   void SetNeutralMetric(double _in){ neutral_metric = _in; }
   void SetLifeFitness(double _in){ life_fitness = _in; }

Modified: development/source/main/cWorld.cc
===================================================================
--- development/source/main/cWorld.cc	2007-02-18 01:53:22 UTC (rev 1330)
+++ development/source/main/cWorld.cc	2007-02-18 17:14:21 UTC (rev 1331)
@@ -83,16 +83,15 @@
   
   m_class_mgr = new cClassificationManager(this);
   m_env = new cEnvironment(this);
+  m_hw_mgr = new cHardwareManager(this);
   
   // Initialize the default environment...
+  // This must be after the HardwareManager in case REACTIONS that trigger instructions are used.
   if (!m_env->Load(m_conf->ENVIRONMENT_FILE.Get())) {
     cerr << "Error: Unable to load environment" << endl;
     ExitAvida(-1);
   }
   
-  m_hw_mgr = new cHardwareManager(this);
-  
-  
   // Setup Stats Object
   m_stats = new cStats(this);
     




More information about the Avida-cvs mailing list