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

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Tue Oct 30 15:02:46 PDT 2007


Author: dknoester
Date: 2007-10-30 18:02:46 -0400 (Tue, 30 Oct 2007)
New Revision: 2162

Modified:
   branches/dkdev/source/actions/PrintActions.cc
   branches/dkdev/source/main/cStats.cc
   branches/dkdev/source/main/cStats.h
Log:
Statistics for tracking germline w/ highest merit.

Modified: branches/dkdev/source/actions/PrintActions.cc
===================================================================
--- branches/dkdev/source/actions/PrintActions.cc	2007-10-30 13:31:58 UTC (rev 2161)
+++ branches/dkdev/source/actions/PrintActions.cc	2007-10-30 22:02:46 UTC (rev 2162)
@@ -66,6 +66,7 @@
 STATS_OUT_FILE(PrintMarketData,		   market.dat		   );
 STATS_OUT_FILE(PrintTopologyData, topology.dat);
 STATS_OUT_FILE(PrintDemeData, deme.dat);
+STATS_OUT_FILE(PrintGermlineData, germline.dat);
 STATS_OUT_FILE(PrintCollectionData, collection.dat);
 STATS_OUT_FILE(PrintTwoCellsData, twocells.dat);
 STATS_OUT_FILE(PrintTwoCellsLocations, location.dat);
@@ -1481,13 +1482,13 @@
 };
 
 
-class cActionPrintLastGermline : public cAction
+class cActionPrintEachConnectedTopology : public cAction
 {
 public:
-  cActionPrintLastGermline(cWorld* world, const cString& args) : cAction(world, args) { }
+  cActionPrintEachConnectedTopology(cWorld* world, const cString& args) : cAction(world, args) { }
   static const cString GetDescription() { return "No arguments."; }
   void Process(cAvidaContext& ctx) {
-    m_world->GetStats().PrintLastGermline();
+    m_world->GetStats().PrintEachConnectedTopology();
   }
 };
 
@@ -1557,9 +1558,10 @@
   // Topology
   action_lib->Register<cActionPrintTopologyData>("PrintTopologyData");
   action_lib->Register<cActionPrintDemeData>("PrintDemeData");
+  action_lib->Register<cActionPrintGermlineData>("PrintGermlineData");
   action_lib->Register<cActionPrintLastTopology>("PrintLastTopology");
-  action_lib->Register<cActionPrintLastGermline>("PrintLastGermline");
   action_lib->Register<cActionPrintEachTopology>("PrintEachTopology");
+  action_lib->Register<cActionPrintEachConnectedTopology>("PrintEachConnectedTopology");
   
   // Satellite
   action_lib->Register<cActionPrintCollectionData>("PrintCollectionData");  

Modified: branches/dkdev/source/main/cStats.cc
===================================================================
--- branches/dkdev/source/main/cStats.cc	2007-10-30 13:31:58 UTC (rev 2161)
+++ branches/dkdev/source/main/cStats.cc	2007-10-30 22:02:46 UTC (rev 2162)
@@ -96,6 +96,7 @@
   , num_own_used(0)
   , _topo_connected(0)
   , _deme_repl_count(0)
+  , _deme_max_germline_merit(0.0)
   , _two_cells_incorrect(0)
   , _two_cells_inside(0)
   , _two_cells_outside(0)
@@ -964,6 +965,20 @@
 };
   
 
+void cStats::PrintEachConnectedTopology() {
+  for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
+    cDeme& deme = m_world->GetPopulation().GetDeme(i);
+    cDeme::Network& network = deme.GetNetwork();
+    if((boost::num_vertices(network) == deme.GetSize()) && network_is_connected(network)) {
+      std::stringstream filename;
+      filename << "./data/connected-topo-" << i << "-" << GetUpdate() << "u.dot";
+      std::ofstream outfile(filename.str().c_str());
+      boost::write_graphviz(outfile, network, topo_vertex_writer(network));
+      outfile.close();      
+    }
+  }  
+}
+
 void cStats::PrintEachTopology() {
   for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
     cDeme& deme = m_world->GetPopulation().GetDeme(i);
@@ -980,18 +995,6 @@
 }
 
 
