[Avida-SVN] r2188 - in branches/dkdev/source: actions main

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Thu Nov 8 16:33:08 PST 2007


Author: dknoester
Date: 2007-11-08 19:33:08 -0500 (Thu, 08 Nov 2007)
New Revision: 2188

Modified:
   branches/dkdev/source/actions/PrintActions.cc
   branches/dkdev/source/main/cAvidaConfig.h
   branches/dkdev/source/main/cDeme.cc
   branches/dkdev/source/main/cGermline.h
   branches/dkdev/source/main/cPopulation.cc
   branches/dkdev/source/main/cStats.cc
   branches/dkdev/source/main/cStats.h
Log:
Added:
- Dominant germline stats.
- Flag to not report age-based replications.
- Don't do age-based replications of sterile germlines.
- Removed windowed germline merit (it may come back later...?).
- Resetting a deme moves its twocells/region line (no more laggard parents).



Modified: branches/dkdev/source/actions/PrintActions.cc
===================================================================
--- branches/dkdev/source/actions/PrintActions.cc	2007-11-08 18:02:27 UTC (rev 2187)
+++ branches/dkdev/source/actions/PrintActions.cc	2007-11-09 00:33:08 UTC (rev 2188)
@@ -70,6 +70,7 @@
 STATS_OUT_FILE(PrintCollectionData, collection.dat);
 STATS_OUT_FILE(PrintTwoCellsData, twocells.dat);
 STATS_OUT_FILE(PrintTwoCellsLocations, location.dat);
+STATS_OUT_FILE(PrintDominantGermlineData, germdom.dat);
 
 
 
@@ -1559,6 +1560,7 @@
   action_lib->Register<cActionPrintTopologyData>("PrintTopologyData");
   action_lib->Register<cActionPrintDemeData>("PrintDemeData");
   action_lib->Register<cActionPrintGermlineData>("PrintGermlineData");
+  action_lib->Register<cActionPrintDominantGermlineData>("PrintDominantGermlineData");
   action_lib->Register<cActionPrintLastTopology>("PrintLastTopology");
   action_lib->Register<cActionPrintEachTopology>("PrintEachTopology");
   action_lib->Register<cActionPrintEachConnectedTopology>("PrintEachConnectedTopology");

Modified: branches/dkdev/source/main/cAvidaConfig.h
===================================================================
--- branches/dkdev/source/main/cAvidaConfig.h	2007-11-08 18:02:27 UTC (rev 2187)
+++ branches/dkdev/source/main/cAvidaConfig.h	2007-11-09 00:33:08 UTC (rev 2188)
@@ -167,7 +167,6 @@
   CONFIG_ADD_VAR(FILL_DEME_ON_REPLICATE, int, 0, "Whether to fill the source and target demes upon replication.");
   CONFIG_ADD_VAR(GERMLINE_REPLACES_SOURCE, int, 0, "Whether the source germline is updated on replication; 0=no.");
   CONFIG_ADD_VAR(GERMLINE_RANDOM_PLACEMENT, int, 0, "Whether the seed for a germline is placed randomly within the deme; 0=no.");
-  CONFIG_ADD_VAR(GERMLINE_MERIT_WINDOW_SIZE, int, 1, "The size of the germline merit accumulation window; >=1.");
   CONFIG_ADD_VAR(MAX_DEME_AGE, int, 500, "The maximum age of a deme (in updates) to be used for age-based replication (default=500).");
   CONFIG_ADD_VAR(TRACK_GENOTYPES, int, 0, "Whether genotypes are tracked graphically.");
   CONFIG_ADD_VAR(TWOCELLS_MIN_REGION_RATIO, double, 0.2, "Ratio of size of two-cells region to environment size.");

Modified: branches/dkdev/source/main/cDeme.cc
===================================================================
--- branches/dkdev/source/main/cDeme.cc	2007-11-08 18:02:27 UTC (rev 2187)
+++ branches/dkdev/source/main/cDeme.cc	2007-11-09 00:33:08 UTC (rev 2188)
@@ -39,24 +39,13 @@
   width = in_width;
   if (width < 1) width = cell_ids.GetSize();
   
