[Avida-SVN] r2498 - in development/source: actions main

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Tue Mar 25 13:25:08 PDT 2008


Author: dknoester
Date: 2008-03-25 16:25:08 -0400 (Tue, 25 Mar 2008)
New Revision: 2498

Modified:
   development/source/actions/PrintActions.cc
   development/source/main/cDeme.cc
   development/source/main/cDeme.h
   development/source/main/cStats.cc
   development/source/main/cStats.h
Log:
Added PrintDemeFounders event.

Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2008-03-24 03:51:47 UTC (rev 2497)
+++ development/source/actions/PrintActions.cc	2008-03-25 20:25:08 UTC (rev 2498)
@@ -95,6 +95,7 @@
 STATS_OUT_FILE(PrintSleepData,              sleep.dat           );
 STATS_OUT_FILE(PrintCompetitionData,        competition.dat     );
 STATS_OUT_FILE(PrintDemeReplicationData,    deme_repl.dat       );
+STATS_OUT_FILE(PrintDemeFounders,           deme_founders.dat   );
 STATS_OUT_FILE(PrintGermlineData,           germline.dat        );
 // @WRE: Added output event for collected visit counts
 STATS_OUT_FILE(PrintCellVisitsData,         visits.dat			);
@@ -2654,6 +2655,7 @@
   action_lib->Register<cActionPrintDemeSpacialSleep>("PrintDemeSpacialSleepStats");
   action_lib->Register<cActionPrintDemeResources>("PrintDemeResourceStats");
   action_lib->Register<cActionPrintDemeReplicationData>("PrintDemeReplicationData");
+  action_lib->Register<cActionPrintDemeFounders>("PrintDemeFounders");
   action_lib->Register<cActionPrintGermlineData>("PrintGermlineData");
   
   

Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc	2008-03-24 03:51:47 UTC (rev 2497)
+++ development/source/main/cDeme.cc	2008-03-25 20:25:08 UTC (rev 2498)
@@ -68,6 +68,11 @@
   return std::make_pair(cellid % GetWidth(), cellid / GetWidth());
 }
 
