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

barrick at myxo.css.msu.edu barrick at myxo.css.msu.edu
Thu Feb 15 07:08:27 PST 2007


Author: barrick
Date: 2007-02-15 10:08:27 -0500 (Thu, 15 Feb 2007)
New Revision: 1325

Modified:
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/cpu/cHardwareExperimental.cc
   development/source/cpu/cTestCPU.cc
   development/source/cpu/cTestCPU.h
   development/source/cpu/cTestCPUInterface.cc
   development/source/cpu/cTestCPUInterface.h
   development/source/defs.h
   development/source/main/cAvidaConfig.h
   development/source/main/cOrgInterface.h
   development/source/main/cPopulation.cc
   development/source/main/cPopulation.h
   development/source/main/cPopulationCell.cc
   development/source/main/cPopulationCell.h
   development/source/main/cPopulationInterface.cc
   development/source/main/cPopulationInterface.h
Log:
(1) Added local birth method based on energy used.
(2) Added put and combined put/repro instructions that reset the inputs in the organism's cell to newly randomized values.
(3) Changed some terminology in trace files from "AgedTime" to "EnergyUsed"



Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/cpu/cHardwareCPU.cc	2007-02-15 15:08:27 UTC (rev 1325)
@@ -233,7 +233,8 @@
     cInstEntryCPU("stk-get",   &cHardwareCPU::Inst_TaskStackGet),
     cInstEntryCPU("stk-load",  &cHardwareCPU::Inst_TaskStackLoad),
     cInstEntryCPU("put",       &cHardwareCPU::Inst_TaskPut),
-    cInstEntryCPU("put-clear", &cHardwareCPU::Inst_TaskPutClearInput),    
+    cInstEntryCPU("put-clear", &cHardwareCPU::Inst_TaskPutClearInput), 
+    cInstEntryCPU("put-reset", &cHardwareCPU::Inst_TaskPutResetInputs), 
     cInstEntryCPU("put-bcost2", &cHardwareCPU::Inst_TaskPutBonusCost2),
     cInstEntryCPU("put-mcost2", &cHardwareCPU::Inst_TaskPutMeritCost2),
     cInstEntryCPU("IO",        &cHardwareCPU::Inst_TaskIO, true,
@@ -373,8 +374,9 @@
     cInstEntryCPU("repro-Z",    &cHardwareCPU::Inst_Repro),
 
     cInstEntryCPU("IO-repro",   &cHardwareCPU::Inst_IORepro),
-    cInstEntryCPU("put-repro",  &cHardwareCPU::Inst_PutRepro),
-    cInstEntryCPU("putc-repro", &cHardwareCPU::Inst_PutClearRepro),
+    cInstEntryCPU("put-repro",  &cHardwareCPU::Inst_TaskPutRepro),
+    cInstEntryCPU("putc-repro", &cHardwareCPU::Inst_TaskPutClearInputRepro),
+    cInstEntryCPU("metabolize", &cHardwareCPU::Inst_TaskPutResetInputsRepro),        
 
     cInstEntryCPU("spawn-deme", &cHardwareCPU::Inst_SpawnDeme),
     
@@ -675,7 +677,7 @@
   // leave this out if there are no differences to keep it cleaner
   if ( organism->GetPhenotype().GetTimeUsed() != organism->GetPhenotype().GetCPUCyclesUsed() )
   {
-    fp << "  AgedTime:" << organism->GetPhenotype().GetTimeUsed();
+    fp << "  EnergyUsed:" << organism->GetPhenotype().GetTimeUsed();
   }
   fp << endl;
   
@@ -2557,7 +2559,7 @@
   return Inst_Repro(ctx);
 }
 
-bool cHardwareCPU::Inst_PutRepro(cAvidaContext& ctx)
+bool cHardwareCPU::Inst_TaskPutRepro(cAvidaContext& ctx)
 {
   // Do normal IO
   Inst_TaskPut(ctx);
@@ -2566,7 +2568,7 @@
   return Inst_Repro(ctx);
 }
 
