[Avida-SVN] r2391 - in development/source: main tools

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Thu Feb 28 07:32:07 PST 2008


Author: dknoester
Date: 2008-02-28 10:32:07 -0500 (Thu, 28 Feb 2008)
New Revision: 2391

Modified:
   development/source/main/cDeme.cc
   development/source/main/cDeme.h
   development/source/main/cPopulation.cc
   development/source/tools/cConstSchedule.cc
   development/source/tools/cConstSchedule.h
   development/source/tools/cDemeProbSchedule.cc
   development/source/tools/cDemeProbSchedule.h
   development/source/tools/cIntegratedSchedule.cc
   development/source/tools/cIntegratedSchedule.h
   development/source/tools/cProbDemeProbSchedule.cc
   development/source/tools/cProbDemeProbSchedule.h
   development/source/tools/cProbSchedule.cc
   development/source/tools/cProbSchedule.h
   development/source/tools/cSchedule.h
Log:
Second of three commits for adding deme merit.  This one touches adds the scheduling component of deme merit, multiplying the merit of each organism by the merit of its deme.  Note that deme merit defaults to 1.

Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/main/cDeme.cc	2008-02-28 15:32:07 UTC (rev 2391)
@@ -29,13 +29,17 @@
 #include "cResource.h"
 #include "cWorld.h"
 
-void cDeme::Setup(const tArray<int> & in_cells, int in_width, cWorld* world)
+void cDeme::Setup(int id, const tArray<int> & in_cells, int in_width, cWorld* world)
 {
+  _id = id;
   cell_ids = in_cells;
   birth_count = 0;
   org_count = 0;
   m_world = world;
 
+  _current_merit = 1.0;
+  _next_merit = 1.0;
+  
   // If width is negative, set it to the full number of cells.
   width = in_width;
   if (width < 1) width = cell_ids.GetSize();
@@ -136,7 +140,7 @@
 */
 void cDeme::UpdateDemeMerit() {
   _current_merit = _next_merit;
-  _next_merit = 0;
+  _next_merit = 1.0;
 }
 
 
@@ -144,7 +148,7 @@
 */
 void cDeme::UpdateDemeMerit(cDeme& source) {
   _current_merit = source.GetHeritableDemeMerit();
-  _next_merit = 0;
+  _next_merit = 1.0;
 }
 
 

Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/main/cDeme.h	2008-02-28 15:32:07 UTC (rev 2391)
@@ -42,6 +42,7 @@
 {
 private:
   cWorld* m_world;
+  int _id; //!< ID of this deme (position in cPopulation::deme_array).
   tArray<int> cell_ids;
   int width; //!< Width of this deme.
   int birth_count; //!< Number of organisms that have been born into this deme since reset.
@@ -62,11 +63,12 @@
   cMerit _next_merit; //!< Deme merit that will be inherited upon deme replication.
   
 public:
-  cDeme() : width(0), birth_count(0), org_count(0), _age(0), total_org_energy(0.0), deme_resource_count(0) { ; }
+  cDeme() : _id(0), width(0), birth_count(0), org_count(0), _age(0), total_org_energy(0.0), deme_resource_count(0) { ; }
   ~cDeme() { ; }
 
-  void Setup(const tArray<int>& in_cells, int in_width = -1, cWorld* world = NULL);
+  void Setup(int id, const tArray<int>& in_cells, int in_width = -1, cWorld* world = NULL);
 
+  int GetID() const { return _id; }
   int GetSize() const { return cell_ids.GetSize(); }
   int GetCellID(int pos) const { return cell_ids[pos]; }
   int GetCellID(int x, int y) const;

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/main/cPopulation.cc	2008-02-28 15:32:07 UTC (rev 2391)
@@ -158,7 +158,7 @@
       deme_cells[offset] = cell_id;
       cell_array[cell_id].SetDemeID(deme_id);
     }
-    deme_array[deme_id].Setup(deme_cells, deme_size_x, m_world);
+    deme_array[deme_id].Setup(deme_id, deme_cells, deme_size_x, m_world);
   }
   
   // Setup the topology.