-  
-  // Need to change this to pick (x,y) instead of cellid.
-  
-  _cellsToLink = std::make_pair(GetCellID(_world->GetRandom().GetInt(GetWidth()), _world->GetRandom().GetInt(GetHeight()-2)+1),
-                                cell_ids[_world->GetRandom().GetInt(cell_ids.GetSize())]);
-                                
-  while((_cellsToLink.second == _cellsToLink.first) 
-        || (((double)region_size(GetCellPosition(_cellsToLink.first), GetCellPosition(_cellsToLink.second))
-             / GetSize()) < _world->GetConfig().TWOCELLS_MIN_REGION_RATIO.Get())) {
-    _cellsToLink.second = cell_ids[_world->GetRandom().GetInt(cell_ids.GetSize())];
-  }
-  
   // Load up the map of random cell ids.
   if(_cellsToMsgCount.size()==0) {
     for(int i=0; i<cell_ids.GetSize(); ++i) {
       _cellsToMsgCount[pop->GetCell(cell_ids[i]).GetRandomCellID()] = 0;
     }  
   }  
+  Reset();
 }
 
 int cDeme::GetCellID(int x, int y) const
@@ -89,6 +78,16 @@
   for(CellCountMap::iterator i=_cellsToMsgCount.begin(); i!=_cellsToMsgCount.end(); ++i) {
     i->second = 0;
   }
+  if(cell_ids.GetSize() > 0) {
+    _cellsToLink = std::make_pair(GetCellID(_world->GetRandom().GetInt(GetWidth()), _world->GetRandom().GetInt(GetHeight()-2)+1),
+                                  cell_ids[_world->GetRandom().GetInt(cell_ids.GetSize())]);
+    
+    while((_cellsToLink.second == _cellsToLink.first) 
+          || (((double)region_size(GetCellPosition(_cellsToLink.first), GetCellPosition(_cellsToLink.second))
+               / GetSize()) < _world->GetConfig().TWOCELLS_MIN_REGION_RATIO.Get())) {
+      _cellsToLink.second = cell_ids[_world->GetRandom().GetInt(cell_ids.GetSize())];
+    }  
+  }
 }
 
 

Modified: branches/dkdev/source/main/cGermline.h
===================================================================
--- branches/dkdev/source/main/cGermline.h	2007-11-08 18:02:27 UTC (rev 2187)
+++ branches/dkdev/source/main/cGermline.h	2007-11-09 00:33:08 UTC (rev 2188)
@@ -2,7 +2,6 @@
 #define _C_GERMLINE_H_
 
 #include <vector>
-#include <deque>
 #include <numeric>
 
 #include "cGenome.h"
@@ -11,27 +10,16 @@
 class cGermline {
 public:
 	cGenome& GetLatest() { return _germline.back(); }
-  const std::deque<double>& GetMeritWindow() { return _merit_window; }
 	void Add(const cGenome& genome) { _germline.push_back(genome); }
 	unsigned int Size() const { return _germline.size(); }
   
-  const cMerit& GetMerit() {
-    _merit = std::accumulate(_merit_window.begin(), _merit_window.end(), 0.0);
-    return _merit; 
-  }
-  void UpdateMerit(double v) { UpdateWindowedMerit(v, 1); }
-  void UpdateWindowedMerit(double v, int window_size) { 
-    assert(window_size >= 1);
-    if(_merit_window.size() >= (unsigned int)window_size) {
-      _merit_window.pop_front();
-    }
-    _merit_window.push_back(v);
-  }
+  const cMerit& GetMerit() { return _merit; }
+  void UpdateMerit(double v) { _merit = v; }
 
 protected:
 	std::vector<cGenome> _germline;
-  std::deque<double> _merit_window;
   cMerit _merit;
 };
 
+
 #endif

Modified: branches/dkdev/source/main/cPopulation.cc
===================================================================
--- branches/dkdev/source/main/cPopulation.cc	2007-11-08 18:02:27 UTC (rev 2187)
+++ branches/dkdev/source/main/cPopulation.cc	2007-11-09 00:33:08 UTC (rev 2188)
@@ -933,6 +933,7 @@
 		cDeme& source_deme = deme_array[deme_id];
     cDeme::Network& network = source_deme.GetNetwork();
     double source_germline_merit = 0.0;
+    bool record_replication = true;
 
     // Doesn't make sense to try and replicate a deme that *has no organisms*.
     if(source_deme.IsEmpty()) continue;
@@ -960,8 +961,12 @@
 				break;
 			}
       case 3: {
-        // Replicate old demes (deme-age).
-        if(source_deme.GetAge() < m_world->GetConfig().MAX_DEME_AGE.Get()) continue;
+        // Replicate old demes (deme-age), but don't replicate sterile demes.
+        if((source_deme.GetAge() < m_world->GetConfig().MAX_DEME_AGE.Get())
+           || (source_deme.GetBirthCount() < source_deme.GetSize())) {
+          continue;
+        }
+        record_replication = false;
         break;
       }			
       case 4: {
@@ -1174,7 +1179,6 @@
                                                     &cell_array.begin()[source_deme.GetCellID(source_deme.GetSize()-1)+1],
                                                     0.0, correct_region_accumulator(source_deme)),
                                     2);