-bool cHardwareCPU::Inst_PutClearRepro(cAvidaContext& ctx)
+bool cHardwareCPU::Inst_TaskPutClearInputRepro(cAvidaContext& ctx)
 {
   // Do normal IO
   Inst_TaskPutClearInput(ctx);
@@ -2575,7 +2577,18 @@
   return Inst_Repro(ctx);
 }
 
+bool cHardwareCPU::Inst_TaskPutResetInputsRepro(cAvidaContext& ctx)
+{
+  // Do normal IO
+  bool return_value = Inst_TaskPutResetInputs(ctx);
+  
+  // Immediately attempt a repro
+  Inst_Repro(ctx);
 
+  // return value of put since successful repro would wipe state anyway
+  return return_value; 
+}
+
 bool cHardwareCPU::Inst_SpawnDeme(cAvidaContext& ctx)
 {
   organism->SpawnDeme();
@@ -2767,6 +2780,13 @@
   return return_value;
 }
 
+bool cHardwareCPU::Inst_TaskPutResetInputs(cAvidaContext& ctx)
+{
+  bool return_value = Inst_TaskPut(ctx);          // Do a normal put
+  organism->GetOrgInterface().ResetInputs(ctx);   // Now re-randomize the inputs this organism sees
+  return return_value;
+}
+
 bool cHardwareCPU::Inst_TaskPutBonusCost2(cAvidaContext& ctx)
 {
   const int reg_used = FindModifiedRegister(REG_BX);

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/cpu/cHardwareCPU.h	2007-02-15 15:08:27 UTC (rev 1325)
@@ -397,8 +397,9 @@
   bool Inst_Transposon(cAvidaContext& ctx);
   bool Inst_Repro(cAvidaContext& ctx);
   bool Inst_IORepro(cAvidaContext& ctx);
-  bool Inst_PutRepro(cAvidaContext& ctx);
-  bool Inst_PutClearRepro(cAvidaContext& ctx);
+  bool Inst_TaskPutRepro(cAvidaContext& ctx);
+  bool Inst_TaskPutClearInputRepro(cAvidaContext& ctx);
+  bool Inst_TaskPutResetInputsRepro(cAvidaContext& ctx);
 
   bool Inst_SpawnDeme(cAvidaContext& ctx);
   bool Inst_Kazi(cAvidaContext& ctx);
@@ -411,6 +412,7 @@
   bool Inst_TaskStackLoad(cAvidaContext& ctx);
   bool Inst_TaskPut(cAvidaContext& ctx);
   bool Inst_TaskPutClearInput(cAvidaContext& ctx);  
+  bool Inst_TaskPutResetInputs(cAvidaContext& ctx);  
   bool Inst_TaskPutBonusCost2(cAvidaContext& ctx);  
   bool Inst_TaskPutMeritCost2(cAvidaContext& ctx); 
   bool Inst_TaskIO(cAvidaContext& ctx);

Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/cpu/cHardwareExperimental.cc	2007-02-15 15:08:27 UTC (rev 1325)
@@ -458,7 +458,7 @@
   // leave this out if there are no differences to keep it cleaner
   if ( organism->GetPhenotype().GetTimeUsed() != organism->GetPhenotype().GetCPUCyclesUsed() )
   {
-    fp << "  AgedTime:" << organism->GetPhenotype().GetTimeUsed();
+    fp << "  EnergyUsed:" << organism->GetPhenotype().GetTimeUsed();
   }
   fp << endl;
   

Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/cpu/cTestCPU.cc	2007-02-15 15:08:27 UTC (rev 1325)
@@ -302,8 +302,9 @@
   assert(cur_depth < test_info.generation_tests);
 
   // Input sizes can vary based on environment settings, must at least initialize
-  m_world->GetEnvironment().SetupInputs(ctx, input_array, test_info.GetUseRandomInputs());
-
+  m_use_random_inputs = test_info.GetUseRandomInputs(); // save this value in case ResetInputs is used.
+  m_world->GetEnvironment().SetupInputs(ctx, input_array, m_use_random_inputs);
+  
   receive_array.Resize(3);
   if (test_info.GetUseRandomInputs()) {
     receive_array[0] = (15 << 24) + ctx.GetRandom().GetUInt(1 << 24);  // 00001111
@@ -497,3 +498,9 @@
   m_world->GetDataFileManager().Remove(filename);
 }
 
+
+void cTestCPU::ResetInputs(cAvidaContext& ctx) 
+{ 
+  m_world->GetEnvironment().SetupInputs(ctx, input_array, m_use_random_inputs);
+}
+

Modified: development/source/cpu/cTestCPU.h
===================================================================
--- development/source/cpu/cTestCPU.h	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/cpu/cTestCPU.h	2007-02-15 15:08:27 UTC (rev 1325)
@@ -66,6 +66,7 @@
   tArray<int> receive_array;
   int cur_input;
   int cur_receive;  
+  bool m_use_random_inputs;
 
   eTestCPUResourceMethod m_res_method;
   std::vector<std::pair<int, std::vector<double> > > * m_res;
@@ -97,6 +98,8 @@
 
   inline int GetInput();
   inline int GetInputAt(int & input_pointer);
+  void ResetInputs(cAvidaContext& ctx);
+
   inline int GetReceiveValue();
   inline const tArray<double>& GetResources();  
   inline void SetResource(int id, double new_level);

Modified: development/source/cpu/cTestCPUInterface.cc
===================================================================
--- development/source/cpu/cTestCPUInterface.cc	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/cpu/cTestCPUInterface.cc	2007-02-15 15:08:27 UTC (rev 1325)
@@ -55,6 +55,11 @@
   return m_testcpu->GetInputAt(input_pointer);
 }
 