+cPopulationCell& cDeme::GetCell(int pos)
+{
+  return m_world->GetPopulation().GetCell(cell_ids[pos]);
+}
+
 void cDeme::ProcessUpdate() {
   for(int i = 0; i < cell_events.GetSize(); i++) {
     cDemeCellEvent& event = cell_events[i];

Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h	2008-03-24 03:51:47 UTC (rev 2497)
+++ development/source/main/cDeme.h	2008-03-25 20:25:08 UTC (rev 2498)
@@ -33,6 +33,7 @@
 
 class cResource;
 class cWorld;
+class cPopulationCell;
 
 /*! Demes are groups of cells in the population that are somehow bound together
 as a unit.  The deme object is used from within cPopulation to manage these 
@@ -79,6 +80,7 @@
   int GetCellID(int x, int y) const;
   //! Returns an (x,y) pair for the position of the passed-in cell ID.
   std::pair<int, int> GetCellPosition(int cellid) const;
+  cPopulationCell& GetCell(int pos);
 
   int GetWidth() const { return width; }
   int GetHeight() const { return cell_ids.GetSize() / width; }

Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc	2008-03-24 03:51:47 UTC (rev 2497)
+++ development/source/main/cStats.cc	2008-03-25 20:25:08 UTC (rev 2498)
@@ -27,6 +27,7 @@
 
 #include "cDataFile.h"
 #include "cEnvironment.h"
+#include "cGenotype.h"
 #include "cHardwareManager.h"
 #include "cInstSet.h"
 #include "cPopulation.h"
@@ -1203,7 +1204,7 @@
   df.WriteColumnDesc("predicate:{p_info,...}...");
   df.FlushComments();
   
-  df.WriteAnonymous(m_update);
+  df.WriteAnonymous(GetUpdate());
   std::ofstream& out = df.GetOFStream();
   for(message_pred_ptr_list::iterator i=m_message_predicates.begin();
       i!=m_message_predicates.end(); ++i) {
@@ -1225,6 +1226,25 @@
 }
 
 
+/*! This method is a generic hook for post-deme-replication stat tracking.  We 
+currently only track the genotype ids of all the founders of each deme in the population.
+Note that we capture genotype ids at the time of deme replication, so we unfortunately
+lose the ancestral deme founders.
+*/
+void cStats::DemePostReplication(cDeme& source_deme, cDeme& target_deme)
+{
+  std::set<int> genotype_ids;
+  for(int i=0; i<target_deme.GetSize(); ++i) {
+    cPopulationCell& cell = target_deme.GetCell(i);
+    if(cell.IsOccupied()) {
+      genotype_ids.insert(cell.GetOrganism()->GetGenotype()->GetID());  
+    }
+  }
+  assert(genotype_ids.size()>0); // How did we get to replication otherwise?
+  m_deme_founders[target_deme.GetID()] = genotype_ids;
+}
+
+
 /*! Called immediately prior to germline replacement.
 */
 void cStats::GermlineReplication(cGermline& source_germline, cGermline& target_germline)
@@ -1243,7 +1263,7 @@
   
   df.WriteComment("Avida deme replication data");
   df.WriteTimeStamp();
-  df.Write(m_update, "Update [update]");
+  df.Write(GetUpdate(), "Update [update]");
   df.Write(m_deme_num_repls, "Number of deme replications [numrepl]");
   df.Write(m_deme_gestation_time.Average(), "Mean deme gestation time [gesttime]");
   df.Write(m_deme_births.Average(), "Mean number of births within replicated demes [numbirths]");
@@ -1266,9 +1286,42 @@
   
   df.WriteComment("Avida germline data");
   df.WriteTimeStamp();
-  df.Write(m_update, "Update [update]");
+  df.Write(GetUpdate(), "Update [update]");
   df.Write(m_germline_generation.Average(), "Mean germline generation of replicated germlines [replgen]");
   df.Endl();
     
   m_germline_generation.Clear();
 }
+
+
+/*! Print the genotype IDs of the founders of recently born demes.
+
+Prints only the most recent set of founding genotype ids for each deme.  If a deme was replaced multiple
+times since the last time this method ran, only the most recent is maintained.  Only deme "births" (i.e., due
+to deme replication) are tracked; the ancestral deme founders are lost.  The update column is the update 
+at which this method executes, not the time at which the given deme was born.  Only unique genotype ids are
+recorded (if multiple individuals are cloned from source to target deme [propagule size > 1], only a single
+genotype id will appear in the datafile).          
+*/
+void cStats::PrintDemeFounders(const cString& filename)
+{
+  cDataFile& df = m_world->GetDataFile(filename);
+  
+  df.WriteComment("Avida deme founder data.");
+  df.WriteTimeStamp();
+  df.WriteColumnDesc("Update [update]");
+  df.WriteColumnDesc("Deme ID [demeid]");
+  df.WriteColumnDesc("Number of founders [size]");
+  df.WriteColumnDesc("{Genotype ID of founder 0, ...}");
+  df.FlushComments();
+  
+  std::ofstream& out = df.GetOFStream();
+  for(t_founder_map::iterator i=m_deme_founders.begin(); i!=m_deme_founders.end(); ++i) {
+    out << GetUpdate() << " " << i->first << " " << i->second.size();    
+    for(std::set<int>::iterator j=i->second.begin(); j!=i->second.end(); ++j) {
+      out << " " << *j;
+    }
+    df.Endl();
+  }
+  m_deme_founders.clear();
+}

Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h	2008-03-24 03:51:47 UTC (rev 2497)
+++ development/source/main/cStats.h	2008-03-25 20:25:08 UTC (rev 2498)
@@ -30,6 +30,8 @@
 #include <fstream>
 #include <iostream>
 #include <vector>
+#include <map>
+#include <set>
 
 #ifndef defs_h
 #include "defs.h"
@@ -695,7 +697,7 @@
   //! Called immediately prior to deme replacement.
   void DemePreReplication(cDeme& source_deme, cDeme& target_deme);
   //! Called immediately after deme replacement.
-  void DemePostReplication(cDeme& source_deme, cDeme& target_deme) { }
+  void DemePostReplication(cDeme& source_deme, cDeme& target_deme);
   //! Called immediately prior to germline replacement.
   void GermlineReplication(cGermline& source_germline, cGermline& target_germline);
   //! Print statistics about deme replication.
@@ -704,7 +706,12 @@
   void PrintGermlineData(const cString& filename);
   //! Accessor for average "generation" of germlines.
   double GetAveGermlineGeneration() const { return m_germline_generation.Average(); }
-  
+  /*! Typedef of a data structure to track deme founders.
+    * Map of deme id -> {founder genotype id_0, id_1,... id_{deme propagule size}} */
+  typedef std::map<int, std::set<int> > t_founder_map;
+  //! Print the genotype IDs for the founders of demes that have recently been "born."
+  void PrintDemeFounders(const cString& filename);
+
 protected:
   int m_deme_num_repls; //!< Number of deme replications since last PrintDemeReplicationData.
   cDoubleSum m_deme_gestation_time; //!< Gestation time for demes - mean age at deme replication.
@@ -712,6 +719,7 @@
   cDoubleSum m_deme_merit; //!< Mean merit of replicated demes.
   cDoubleSum m_deme_generation; //!< Mean generation of replicated demes.
   cDoubleSum m_germline_generation; //!< "Generation" accumulator of replicated germlines.
+  t_founder_map m_deme_founders; //!< Data structure to track the founders of demes.
 };
 
 




More information about the Avida-cvs mailing list