@@ -356,7 +356,7 @@
         delete test_cpu;
       }
     }
-    schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit(),parent_cell.GetDemeID());
+    schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit(), deme_array[parent_cell.GetDemeID()]);
     
     // In a local run, face the child toward the parent. 
     const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
@@ -489,7 +489,7 @@
   m_world->GetClassificationManager().AdjustGenotype(*in_genotype);
   
   // Initialize the time-slice for this new organism.
-  schedule->Adjust(target_cell.GetID(), in_organism->GetPhenotype().GetMerit(), target_cell.GetDemeID());
+  schedule->Adjust(target_cell.GetID(), in_organism->GetPhenotype().GetMerit(), deme_array[target_cell.GetDemeID()]);
   
   // Special handling for certain birth methods.
   if (m_world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST) {
@@ -677,7 +677,7 @@
   else organism->GetPhenotype().SetToDelete();
   
   // Alert the scheduler that this cell has a 0 merit.
-  schedule->Adjust(in_cell.GetID(), cMerit(0),in_cell.GetDemeID());
+  schedule->Adjust(in_cell.GetID(), cMerit(0), deme_array[in_cell.GetDemeID()]);
   
   // Update the archive (note: genotype adjustment may be defered)
   m_world->GetClassificationManager().AdjustGenotype(*genotype);
@@ -815,9 +815,9 @@
   cOrganism * org2 = cell2.RemoveOrganism();
   if (org2 != NULL) {
     cell1.InsertOrganism(org2);
-    schedule->Adjust(cell1.GetID(), org2->GetPhenotype().GetMerit(),cell1.GetDemeID());
+    schedule->Adjust(cell1.GetID(), org2->GetPhenotype().GetMerit(), deme_array[cell1.GetDemeID()]);
   } else {
-    schedule->Adjust(cell1.GetID(), cMerit(0), cell1.GetDemeID());
+    schedule->Adjust(cell1.GetID(), cMerit(0), deme_array[cell1.GetDemeID()]);
   }
   if (org1 != NULL) {
     cell2.InsertOrganism(org1);
@@ -833,9 +833,9 @@
       cAvidaContext& ctx = m_world->GetDefaultContext();
       org1->DoOutput(ctx,0);
     }
-    schedule->Adjust(cell2.GetID(), org1->GetPhenotype().GetMerit(), cell2.GetDemeID());
+    schedule->Adjust(cell2.GetID(), org1->GetPhenotype().GetMerit(), deme_array[cell2.GetDemeID()]);
   } else {
-    schedule->Adjust(cell2.GetID(), cMerit(0), cell2.GetDemeID());
+    schedule->Adjust(cell2.GetID(), cMerit(0), deme_array[cell2.GetDemeID()]);
   }
 }
 
@@ -2907,7 +2907,7 @@
         InjectGenotype( current_cell, (*it).genotype );
         cPhenotype & phenotype = GetCell(current_cell).GetOrganism()->GetPhenotype();
         if ( (*it).merit > 0) phenotype.SetMerit( cMerit((*it).merit) );
-        schedule->Adjust(current_cell, phenotype.GetMerit(), GetCell(current_cell).GetDemeID());
+        schedule->Adjust(current_cell, phenotype.GetMerit(), deme_array[GetCell(current_cell).GetDemeID()]);
         
         int lineage_label = 0;
         LineageSetupOrganism(GetCell(current_cell).GetOrganism(),
@@ -2997,7 +2997,7 @@
   phenotype.SetNeutralMetric(neutral);
     
   if (merit > 0) phenotype.SetMerit(cMerit(merit));
-  schedule->Adjust(cell_id, phenotype.GetMerit(), GetCell(cell_id).GetDemeID());
+  schedule->Adjust(cell_id, phenotype.GetMerit(), deme_array[GetCell(cell_id).GetDemeID()]);
   
   LineageSetupOrganism(GetCell(cell_id).GetOrganism(), 0, lineage_label);
   
@@ -3461,7 +3461,7 @@
   if (new_merit <= old_merit) {
 	  phenotype.SetIsDonorCur(); }  
   else  { phenotype.SetIsReceiver(); } 
-  schedule->Adjust(cell_id, phenotype.GetMerit(),GetCell(cell_id).GetDemeID());
+  schedule->Adjust(cell_id, phenotype.GetMerit(), deme_array[GetCell(cell_id).GetDemeID()]);
   
   return true;
 }