+void cTestCPUInterface::ResetInputs(cAvidaContext& ctx)
+{ 
+  m_testcpu->ResetInputs(ctx); 
+}
+
 int cTestCPUInterface::Debug()
 {
   return -1;

Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/cpu/cTestCPUInterface.h	2007-02-15 15:08:27 UTC (rev 1325)
@@ -53,6 +53,7 @@
   void Rotate(int direction = 1);
   void Breakpoint() { ; }
   int GetInputAt(int& input_pointer);
+  void ResetInputs(cAvidaContext& ctx);
   int Debug();
   const tArray<double>& GetResources();
   void UpdateResources(const tArray<double>& res_change);

Modified: development/source/defs.h
===================================================================
--- development/source/defs.h	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/defs.h	2007-02-15 15:08:27 UTC (rev 1325)
@@ -140,7 +140,8 @@
   POSITION_CHILD_DEME_RANDOM,
   POSITION_CHILD_PARENT_FACING,
   POSITION_CHILD_NEXT_CELL,
-  POSITION_CHILD_FULL_SOUP_TIME_USED
+  POSITION_CHILD_FULL_SOUP_ENERGY_USED,
+  POSITION_CHILD_NEIGHBORHOOD_ENERGY_USED
 };
 const int NUM_LOCAL_POSITION_CHILD = POSITION_CHILD_FULL_SOUP_RANDOM;
 

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/main/cAvidaConfig.h	2007-02-15 15:08:27 UTC (rev 1325)
@@ -208,7 +208,7 @@
   CONFIG_ADD_VAR(START_CREATURE, cString, "default-classic.org", "Organism to seed the soup");
   
   CONFIG_ADD_GROUP(REPRODUCTION_GROUP, "Birth and Death");
