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

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Thu Feb 28 11:12:22 PST 2008


Author: brysonda
Date: 2008-02-28 14:12:22 -0500 (Thu, 28 Feb 2008)
New Revision: 2394

Modified:
   development/source/main/cDeme.h
   development/source/main/cPopulation.cc
   development/source/main/cPopulation.h
   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/cMerit.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:
Tools classes should NEVER depend on classes outside of tools.

Change deme merit calculation to be performed outside of the schedulers.  Also move scheduler calls into a single location in cPopulation for easier maintenance.

Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h	2008-02-28 18:31:51 UTC (rev 2393)
+++ development/source/main/cDeme.h	2008-02-28 19:12:22 UTC (rev 2394)
@@ -106,6 +106,8 @@
   const cMerit& GetDemeMerit() const { return _current_merit; }
   //! Retrieve this deme's heritable merit.
   const cMerit& GetHeritableDemeMerit() const { return _next_merit; }
+  
+  bool HasDemeMerit() const { return _current_merit.GetDouble() != 1.0; }
 
   // -= Update support =-
   //! Called once, at the end of every update.

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2008-02-28 18:31:51 UTC (rev 2393)
+++ development/source/main/cPopulation.cc	2008-02-28 19:12:22 UTC (rev 2394)
@@ -274,6 +274,15 @@
 }
 
 
+inline void cPopulation::AdjustSchedule(const cPopulationCell& cell, const cMerit& merit)
+{
+  const int deme_id = cell.GetDemeID();
+  const cDeme& deme = deme_array[deme_id];
+  schedule->Adjust(cell.GetID(), deme.HasDemeMerit() ? (merit * deme.GetDemeMerit()) : merit, cell.GetDemeID());
+}
+
+
+
 // Activate the child, given information from the parent.
 // Return true if parent lives through this process.
 
@@ -356,7 +365,7 @@
         delete test_cpu;
       }
     }
-    schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit(), deme_array[parent_cell.GetDemeID()]);
+    AdjustSchedule(parent_cell, parent_phenotype.GetMerit());
     
     // In a local run, face the child toward the parent. 
     const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
@@ -489,7 +498,7 @@
   m_world->GetClassificationManager().AdjustGenotype(*in_genotype);
   
   // Initialize the time-slice for this new organism.
-  schedule->Adjust(target_cell.GetID(), in_organism->GetPhenotype().GetMerit(), deme_array[target_cell.GetDemeID()]);
+  AdjustSchedule(target_cell, in_organism->GetPhenotype().GetMerit());
   
   // Special handling for certain birth methods.
   if (m_world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST) {
@@ -677,7 +686,7 @@
   else organism->GetPhenotype().SetToDelete();
   
   // Alert the scheduler that this cell has a 0 merit.
-  schedule->Adjust(in_cell.GetID(), cMerit(0), deme_array[in_cell.GetDemeID()]);
+  AdjustSchedule(in_cell, cMerit(0));
   
   // Update the archive (note: genotype adjustment may be defered)
   m_world->GetClassificationManager().AdjustGenotype(*genotype);
@@ -815,9 +824,9 @@
   cOrganism * org2 = cell2.RemoveOrganism();
   if (org2 != NULL) {
     cell1.InsertOrganism(org2);
-    schedule->Adjust(cell1.GetID(), org2->GetPhenotype().GetMerit(), deme_array[cell1.GetDemeID()]);
+    AdjustSchedule(cell1, org2->GetPhenotype().GetMerit());
   } else {
-    schedule->Adjust(cell1.GetID(), cMerit(0), deme_array[cell1.GetDemeID()]);
+    AdjustSchedule(cell1, cMerit(0));
   }
   if (org1 != NULL) {
     cell2.InsertOrganism(org1);
@@ -833,9 +842,9 @@
       cAvidaContext& ctx = m_world->GetDefaultContext();
       org1->DoOutput(ctx,0);
     }
-    schedule->Adjust(cell2.GetID(), org1->GetPhenotype().GetMerit(), deme_array[cell2.GetDemeID()]);
+    AdjustSchedule(cell2, org1->GetPhenotype().GetMerit());
   } else {
-    schedule->Adjust(cell2.GetID(), cMerit(0), deme_array[cell2.GetDemeID()]);
+    AdjustSchedule(cell2, cMerit(0));
   }
 }
 