Modified: development/source/tools/cConstSchedule.cc
===================================================================
--- development/source/tools/cConstSchedule.cc	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/tools/cConstSchedule.cc	2008-02-28 15:32:07 UTC (rev 2391)
@@ -25,6 +25,7 @@
 
 #include "cConstSchedule.h"
 
+#include "cDeme.h"
 #include "cChangeList.h"
 #include "cMerit.h"
 
@@ -35,8 +36,13 @@
   return true;
 }
 
-void cConstSchedule::Adjust(int item_id, const cMerit & merit, int deme_id)
+void cConstSchedule::Adjust(int item_id, const cMerit & merit, const cDeme& deme)
 {
+  Adjust(item_id, merit);
+}
+
+void cConstSchedule::Adjust(int item_id, const cMerit & merit)
+{
   if (cChangeList *change_list = GetChangeList()) {
     change_list->MarkChange(item_id);
   }

Modified: development/source/tools/cConstSchedule.h
===================================================================
--- development/source/tools/cConstSchedule.h	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/tools/cConstSchedule.h	2008-02-28 15:32:07 UTC (rev 2391)
@@ -33,12 +33,12 @@
 #include "tArray.h"
 #endif
 
+class cDeme;
+class cMerit;
+
 /**
  * This class rotates between all items to schedule, giving each equal time.
  **/
-
-class cMerit;
-
 class cConstSchedule : public cSchedule
 {
 private:
@@ -58,8 +58,10 @@
   ~cConstSchedule() { ; }
 
   bool OK();
-  void Adjust(int item_id, const cMerit& merit, int deme_id);
 
+  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
+  virtual void Adjust(int item_id, const cMerit& merit);
+
   int GetNextID();
 };
 

Modified: development/source/tools/cDemeProbSchedule.cc
===================================================================
--- development/source/tools/cDemeProbSchedule.cc	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/tools/cDemeProbSchedule.cc	2008-02-28 15:32:07 UTC (rev 2391)
@@ -26,6 +26,7 @@
 #include "cDemeProbSchedule.h"
 
 #include "cChangeList.h"
+#include "cDeme.h"
 #include "cMerit.h"
 
 // The larger merits cause problems here; things need to be re-thought out. 
@@ -71,16 +72,25 @@
 
 
 //adjust the weight of an org within deme
-void cDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit, int deme_id)
+void cDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit, const cDeme& deme)
 {
+  int deme_id = deme.GetID();
+  
   //calculate the corrected id for the org to be adjusted
   int offset_id = item_id - (deme_id * deme_size);
-
+  
   //who the hell knows what this crap does -- "ineherited" from cProbScheduler
   if (cChangeList *change_list = GetChangeList()) {
     change_list->MarkChange(item_id);
   }
-
+  
   //adjust the merit of the org in the tree
   chart[deme_id]->SetWeight(offset_id, item_merit.GetDouble());
 }
+
+
+//adjust the weight of an org within deme
+void cDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit)
+{
+  assert(false);
+}

Modified: development/source/tools/cDemeProbSchedule.h
===================================================================
--- development/source/tools/cDemeProbSchedule.h	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/tools/cDemeProbSchedule.h	2008-02-28 15:32:07 UTC (rev 2391)
@@ -83,7 +83,9 @@
   }
   ~cDemeProbSchedule() { for (int i = 0; i < chart.GetSize(); i++) delete chart[i]; }
 