-  CONFIG_ADD_VAR(BIRTH_METHOD, int, 0, "Which organism should be replaced on birth?\n0 = Random organism in neighborhood\n1 = Oldest in neighborhood\n2 = Largest Age/Merit in neighborhood\n3 = None (use only empty cells in neighborhood)\n4 = Random from population (Mass Action)\n5 = Oldest in entire population\n6 = Random within deme\n7 = Organism faced by parent\n8 = Next grid cell (id+1)\n9= Max time used in entire population");
+  CONFIG_ADD_VAR(BIRTH_METHOD, int, 0, "Which organism should be replaced on birth?\n0 = Random organism in neighborhood\n1 = Oldest in neighborhood\n2 = Largest Age/Merit in neighborhood\n3 = None (use only empty cells in neighborhood)\n4 = Random from population (Mass Action)\n5 = Oldest in entire population\n6 = Random within deme\n7 = Organism faced by parent\n8 = Next grid cell (id+1)\n9= Largest energy used in entire population\n10= Largest energy used in neighborhood");
   CONFIG_ADD_VAR(PREFER_EMPTY, int, 1, "Give empty cells preference in offsping placement?");
   CONFIG_ADD_VAR(DEATH_METHOD, int, 2, "0 = Never die of old age.\n1 = Die when inst executed = AGE_LIMIT (+deviation)\n2 = Die when inst executed = length*AGE_LIMIT (+dev)");
   CONFIG_ADD_VAR(AGE_LIMIT, int, 20, "Modifies DEATH_METHOD");

Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/main/cOrgInterface.h	2007-02-15 15:08:27 UTC (rev 1325)
@@ -61,6 +61,7 @@
   virtual void Rotate(int direction = 1) = 0;
   virtual void Breakpoint() = 0;
   virtual int GetInputAt(int& input_pointer) = 0;
+  virtual void ResetInputs(cAvidaContext& ctx) = 0;
   virtual int Debug() = 0;
   virtual const tArray<double>& GetResources() = 0;
   virtual void UpdateResources(const tArray<double>& res_change) = 0;

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/main/cPopulation.cc	2007-02-15 15:08:27 UTC (rev 1325)
@@ -1308,7 +1308,7 @@
     if (out_cell_id == cell_array.GetSize()) out_cell_id = 0;
     return GetCell(out_cell_id);
   }
-  else if (birth_method == POSITION_CHILD_FULL_SOUP_TIME_USED) {
+  else if (birth_method == POSITION_CHILD_FULL_SOUP_ENERGY_USED) {
     tList<cPopulationCell> found_list;
     int max_time_used = 0;
     for  (int i=0; i < cell_array.GetSize(); i++)
@@ -1329,7 +1329,6 @@
     return *( found_list.GetPos(choice) );
   }
   
-  
   // All remaining methods require us to choose among mulitple local positions.
   
   // Construct a list of equally viable locations to place the child...
@@ -1360,6 +1359,8 @@
         found_list.Append(conn_list);
         if (parent_ok == true) found_list.Push(&parent_cell);
           break;
+      case POSITION_CHILD_NEIGHBORHOOD_ENERGY_USED:
+        PositionEnergyUsed(parent_cell, found_list, parent_ok);
       case POSITION_CHILD_EMPTY:
         // Nothing is in list if no empty cells are found...
         break;
@@ -2147,6 +2148,34 @@
   }
 }
 