@@ -2906,7 +2915,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(), deme_array[GetCell(current_cell).GetDemeID()]);
+        AdjustSchedule(GetCell(current_cell), phenotype.GetMerit());
         
         int lineage_label = 0;
         LineageSetupOrganism(GetCell(current_cell).GetOrganism(),
@@ -2996,7 +3005,7 @@
   phenotype.SetNeutralMetric(neutral);
     
   if (merit > 0) phenotype.SetMerit(cMerit(merit));
-  schedule->Adjust(cell_id, phenotype.GetMerit(), deme_array[GetCell(cell_id).GetDemeID()]);
+  AdjustSchedule(GetCell(cell_id), phenotype.GetMerit());
   
   LineageSetupOrganism(GetCell(cell_id).GetOrganism(), 0, lineage_label);
   
@@ -3460,7 +3469,7 @@
   if (new_merit <= old_merit) {
 	  phenotype.SetIsDonorCur(); }  
   else  { phenotype.SetIsReceiver(); } 
-  schedule->Adjust(cell_id, phenotype.GetMerit(), deme_array[GetCell(cell_id).GetDemeID()]);
+  AdjustSchedule(GetCell(cell_id), phenotype.GetMerit());
   
   return true;
 }

Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h	2008-02-28 18:31:51 UTC (rev 2393)
+++ development/source/main/cPopulation.h	2008-02-28 19:12:22 UTC (rev 2394)
@@ -143,6 +143,9 @@
 	
   // Must be called to activate *any* organism in the population.
   void ActivateOrganism(cAvidaContext& ctx, cOrganism* in_organism, cPopulationCell& target_cell);
+  
+  inline void AdjustSchedule(const cPopulationCell& cell, const cMerit& merit);
+  
 
   cPopulation(); // @not_implemented
   cPopulation(const cPopulation&); // @not_implemented

Modified: development/source/tools/cConstSchedule.cc
===================================================================
--- development/source/tools/cConstSchedule.cc	2008-02-28 18:31:51 UTC (rev 2393)
+++ development/source/tools/cConstSchedule.cc	2008-02-28 19:12:22 UTC (rev 2394)
@@ -36,13 +36,8 @@
   return true;
 }
 
-void cConstSchedule::Adjust(int item_id, const cMerit & merit, const cDeme& deme)
+void cConstSchedule::Adjust(int item_id, const cMerit& merit, int deme_id)
 {
-  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 18:31:51 UTC (rev 2393)
+++ development/source/tools/cConstSchedule.h	2008-02-28 19:12:22 UTC (rev 2394)
@@ -59,8 +59,7 @@
 
   bool OK();
 
-  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
-  virtual void Adjust(int item_id, const cMerit& merit);
+  virtual void Adjust(int item_id, const cMerit& merit, int deme_id = 0);
 
   int GetNextID();
 };

Modified: development/source/tools/cDemeProbSchedule.cc
===================================================================
--- development/source/tools/cDemeProbSchedule.cc	2008-02-28 18:31:51 UTC (rev 2393)
+++ development/source/tools/cDemeProbSchedule.cc	2008-02-28 19:12:22 UTC (rev 2394)
@@ -72,10 +72,8 @@
 
 
 //adjust the weight of an org within deme
-void cDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit, const cDeme& deme)
+void cDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit, int deme_id)
 {
-  int deme_id = deme.GetID();
-  
   //calculate the corrected id for the org to be adjusted
   int offset_id = item_id - (deme_id * deme_size);
   
@@ -88,9 +86,3 @@
   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 18:31:51 UTC (rev 2393)
+++ development/source/tools/cDemeProbSchedule.h	2008-02-28 19:12:22 UTC (rev 2394)
@@ -83,8 +83,7 @@
   }
   ~cDemeProbSchedule() { for (int i = 0; i < chart.GetSize(); i++) delete chart[i]; }
 
-  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
-  virtual void Adjust(int item_id, const cMerit& merit);
+  virtual void Adjust(int item_id, const cMerit& merit, int deme_id = 0);
 
   int GetNextID();
 };

Modified: development/source/tools/cIntegratedSchedule.cc
===================================================================
--- development/source/tools/cIntegratedSchedule.cc	2008-02-28 18:31:51 UTC (rev 2393)
+++ development/source/tools/cIntegratedSchedule.cc	2008-02-28 19:12:22 UTC (rev 2394)
@@ -76,13 +76,8 @@
   return true;
 }
 
-void cIntegratedSchedule::Adjust(int item_id, const cMerit& new_merit, const cDeme& deme)
+void cIntegratedSchedule::Adjust(int item_id, const cMerit& new_merit, int deme_id)
 {
-  Adjust(item_id, new_merit * deme.GetDemeMerit());
-}
-
-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 18:31:51 UTC (rev 2393)
+++ development/source/tools/cIntegratedSchedule.h	2008-02-28 19:12:22 UTC (rev 2394)
@@ -66,8 +66,7 @@
   cIntegratedSchedule(int _item_count);
   ~cIntegratedSchedule();
 
-  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
-  virtual void Adjust(int item_id, const cMerit& merit);
+  virtual void Adjust(int item_id, const cMerit& merit, int deme_id);
   
   int GetNextID();
   double GetStatus(int id);

