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

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Mon Jul 23 10:23:27 PDT 2007


Author: dknoester
Date: 2007-07-23 13:23:26 -0400 (Mon, 23 Jul 2007)
New Revision: 1839

Modified:
   branches/dkdev/source/actions/PopulationActions.cc
   branches/dkdev/source/main/cPopulation.cc
   branches/dkdev/source/main/cStats.cc
   branches/dkdev/source/main/cStats.h
Log:
Added CPL replicate deme method.


Modified: branches/dkdev/source/actions/PopulationActions.cc
===================================================================
--- branches/dkdev/source/actions/PopulationActions.cc	2007-07-23 16:58:40 UTC (rev 1838)
+++ branches/dkdev/source/actions/PopulationActions.cc	2007-07-23 17:23:26 UTC (rev 1839)
@@ -900,6 +900,7 @@
     else if (in_trigger == "topo-2cells-path-merit") m_rep_trigger = 8;
     else if (in_trigger == "message-collection") m_rep_trigger = 9;
     else if (in_trigger == "clustering-coefficient") m_rep_trigger = 10;
+    else if (in_trigger == "characteristic-path-length") m_rep_trigger = 11;
     else {
       cString err("Unknown replication trigger '");
       err += in_trigger;

Modified: branches/dkdev/source/main/cPopulation.cc
===================================================================
--- branches/dkdev/source/main/cPopulation.cc	2007-07-23 16:58:40 UTC (rev 1838)
+++ branches/dkdev/source/main/cPopulation.cc	2007-07-23 17:23:26 UTC (rev 1839)
@@ -1037,6 +1037,41 @@
         source_germline_merit = pow(target_clustering_coeff - abs(target_clustering_coeff-clustering_coeff) + 1, 2);
         break;
       }
+      case 11: {
+        // Replicate demes that are connected, and set merit inversly proportional to the 
+        // characteristic path length of the network.
+        // Replicate demes that are connected, and set merit to the inverse of mean LSP.
+        m_world->GetStats().Topology(source_deme.GetNetwork());
+        if(!network_is_connected(source_deme)) continue;
+        m_world->GetStats().TopologyConnected(source_deme.GetNetwork());
+        m_world->GetStats().TopologyReplication(source_deme.GetNetwork());        
+        
+        // Calculate the distances between each pair of nodes.
+        cDeme::Network& network = source_deme.GetNetwork();
+        typedef cDeme::Network::vertices_size_type size_type;
+        typedef std::vector<size_type> DistanceVector;
+        std::vector<DistanceVector> distance_matrix(boost::num_vertices(network),
+                                                    DistanceVector(boost::num_vertices(network), 0));
+        for(size_type i=0; i<boost::num_vertices(network); ++i) {
+          DistanceVisitor<size_type*> visitor(&distance_matrix[i][0]);
+          cDeme::Network::vertex_descriptor src = boost::vertices(network).first[i];
+          boost::breadth_first_search(network, src, boost::visitor(visitor));
+        }
+        
+        // Mean path length from v to v'.
+        double vertex_cpl=0.0;
+        for(size_type i=0; i<boost::num_vertices(network); ++i) {
+          vertex_cpl += std::accumulate(distance_matrix[i].begin(), distance_matrix[i].end(), 0.0) / (boost::num_vertices(network)-1);
+        }
+        
+        // Mean of mean path lengths.
+        double cpl = vertex_cpl / boost::num_vertices(network);        
+        double max_cpl = world_x * world_y/num_demes * 0.75;
+        
+        m_world->GetStats().TopologyCPL(cpl);
+        source_germline_merit = pow(max_cpl - cpl + 1, 2);
+        break;
+      }
 //case 5: {
 //  // Replicate demes that are connectd, and set merit to f(edge count, diameter).
 //  

Modified: branches/dkdev/source/main/cStats.cc
===================================================================
--- branches/dkdev/source/main/cStats.cc	2007-07-23 16:58:40 UTC (rev 1838)
+++ branches/dkdev/source/main/cStats.cc	2007-07-23 17:23:26 UTC (rev 1839)
@@ -889,6 +889,11 @@
 }
 
 
+void cStats::TopologyCPL(double cpl) {
+  _topo_cpl.Add(cpl);
+}
+
+
 void cStats::PrintTopologyData(const cString& filename) {
 	cDataFile& df = m_world->GetDataFile(filename);
 	df.WriteComment( "Topology data\n" );
@@ -901,6 +906,7 @@
   df.Write(_topo_maxlsp.Average(), "mean max longest shortest-path");
   df.Write(_topo_maxlsp_frac.Average(), "mean (mean lsp / max lsp)");
   df.Write(_topo_clustering_coeff.Average(), "mean clustering coefficient");
+  df.Write(_topo_cpl.Average(), "mean characteristic path length");
 	df.Endl();
   
   _topo_connected = 0;
@@ -910,6 +916,7 @@
   _topo_maxlsp.Clear();
   _topo_maxlsp_frac.Clear();
   _topo_clustering_coeff.Clear();
+  _topo_cpl.Clear();
 }
 
 

Modified: branches/dkdev/source/main/cStats.h
===================================================================
--- branches/dkdev/source/main/cStats.h	2007-07-23 16:58:40 UTC (rev 1838)
+++ branches/dkdev/source/main/cStats.h	2007-07-23 17:23:26 UTC (rev 1839)
@@ -209,6 +209,7 @@
   cDoubleSum _topo_maxlsp; //!< Max longest shortest-path.
   cDoubleSum _topo_maxlsp_frac; //!< Mean LSP / Max LSP.
   cDoubleSum _topo_clustering_coeff; //!< Clustering coefficient.
+  cDoubleSum _topo_cpl; //!< Characteristic path length.
   cDeme::Network _topo_last_network; //!< The last constructed network.
 
   int _deme_repl_count; //!< Number of deme replications since the last stats output.
@@ -565,6 +566,7 @@
   void TopologyLSP(double meanlsp, double maxlsp);
   void TopologyReplication(cDeme::Network& network);
   void TopologyClusteringCoeff(double clustering_coefficient);
+  void TopologyCPL(double cpl);
   void PrintTopologyData(const cString& filename);
   void PrintLastTopology();
   void PrintEachTopology();




More information about the Avida-cvs mailing list