-  void Adjust(int item_id, const cMerit& merit, int deme_id=0);
+  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
+  virtual void Adjust(int item_id, const cMerit& merit);
+
   int GetNextID();
 };
 

Modified: development/source/tools/cIntegratedSchedule.cc
===================================================================
--- development/source/tools/cIntegratedSchedule.cc	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/tools/cIntegratedSchedule.cc	2008-02-28 15:32:07 UTC (rev 2391)
@@ -25,6 +25,7 @@
 
 #include "cIntegratedSchedule.h"
 
+#include "cDeme.h"
 #include "cChangeList.h"
 #include "functions.h"
 #include "cIntegratedScheduleNode.h"
@@ -75,8 +76,12 @@
   return true;
 }
 
+void cIntegratedSchedule::Adjust(int item_id, const cMerit& new_merit, const cDeme& deme)
+{
+  Adjust(item_id, new_merit * deme.GetDemeMerit());
+}
 
-void cIntegratedSchedule::Adjust(int item_id, const cMerit & new_merit, int deme_id)
+void cIntegratedSchedule::Adjust(int item_id, const cMerit& new_merit)
 {
   if (cChangeList *change_list = GetChangeList()) {
     change_list->MarkChange(item_id);

Modified: development/source/tools/cIntegratedSchedule.h
===================================================================
--- development/source/tools/cIntegratedSchedule.h	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/tools/cIntegratedSchedule.h	2008-02-28 15:32:07 UTC (rev 2391)
@@ -33,8 +33,12 @@
 #include "tArray.h"
 #endif
 
+class cDeme;
+class cIntegratedScheduleNode;
+class cMerit;
+
 /**
- * The cIntegratedSchedule method relies on breaking up all merits into
+* The cIntegratedSchedule method relies on breaking up all merits into
  * sums of powers of 2 (i.e. using the binary representation of the merit).
  * All items with merits in the highest power of two will get the most
  * time, and subsequent merit components will have time divided,
@@ -43,10 +47,6 @@
  * the best, and everything else (where in everything else we again alternate
  * with the best of this sub-list recursively).
  **/
-
-class cIntegratedScheduleNode;
-class cMerit;
-
 class cIntegratedSchedule : public cSchedule
 {
 private:
@@ -66,7 +66,9 @@
   cIntegratedSchedule(int _item_count);
   ~cIntegratedSchedule();
 
-  void Adjust(int item_id, const cMerit & new_merit,int deme_id);
+  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
+  virtual void Adjust(int item_id, const cMerit& merit);
+  
   int GetNextID();
   double GetStatus(int id);
 

Modified: development/source/tools/cProbDemeProbSchedule.cc
===================================================================
--- development/source/tools/cProbDemeProbSchedule.cc	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/tools/cProbDemeProbSchedule.cc	2008-02-28 15:32:07 UTC (rev 2391)
@@ -25,6 +25,7 @@
 
 #include "cProbDemeProbSchedule.h"
 
+#include "cDeme.h"
 #include "cChangeList.h"
 #include "cMerit.h"
 
@@ -56,8 +57,10 @@
 
 
 //adjust the weight of an org within deme -- adjust the weighting for scheduling that deme
-void cProbDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit, int deme_id)
+void cProbDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit, const cDeme& deme)
 {
+  int deme_id = deme.GetID();
+  
   //calculate the corrected id for the org to be adjusted
   int offset_id = item_id - (deme_id * deme_size);
 
@@ -81,3 +84,9 @@
   //adjust the merit of the org in the tree
   chart[deme_id]->SetWeight(offset_id, item_merit.GetDouble());
 }
+
+
+void cProbDemeProbSchedule::Adjust(int item_id, const cMerit& merit)
+{
+  assert(false);
+}

Modified: development/source/tools/cProbDemeProbSchedule.h
===================================================================
--- development/source/tools/cProbDemeProbSchedule.h	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/tools/cProbDemeProbSchedule.h	2008-02-28 15:32:07 UTC (rev 2391)
@@ -48,6 +48,7 @@
  * @AWC -- further implementation notes in CC file.
  **/
 
+class cDeme;
 class cMerit;
 
 class cProbDemeProbSchedule : public cSchedule
@@ -88,7 +89,9 @@
 
   ~cProbDemeProbSchedule() { for (int i = 0; i < chart.GetSize(); i++) delete chart[i]; }
 
-  void Adjust(int item_id, const cMerit& merit, int deme_id = 0);
+  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
+  virtual void Adjust(int item_id, const cMerit& merit);
+
   int GetNextID();
 };
 