Modified: development/source/tools/cMerit.h
===================================================================
--- development/source/tools/cMerit.h	2008-02-28 18:31:51 UTC (rev 2393)
+++ development/source/tools/cMerit.h	2008-02-28 19:12:22 UTC (rev 2394)
@@ -62,14 +62,18 @@
   }
 
   void operator=(double _merit) { UpdateValue(_merit); }
-  void operator+=(const cMerit & _m){ UpdateValue(value + _m.GetDouble()); }
+  
+  void operator+=(const cMerit & _m) { UpdateValue(value + _m.GetDouble()); }
   void operator+=(double _merit) { UpdateValue(value + _merit); }
+  
   cMerit operator*(const cMerit& _m) const { return cMerit(value * _m.GetDouble()); }
-  int  operator>(const cMerit & _m)  const { return value >  _m.GetDouble(); }
-  int  operator<(const cMerit & _m)  const { return value <  _m.GetDouble(); }
-  int  operator>=(const cMerit & _m) const { return value >= _m.GetDouble(); }
-  int  operator<=(const cMerit & _m) const { return value <= _m.GetDouble(); }
+  void operator*=(const cMerit& _m) { UpdateValue(value * _m.GetDouble()); }
 
+  int  operator>(const cMerit& _m)  const { return value >  _m.GetDouble(); }
+  int  operator<(const cMerit& _m)  const { return value <  _m.GetDouble(); }
+  int  operator>=(const cMerit& _m) const { return value >= _m.GetDouble(); }
+  int  operator<=(const cMerit& _m) const { return value <= _m.GetDouble(); }
+
   int  operator==(const cMerit & _m) const { return value == _m.GetDouble(); }
   int  operator==(const double _m) const { return value == _m; }
   int  operator==(const unsigned int _m)   const { return (offset==0 && base==_m); }

Modified: development/source/tools/cProbDemeProbSchedule.cc
===================================================================
--- development/source/tools/cProbDemeProbSchedule.cc	2008-02-28 18:31:51 UTC (rev 2393)
+++ development/source/tools/cProbDemeProbSchedule.cc	2008-02-28 19:12:22 UTC (rev 2394)
@@ -57,10 +57,8 @@
 
 
 //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, const cDeme& deme)
+void cProbDemeProbSchedule::Adjust(int item_id, const cMerit& item_merit, int deme_id)
 {
-  int deme_id = deme.GetID();
-  
   //calculate the corrected id for the org to be adjusted
   int offset_id = item_id - (deme_id * deme_size);
 
@@ -84,9 +82,3 @@
   //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 18:31:51 UTC (rev 2393)
+++ development/source/tools/cProbDemeProbSchedule.h	2008-02-28 19:12:22 UTC (rev 2394)
@@ -89,8 +89,7 @@
 
   ~cProbDemeProbSchedule() { for (int i = 0; i < chart.GetSize(); i++) delete chart[i]; }
 
-  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
-  virtual void Adjust(int item_id, const cMerit& merit);
+  virtual void Adjust(int item_id, const cMerit& merit, int deme_id = 0);
 
   int GetNextID();
 };

Modified: development/source/tools/cProbSchedule.cc
===================================================================
--- development/source/tools/cProbSchedule.cc	2008-02-28 18:31:51 UTC (rev 2393)
+++ development/source/tools/cProbSchedule.cc	2008-02-28 19:12:22 UTC (rev 2394)
@@ -38,13 +38,8 @@
   return chart.FindPosition(position);
 }
 
-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)
+void cProbSchedule::Adjust(int item_id, const cMerit& item_merit, int deme_id)
 {
   if (cChangeList *change_list = GetChangeList()) {
     change_list->MarkChange(item_id);

Modified: development/source/tools/cProbSchedule.h
===================================================================
--- development/source/tools/cProbSchedule.h	2008-02-28 18:31:51 UTC (rev 2393)
+++ development/source/tools/cProbSchedule.h	2008-02-28 19:12:22 UTC (rev 2394)
@@ -57,8 +57,7 @@
   cProbSchedule(int num_cells, int seed) : cSchedule(num_cells), m_rng(seed), chart(num_cells) { ; }
   ~cProbSchedule() { ; }
 
-  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme);
-  virtual void Adjust(int item_id, const cMerit& merit);
+  virtual void Adjust(int item_id, const cMerit& merit, int deme_id = 0);
 
   int GetNextID();
 };

Modified: development/source/tools/cSchedule.h
===================================================================
--- development/source/tools/cSchedule.h	2008-02-28 18:31:51 UTC (rev 2393)
+++ development/source/tools/cSchedule.h	2008-02-28 19:12:22 UTC (rev 2394)
@@ -60,8 +60,7 @@
   virtual ~cSchedule();
 
   virtual bool OK() { return true; }
-  virtual void Adjust(int item_id, const cMerit& merit, const cDeme& deme) = 0;
-  virtual void Adjust(int item_id, const cMerit& merit) = 0;
+  virtual void Adjust(int item_id, const cMerit& merit, int deme_id = 0) = 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