-        
         break;
       }
       case 21: {
@@ -1212,7 +1216,6 @@
                                                     &cell_array.begin()[source_deme.GetCellID(source_deme.GetSize()-1)+1],
                                                     0.0, bounded_region_accumulator(source_deme)),
                                     2);
-        
         break;
       }
 //      case 19: {
@@ -1318,9 +1321,11 @@
     
     // Check to see if we should update the source deme's germline merit.
     if(m_world->GetConfig().DEMES_USE_GERMLINE.Get() && m_world->GetConfig().DEMES_HAVE_MERIT.Get()) {
-      source_deme.GetGermline().UpdateWindowedMerit(source_germline_merit, m_world->GetConfig().GERMLINE_MERIT_WINDOW_SIZE.Get());
+      source_deme.GetGermline().UpdateMerit(source_germline_merit);
     }
-    m_world->GetStats().DemeReplication(source_deme);
+    if(record_replication) {
+      m_world->GetStats().DemeReplication(source_deme, rep_trigger);
+    }
 		cRandom& random = m_world->GetRandom();
 		
 		// Choose a random target deme to replicate to, and kill all the organisms

Modified: branches/dkdev/source/main/cStats.cc
===================================================================
--- branches/dkdev/source/main/cStats.cc	2007-11-08 18:02:27 UTC (rev 2187)
+++ branches/dkdev/source/main/cStats.cc	2007-11-09 00:33:08 UTC (rev 2188)
@@ -995,7 +995,7 @@
 }
 
 
-void cStats::DemeReplication(cDeme& deme) {
+void cStats::DemeReplication(cDeme& deme, int replication_trigger) {
   // Common deme statistics.
   ++_deme_repl_count;
   _deme_age.Add(deme.GetAge());
@@ -1045,7 +1045,35 @@
   _deme_max_germline_merit = 0.0;
 }
 
+typedef std::multiset<std::string> dom_germline_t;
 
+struct find_dominant_germline : std::binary_function<std::string, std::string, bool> {
+  find_dominant_germline(dom_germline_t& germs) : _germs(germs) { }
+  bool operator()(const std::string& one, const std::string& two) {
+    // is one less than two?
+    return _germs.count(one) < _germs.count(two);
+  }
+  dom_germline_t& _germs;
+};
+
+void cStats::PrintDominantGermlineData(const cString& filename) {
+  assert(m_world->GetConfig().DEMES_USE_GERMLINE.Get() && m_world->GetConfig().DEMES_HAVE_MERIT.Get());
+  cDataFile& df = m_world->GetDataFile(filename);
+  df.WriteComment("Dominant germline data");
+  df.WriteTimeStamp();
+  df.Write(GetUpdate(), "update [update]");
+  dom_germline_t germs;
+  for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
+    cDeme& deme = m_world->GetPopulation().GetDeme(i);
+    germs.insert((const char*)deme.GetGermline().GetLatest().AsString());
+  }
+  std::string dominant = *std::max_element(germs.begin(), germs.end(), find_dominant_germline(germs));
+  df.Write((int)germs.count(dominant), "abundance of dominant germ [abundance]");
+  df.Write(dominant.data(), "dominant genome");
+  df.Endl();
+}
+
+
 void cStats::PrintCollectionData(const cString& filename) {
   cDataFile& df = m_world->GetDataFile(filename);
   df.WriteComment("Message collection stats");

Modified: branches/dkdev/source/main/cStats.h
===================================================================
--- branches/dkdev/source/main/cStats.h	2007-11-08 18:02:27 UTC (rev 2187)
+++ branches/dkdev/source/main/cStats.h	2007-11-09 00:33:08 UTC (rev 2188)
@@ -577,9 +577,11 @@
   // Deme-related statistics.
   //
 public:
-  void DemeReplication(cDeme& deme);
+  void DemeReplication(cDeme& deme, int replication_trigger);
   void PrintDemeData(const cString& filename);
   void PrintGermlineData(const cString& filename);
+  void PrintDominantGermlineData(const cString& filename);
+
 private:
   int _deme_repl_count; //!< Number of deme replications since the last stats output.
   cDoubleSum _deme_merit; //!< Deme merits, upon replication.




More information about the Avida-cvs mailing list