[Avida-SVN] r2373 - in development: source/actions source/main support/config

welsberr at myxo.css.msu.edu welsberr at myxo.css.msu.edu
Mon Feb 25 02:01:29 PST 2008


Author: welsberr
Date: 2008-02-25 05:01:29 -0500 (Mon, 25 Feb 2008)
New Revision: 2373

Modified:
   development/source/actions/PrintActions.cc
   development/source/main/cAvidaConfig.h
   development/source/main/cPopulation.cc
   development/source/main/cPopulationCell.h
   development/source/main/cStats.cc
   development/source/main/cStats.h
   development/source/main/cTaskLib.cc
   development/source/main/cTaskLib.h
   development/support/config/avida.cfg
Log:
Adding changes for movement experiments.


Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2008-02-25 03:22:08 UTC (rev 2372)
+++ development/source/actions/PrintActions.cc	2008-02-25 10:01:29 UTC (rev 2373)
@@ -96,6 +96,8 @@
 STATS_OUT_FILE(PrintCompetitionData,        competition.dat     );
 STATS_OUT_FILE(PrintDemeReplicationData,    deme_repl.dat       );
 STATS_OUT_FILE(PrintGermlineData,           germline.dat        );
+// @WRE: Added output event for collected visit counts
+STATS_OUT_FILE(PrintCellVisitsData,         visits.dat			);
 
 
 #define POP_OUT_FILE(METHOD, DEFAULT)                                                     /*  1 */ \
@@ -2636,6 +2638,9 @@
   action_lib->Register<cActionPrintSenseExeData>("PrintSenseExeData");
   action_lib->Register<cActionPrintSleepData>("PrintSleepData");
   action_lib->Register<cActionPrintCompetitionData>("PrintCompetitionData");
+  
+  // @WRE: Added printing of visit data
+  action_lib->Register<cActionPrintCellVisitsData>("PrintCellVisitsData");
 
   // Population Out Files
   action_lib->Register<cActionPrintPhenotypeData>("PrintPhenotypeData");

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2008-02-25 03:22:08 UTC (rev 2372)
+++ development/source/main/cAvidaConfig.h	2008-02-25 10:01:29 UTC (rev 2373)
@@ -507,9 +507,11 @@
   CONFIG_ADD_GROUP(BIOMIMETIC_GROUP, "Biomimetic Features Settings");
   CONFIG_ADD_VAR(BIOMIMETIC_REFRACTORY_PERIOD, double, 0.0, "Number of updates affected by refractory period");
   CONFIG_ADD_VAR(BIOMIMETIC_MOVEMENT_STEP, int, 0, "Number of cells to move Avidian on move instruction");
+  CONFIG_ADD_VAR(BIOMIMETIC_MOVEMENT_LOG, int, 0, "Log detailed movement information (WARNING: large data file)");
+  CONFIG_ADD_VAR(BIOMIMETIC_MOVEMENT_FACTOR, double, 1.0, "Scale merit bonus due to movement (m<1.0 applies a cost)");
+  CONFIG_ADD_VAR(BIOMIMETIC_EVAL_ON_MOVEMENT, int, 0, "Force task evaluation on each movement step");
   CONFIG_ADD_VAR(BIOMIMETIC_K, int, 0, "Carrying capacity in number of organisms");
   
-  
   CONFIG_ADD_CUSTOM_FORMAT(INST_SET_NEW, "Instruction Set Definition");
   CONFIG_ADD_FORMAT_VAR(INST, "Instruction entry in the instruction set");
   

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2008-02-25 03:22:08 UTC (rev 2372)
+++ development/source/main/cPopulation.cc	2008-02-25 10:01:29 UTC (rev 2373)
@@ -809,30 +809,35 @@
 {
   // Sanity checks: Don't process if the cells are the same and 
   // don't bother trying to move when given a cell that isn't there
-  //cout << "SwapCells: testing if cell1 and cell2 are non-null" << endl;
-  //if (!(NULL != cell1) || !(NULL != cell2)) return;
   if ((&cell1 == NULL) || (&cell2 == NULL)) return;
-  //cout << "SwapCells: testing if cell1 and cell2 are different" << endl;  
   if (cell1.GetID() == cell2.GetID()) return;
   // Clear current contents of cells
-  //cout << "SwapCells: clearing cell contents" << endl;
   cOrganism * org1 = cell1.RemoveOrganism();
   cOrganism * org2 = cell2.RemoveOrganism();
-  //cout << "SwapCells: organism 2 is non-null, fix up source cell" << endl;
   if (org2 != NULL) {
     cell1.InsertOrganism(org2);
     schedule->Adjust(cell1.GetID(), org2->GetPhenotype().GetMerit(),cell1.GetDemeID());
   } else {
     schedule->Adjust(cell1.GetID(), cMerit(0), cell1.GetDemeID());
   }
-  //cout << "SwapCells: organism 1 is non-null, fix up dest cell" << endl;
   if (org1 != NULL) {
     cell2.InsertOrganism(org1);
+    // Increment visit count
+    cell2.IncVisits();
+    // Adjust for movement factor if needed
+    if (1.0 != m_world->GetConfig().BIOMIMETIC_MOVEMENT_FACTOR.Get()) {
+      double afterfit = org1->GetPhenotype().GetCurBonus() * m_world->GetConfig().BIOMIMETIC_MOVEMENT_FACTOR.Get();
+      org1->GetPhenotype().SetCurBonus(afterfit); //Update fitness
+    }
+    // Trigger evaluation for task completion
+    if (0 < m_world->GetConfig().BIOMIMETIC_EVAL_ON_MOVEMENT.Get()) {
+      cAvidaContext& ctx = m_world->GetDefaultContext();
+      org1->DoOutput(ctx,0);
+    }
     schedule->Adjust(cell2.GetID(), org1->GetPhenotype().GetMerit(), cell2.GetDemeID());
   } else {
     schedule->Adjust(cell2.GetID(), cMerit(0), cell2.GetDemeID());
   }
-  //cout << "SwapCells: Done." << endl;
 }
 
 // CompeteDemes  probabilistically copies demes into the next generation