-void cStats::PrintLastGermline() {
-  assert(m_world->GetConfig().DEMES_USE_GERMLINE.Get());
-  if(_deme_last_germline.Size() > 0) {
-    std::stringstream filename;
-    filename << "./data/germ-" << GetUpdate() << ".genome";
-    std::ofstream outfile(filename.str().c_str());
-    outfile << _deme_last_germline.GetLatest().AsString() << std::endl;
-    outfile.close();
-  }
-}
-
-
 void cStats::DemeReplication(cDeme& deme) {
   // Common deme statistics.
   ++_deme_repl_count;
@@ -1001,6 +1004,10 @@
   if(m_world->GetConfig().DEMES_USE_GERMLINE.Get() && m_world->GetConfig().DEMES_HAVE_MERIT.Get()) {
     _deme_last_germline = deme.GetGermline();
     _deme_merit.Add(deme.GetGermline().GetMerit().GetDouble());
+    if(deme.GetGermline().GetMerit().GetDouble() > _deme_max_germline_merit) {
+      _deme_max_germline_merit = deme.GetGermline().GetMerit().GetDouble();
+      _deme_max_germline = deme.GetGermline();
+    }
   }
 }
 
@@ -1014,14 +1021,28 @@
   df.Write(std::min(_deme_repl_count/(double)m_world->GetPopulation().GetNumDemes(), 1.0), 
            "replication probability [prob]");
   df.Write(_deme_age.Average(), "mean age of replicated demes [age]");
-  if(m_world->GetConfig().DEMES_USE_GERMLINE.Get() && m_world->GetConfig().DEMES_HAVE_MERIT.Get()) {
-    df.Write(_deme_merit.Average(), "mean merit of replicated demes [merit]");
+  df.Endl();  
+  _deme_repl_count = 0;
+  _deme_age.Clear();
+}
+
+
+void cStats::PrintGermlineData(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("Germline data");
+  df.WriteTimeStamp();
+  df.Write(GetUpdate(), "update [update]");
+  df.Write(_deme_merit.Average(), "mean germline merit of replicated demes [mean_merit]");
+  df.Write(_deme_max_germline_merit, "max germline merit of replicated demes [max_merit]");
+  if(_deme_max_germline.Size() > 0) {
+    df.Write(_deme_max_germline.GetLatest().AsString(), "max germline genome [max_genome]");
+  } else {
+    df.Write("-", "max germline genome [max_genome]");
   }
   df.Endl();
-  
-  _deme_repl_count = 0;
   _deme_merit.Clear();
-  _deme_age.Clear();
+  _deme_max_germline_merit = 0.0;
 }
 
 

Modified: branches/dkdev/source/main/cStats.h
===================================================================
--- branches/dkdev/source/main/cStats.h	2007-10-30 13:31:58 UTC (rev 2161)
+++ branches/dkdev/source/main/cStats.h	2007-10-30 22:02:46 UTC (rev 2162)
@@ -554,6 +554,7 @@
   void TopologyReplication(cDeme::Network& network);
   void PrintTopologyData(const cString& filename);
   void PrintLastTopology();
+  void PrintEachConnectedTopology();
   void PrintEachTopology();
   
 private:
@@ -578,12 +579,14 @@
 public:
   void DemeReplication(cDeme& deme);
   void PrintDemeData(const cString& filename);
-  void PrintLastGermline();
+  void PrintGermlineData(const cString& filename);
 private:
   int _deme_repl_count; //!< Number of deme replications since the last stats output.
   cDoubleSum _deme_merit; //!< Deme merits, upon replication.
   cDoubleSum _deme_age; //!< Deme ages, upon replication.
-  cGermline _deme_last_germline; //!< The last germline to cause a deme replication.
+  cGermline _deme_last_germline; //!< The last germline to cause a deme replication.  
+  double _deme_max_germline_merit; //!< The maximum germline merit since the last stat output.
+  cGermline _deme_max_germline; //!< The germline responsible for the maximum merit.
   
   //
   // Satellite-related statistics.




More information about the Avida-cvs mailing list