+void cPopulation::PositionEnergyUsed(cPopulationCell & parent_cell,
+                                tList<cPopulationCell> & found_list,
+                                bool parent_ok)
+{
+  // Start with the parent organism as the replacement, and see if we can find
+  // anything equivilent or better.
+  
+  found_list.Push(&parent_cell);
+  int max_energy_used = parent_cell.GetOrganism()->GetPhenotype().GetTimeUsed();
+  if (parent_ok == false) max_energy_used = -1;
+  
+  // Now look at all of the neighbors.
+  tListIterator<cPopulationCell> conn_it( parent_cell.ConnectionList() );
+  
+  cPopulationCell * test_cell;
+  while ( (test_cell = conn_it.Next()) != NULL) {
+    const int cur_energy_used = test_cell->GetOrganism()->GetPhenotype().GetTimeUsed();
+    if (cur_energy_used > max_energy_used) {
+      max_energy_used = cur_energy_used;
+      found_list.Clear();
+      found_list.Push(test_cell);
+    }
+    else if (cur_energy_used == max_energy_used) {
+      found_list.Push(test_cell);
+    }
+  }
+}
+
 void cPopulation::FindEmptyCell(tList<cPopulationCell> & cell_list,
                                 tList<cPopulationCell> & found_list)
 {

Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/main/cPopulation.h	2007-02-15 15:08:27 UTC (rev 1325)
@@ -94,7 +94,7 @@
   tList<cPopulationCell> reaper_queue; // Death order in some mass-action runs
 
   // Default organism setups...
-  cEnvironment & environment;          // Physics & Chemestry description
+  cEnvironment & environment;          // Physics & Chemistry description
 
   // Other data...
   int world_x;                         // Structured population width.
@@ -112,6 +112,7 @@
   cPopulationCell& PositionChild(cPopulationCell& parent_cell, bool parent_ok = true);
   void PositionAge(cPopulationCell& parent_cell, tList<cPopulationCell>& found_list, bool parent_ok);
   void PositionMerit(cPopulationCell & parent_cell, tList<cPopulationCell>& found_list, bool parent_ok);
+  void PositionEnergyUsed(cPopulationCell & parent_cell, tList<cPopulationCell>& found_list, bool parent_ok);
   void FindEmptyCell(tList<cPopulationCell>& cell_list, tList<cPopulationCell>& found_list);
 
   // Update statistics collecting...
@@ -123,7 +124,7 @@
 
   /**
    * Attention: InjectGenotype does *not* add the genotype to the archive.
-   * It assumes thats where you got the genotype from.
+   * It assumes that's where you got the genotype from.
    **/
   void InjectGenotype(int cell_id, cGenotype* genotype);
   void InjectGenome(int cell_id, const cGenome& genome, int lineage_label);

Modified: development/source/main/cPopulationCell.cc
===================================================================
--- development/source/main/cPopulationCell.cc	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/main/cPopulationCell.cc	2007-02-15 15:08:27 UTC (rev 1325)
@@ -28,6 +28,9 @@
 #include "nHardware.h"
 #include "cOrganism.h"
 #include "cTools.h"
+#include "cTools.h"
+#include "cWorld.h"
+#include "cEnvironment.h"
 
 using namespace std;
 
@@ -115,6 +118,12 @@
   return input_array[id];
 }
 
+void cPopulationCell::ResetInputs(cAvidaContext& ctx) 
+{ 
+  m_world->GetEnvironment().SetupInputs(ctx, input_array); 
+}
+
+
 void cPopulationCell::InsertOrganism(cOrganism & new_org)
 {
   assert(&new_org != NULL);

Modified: development/source/main/cPopulationCell.h
===================================================================
--- development/source/main/cPopulationCell.h	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/main/cPopulationCell.h	2007-02-15 15:08:27 UTC (rev 1325)
@@ -80,6 +80,7 @@
   int GetInput(int);
   int GetInputAt(int & input_pointer);
   int GetInputSize() { return input_array.GetSize(); }
+  void ResetInputs(cAvidaContext& ctx);
 
   int GetID() const { return cell_id; }
   int GetDemeID() const { return deme_id; }

Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/main/cPopulationInterface.cc	2007-02-15 15:08:27 UTC (rev 1325)
@@ -80,6 +80,11 @@
   return cell.GetInputAt(input_pointer);
 }
 
+void cPopulationInterface::ResetInputs(cAvidaContext& ctx) 
+{ 
+  m_world->GetPopulation().GetCell(m_cell_id).ResetInputs(ctx); 
+}
+
 int cPopulationInterface::Debug()
 {
   cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);

Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h	2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/main/cPopulationInterface.h	2007-02-15 15:08:27 UTC (rev 1325)
@@ -62,6 +62,7 @@
   void Rotate(int direction = 1);
   void Breakpoint() { m_world->GetDriver().SignalBreakpoint(); }
   int GetInputAt(int& input_pointer);
+  void ResetInputs(cAvidaContext& ctx);
   int Debug();
   const tArray<double>& GetResources();
   void UpdateResources(const tArray<double>& res_change);




More information about the Avida-cvs mailing list