@@ -2105,6 +2110,36 @@
   
   const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
 
+  // @WRE carrying capacity handling
+  /* Pick and kill an organism here if needed
+   * and then enter choices for birth method handling.
+   */
+  if ((0 < m_world->GetConfig().BIOMIMETIC_K.Get()) &&
+      (num_organisms >= m_world->GetConfig().BIOMIMETIC_K.Get())) {
+    // Measure temporary variables
+    double max_msr = 0.0;
+    double msr = 0.0;
+    int max_msrndx = 0;
+    for  (int i=0; i < cell_array.GetSize(); i++) {
+      if (cell_array[i].IsOccupied()) {
+	if (cell_array[i].GetOrganism()->GetPhenotype().OK()) {
+	  // Get measurement, exclude parent
+	  if (parent_cell.GetID() != cell_array[i].GetID()) {
+	    msr = random();
+	  } else {
+	    msr = 0.0;
+	  }
+
+	  if (max_msr < msr) {
+	    max_msr = msr;
+	    max_msrndx = i;
+	  }
+	}
+      }
+    }
+    KillOrganism(cell_array[max_msrndx]);
+  }
+
   //@AWC -- decide wether the child will migrate to another deme -- if migrating we ignore the birth method.  
   if ((m_world->GetConfig().MIGRATION_RATE.Get() > 0.0) //@AWC -- Pedantic test to maintain consistancy.
       && m_world->GetRandom().P(m_world->GetConfig().MIGRATION_RATE.Get())){
@@ -2336,12 +2371,6 @@
 
 void cPopulation::UpdateOrganismStats()
 {
-  // Carrying capacity @WRE 04-20-07
-  // Check for positive non-zero carrying capacity and apply it
-  if (0 < m_world->GetConfig().BIOMIMETIC_K.Get()) {
-    SerialTransfer(m_world->GetConfig().BIOMIMETIC_K.Get(),true);
-  }
-
   // Loop through all the cells getting stats and doing calculations
   // which must be done on a creature by creature basis.
   

Modified: development/source/main/cPopulationCell.h
===================================================================
--- development/source/main/cPopulationCell.h	2008-02-25 03:22:08 UTC (rev 2372)
+++ development/source/main/cPopulationCell.h	2008-02-25 10:01:29 UTC (rev 2373)
@@ -69,6 +69,8 @@
   int m_x; //!< The x-coordinate of the position of this cell in the environment.
   int m_y; //!< The y-coordinate of the position of this cell in the environment.
 
+  // @WRE: Statistic for movement  
+  int m_visits; // The number of times Avidians move into the cell
   
   void InsertOrganism(cOrganism* new_org);
   cOrganism* RemoveOrganism();
@@ -85,7 +87,7 @@
   void SetDemeID(int in_id) { m_deme_id = in_id; }
   void Rotate(cPopulationCell& new_facing);
 
-  //@AWC -- This is, admittatidly, a hack to get migration between demes working under local copy...
+  //@AWC -- This is, admittedly, a hack to get migration between demes working under local copy...
   void SetMigrant() {m_migrant = true;} //@AWC -- this cell will contain a migrant genome
   void UnsetMigrant() {m_migrant = false;} //@AWC -- unset the migrant flag
   bool IsMigrant() {return m_migrant;} //@AWC -- does this contain a migrant genome?
@@ -96,6 +98,8 @@
   inline cPopulationCell& GetCellFaced() { return *(m_connections.GetFirst()); }
   int GetFacing();  // Returns the facing of this cell.
   inline void GetPosition(int& x, int& y) { x = m_x; y = m_y; } // Retrieves the position (x,y) coordinates of this cell.
+  inline int GetVisits() { return m_visits; } // @WRE: Retrieves the number of visits for this cell.
+  inline void IncVisits() { m_visits++; } // @WRE: Increments the visit count for a cell
   inline const cMutationRates& MutationRates() const { assert(m_mut_rates); return *m_mut_rates; }
   inline cMutationRates& MutationRates() { assert(m_mut_rates); return *m_mut_rates; }
   

Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc	2008-02-25 03:22:08 UTC (rev 2372)
+++ development/source/main/cStats.cc	2008-02-25 10:01:29 UTC (rev 2373)
@@ -949,7 +949,28 @@
   df.Flush();
 }
 
+// @WRE: Added method for printing out visit data
+void cStats::PrintCellVisitsData(const cString& filename)
+{
+  // Write cell visits data to a file that can easily be read into Matlab
 
+  cString tmpfilename = "visits.m";
+  cDataFile& df = m_world->GetDataFile(tmpfilename);
+  cString UpdateStr = cStringUtil::Stringf( "visits%07i", GetUpdate() ) + " = [ ...";
+
+  df.WriteRaw(UpdateStr);
+
+  int xsize = m_world->GetConfig().WORLD_X.Get();
+  
+  for(int i=0; i<m_world->GetPopulation().GetSize(); ++i) {
+    df.WriteBlockElement(m_world->GetPopulation().GetCell(i).GetVisits(), i, xsize);
+  }
+
+  df.WriteRaw("];");
+  df.Flush();
+}
+
+
 void cStats::PrintTimeData(const cString& filename)
 {
   cDataFile& df = m_world->GetDataFile(filename);

Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h	2008-02-25 03:22:08 UTC (rev 2372)
+++ development/source/main/cStats.h	2008-02-25 10:01:29 UTC (rev 2373)
@@ -655,6 +655,8 @@
   void PrintSenseExeData(const cString& filename);
   void PrintSleepData(const cString& filename);
   void PrintCompetitionData(const cString& filename);
+  // @WRE: Added event for printing visit counts
+  void PrintCellVisitsData(const cString& filename);
 
   // -------- Messaging support --------
 public:

Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc	2008-02-25 03:22:08 UTC (rev 2372)
+++ development/source/main/cTaskLib.cc	2008-02-25 10:01:29 UTC (rev 2373)
@@ -79,6 +79,8 @@
   else if (name == "add")  NewTask(name, "Add",  &cTaskLib::Task_Add);
   else if (name == "add3")  NewTask(name, "Add3",  &cTaskLib::Task_Add3);  
   else if (name == "sub")  NewTask(name, "Sub",  &cTaskLib::Task_Sub);
+  // @WRE DontCare task always succeeds.
+  else if (name == "dontcare")  NewTask(name, "DontCare", &cTaskLib::Task_DontCare);
   
   // All 1- and 2-Input Logic Functions
   if (name == "not") NewTask(name, "Not", &cTaskLib::Task_Not);
@@ -548,6 +550,12 @@
   return 0.0;
 }
 
+// @WRE DontCare task always succeeds.
+double cTaskLib::Task_DontCare(cTaskContext& ctx) const
+{
+  return 1.0;
+}
+
 double cTaskLib::Task_Not(cTaskContext& ctx) const
 {
   const int logic_id = ctx.GetLogicId();

Modified: development/source/main/cTaskLib.h
===================================================================
--- development/source/main/cTaskLib.h	2008-02-25 03:22:08 UTC (rev 2372)
+++ development/source/main/cTaskLib.h	2008-02-25 10:01:29 UTC (rev 2373)
@@ -97,6 +97,7 @@
   double Task_Add(cTaskContext& ctx) const;
   double Task_Add3(cTaskContext& ctx) const;
   double Task_Sub(cTaskContext& ctx) const;
+  double Task_DontCare(cTaskContext& ctx) const;
 
   // All 1- and 2-Input Logic Functions
   double Task_Not(cTaskContext& ctx) const;

Modified: development/support/config/avida.cfg
===================================================================
--- development/support/config/avida.cfg	2008-02-25 03:22:08 UTC (rev 2372)
+++ development/support/config/avida.cfg	2008-02-25 10:01:29 UTC (rev 2373)
@@ -360,4 +360,6 @@
 # Biomimetic Features Settings
 BIOMIMETIC_REFRACTORY_PERIOD 0.0  # Number of updates affected by refractory period
 BIOMIMETIC_MOVEMENT_STEP 0        # Number of cells to move Avidian on move instruction
+BIOMIMETIC_MOVEMENT_FACTOR 1.0    # Scale merit bonus due to movement (m<1.0 applies a cost)
+BIOMIMETIC_EVAL_ON_MOVEMENT 0     # Force task evaluation on each movement step
 BIOMIMETIC_K 0                    # Carrying capacity in number of organisms




More information about the Avida-cvs mailing list