Modified: development/source/tools/cProbSchedule.cc
===================================================================
--- development/source/tools/cProbSchedule.cc	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/tools/cProbSchedule.cc	2008-02-28 15:32:07 UTC (rev 2391)
@@ -26,6 +26,7 @@
 #include "cProbSchedule.h"
 
 #include "cChangeList.h"
+#include "cDeme.h"
 #include "cMerit.h"
 
 // The larger merits cause problems here; things need to be re-thought out.
@@ -37,8 +38,14 @@
   return chart.FindPosition(position);
 }
 
-void cProbSchedule::Adjust(int item_id, const cMerit& item_merit, int deme_id)
+void cProbSchedule::Adjust(int item_id, const cMerit& item_merit, const cDeme& deme)
 {
+  Adjust(item_id, item_merit * deme.GetDemeMerit());
+}
+
+
+void cProbSchedule::Adjust(int item_id, const cMerit& item_merit)
+{
   if (cChangeList *change_list = GetChangeList()) {
     change_list->MarkChange(item_id);
   }

Modified: development/source/tools/cProbSchedule.h
===================================================================
--- development/source/tools/cProbSchedule.h	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/tools/cProbSchedule.h	2008-02-28 15:32:07 UTC (rev 2391)
@@ -36,13 +36,13 @@
 #include "cWeightedIndex.h"
 #endif
 
+class cDeme;
+class cMerit;
+
 /**
  * The Probiblistic Schedule has the chance for an item to
  * be scheduled proportional to the merit of that item.
  **/
-
-class cMerit;
-
 class cProbSchedule : public cSchedule
 {
 private:
@@ -57,7 +57,9 @@
   cProbSchedule(int num_cells, int seed) : cSchedule(num_cells), m_rng(seed), chart(num_cells) { ; }
   ~cProbSchedule() { ; }
 
-  void Adjust(int item_id, const cMerit& merit, int deme_id);
+  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
+  virtual void Adjust(int item_id, const cMerit& merit);
+
   int GetNextID();
 };
 

Modified: development/source/tools/cSchedule.h
===================================================================
--- development/source/tools/cSchedule.h	2008-02-28 14:24:31 UTC (rev 2390)
+++ development/source/tools/cSchedule.h	2008-02-28 15:32:07 UTC (rev 2391)
@@ -32,16 +32,15 @@
 # endif
 #endif
 
+class cDeme;
+class cMerit;
+class cChangeList;
 
 /**
  * This class is the base object to handle time-slicing. All other schedulers
  * are derived from this class.  This is a virtual class.
  *
  **/
-
-class cMerit;
-class cChangeList;
-
 class cSchedule
 {
 #if USE_tMemTrack
@@ -61,7 +60,8 @@
   virtual ~cSchedule();
 
   virtual bool OK() { return true; }
-  virtual void Adjust(int item_id, const cMerit & merit, int deme_id=0) { ; }
+  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme) = 0;
+  virtual void Adjust(int item_id, const cMerit& merit) = 0;
   virtual int GetNextID() = 0;
   virtual double GetStatus(int id) { return 0.0; }
   void SetChangeList(cChangeList *change_list);




More information about the Avida-cvs mailing list