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

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Wed Jun 13 16:28:22 PDT 2007


Author: dknoester
Date: 2007-06-13 19:28:22 -0400 (Wed, 13 Jun 2007)
New Revision: 1679

Modified:
   branches/dkdev/source/actions/PopulationActions.cc
   branches/dkdev/source/actions/PrintActions.cc
   branches/dkdev/source/main/cDeme.cc
   branches/dkdev/source/main/cDeme.h
   branches/dkdev/source/main/cPopulation.cc
   branches/dkdev/source/main/cStats.cc
   branches/dkdev/source/main/cStats.h
Log:
Reporting fixes, path merit for 2cells.

Modified: branches/dkdev/source/actions/PopulationActions.cc
===================================================================
--- branches/dkdev/source/actions/PopulationActions.cc	2007-06-13 21:00:25 UTC (rev 1678)
+++ branches/dkdev/source/actions/PopulationActions.cc	2007-06-13 23:28:22 UTC (rev 1679)
@@ -896,7 +896,8 @@
     else if (in_trigger == "topo-connected") m_rep_trigger = 4;
     else if (in_trigger == "topo-edge-merit") m_rep_trigger = 5;
     else if (in_trigger == "topo-meanlsp-merit") m_rep_trigger = 6;
-    else if (in_trigger == "topo-2cells-edge-merit") m_rep_trigger = 7;    
+    else if (in_trigger == "topo-2cells-edge-merit") m_rep_trigger = 7;
+    else if (in_trigger == "topo-2cells-path-merit") m_rep_trigger = 8;
     else {
       cString err("Unknown replication trigger '");
       err += in_trigger;

Modified: branches/dkdev/source/actions/PrintActions.cc
===================================================================
--- branches/dkdev/source/actions/PrintActions.cc	2007-06-13 21:00:25 UTC (rev 1678)
+++ branches/dkdev/source/actions/PrintActions.cc	2007-06-13 23:28:22 UTC (rev 1679)
@@ -1466,6 +1466,17 @@
 };
 
 
+class cActionPrintEachTopology : public cAction
+{
+public:
+  cActionPrintEachTopology(cWorld* world, const cString& args) : cAction(world, args) { }
+  static const cString GetDescription() { return "No arguments."; }
+  void Process(cAvidaContext& ctx) {
+    m_world->GetStats().PrintEachTopology();
+  }
+};
+
+
 class cActionPrintLastGermline : public cAction
 {
 public:
@@ -1544,8 +1555,8 @@
   action_lib->Register<cActionPrintDemeData>("PrintDemeData");
   action_lib->Register<cActionPrintLastTopology>("PrintLastTopology");
   action_lib->Register<cActionPrintLastGermline>("PrintLastGermline");
+  action_lib->Register<cActionPrintEachTopology>("PrintEachTopology");
 
-
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionPrintAverageData>("print_average_data");
   action_lib->Register<cActionPrintErrorData>("print_error_data");

Modified: branches/dkdev/source/main/cDeme.cc
===================================================================
--- branches/dkdev/source/main/cDeme.cc	2007-06-13 21:00:25 UTC (rev 1678)
+++ branches/dkdev/source/main/cDeme.cc	2007-06-13 23:28:22 UTC (rev 1679)
@@ -103,3 +103,30 @@
 int max_edges(cDeme& deme) {
   return cTopology::max_connections(deme.GetWorld()->GetConfig().WORLD_GEOMETRY.Get(), deme.GetHeight(), deme.GetWidth());
 }
+
+
+bool network_2cells_connected(cDeme& deme) {
+  cDeme::Network& network = deme.GetNetwork();
+  
+  cDeme::CellVertexMap& vertex_map = deme.GetCellVertexMap();        
+  std::pair<int,int> cells = deme.GetCellsToLink();
+  
+  // First verify that both of the cells in question are in the network.
+  if(vertex_map.find(cells.first)==vertex_map.end()
+     || vertex_map.find(cells.second)==vertex_map.end()) {
+    return false;
+  }
+  
+  // Ok, they're both in the network.  From the src, get the distance to
+  // all other vertices.
+  typedef cDeme::Network::vertices_size_type size_type;
+  typedef std::vector<size_type> DistanceVector;
+  DistanceVector dv(boost::num_vertices(network),0);
+  DistanceVisitor<size_type*> visitor(&dv[0]);
+  cDeme::Network::vertex_descriptor src = vertex_map[cells.first];
+  cDeme::Network::vertex_descriptor dst = vertex_map[cells.second];
+  boost::breadth_first_search(network, src, boost::visitor(visitor));
+  
+  // Now, if the distance from src to dst is 0, we know there is no path.
+  return dv[dst] != 0;   
+}

Modified: branches/dkdev/source/main/cDeme.h
===================================================================
--- branches/dkdev/source/main/cDeme.h	2007-06-13 21:00:25 UTC (rev 1678)
+++ branches/dkdev/source/main/cDeme.h	2007-06-13 23:28:22 UTC (rev 1679)
@@ -128,5 +128,7 @@
 bool network_is_connected(cDeme& deme);
 //! Returns the maximum number of edges that this deme's network can have.
 int max_edges(cDeme& deme);
+//! Returns a boolean for whether the passed-in deme's two randomly selected cells are connected.
+bool network_2cells_connected(cDeme& deme);
 
 #endif

Modified: branches/dkdev/source/main/cPopulation.cc
===================================================================
--- branches/dkdev/source/main/cPopulation.cc	2007-06-13 21:00:25 UTC (rev 1678)
+++ branches/dkdev/source/main/cPopulation.cc	2007-06-13 23:28:22 UTC (rev 1679)
@@ -916,6 +916,45 @@
         source_germline_merit = pow((double)(max_edges(source_deme) - boost::num_edges(network)+1), 2);
         break;
       }
+      case 8: {
+        // Replicate demes that have connected two randomly-selected cells.
+        // Merit is the inverse of (max(e(N))-e(N)+1) + 
+        cDeme::Network& network = source_deme.GetNetwork();
+        m_world->GetStats().Topology(network);
+        
+        cDeme::CellVertexMap& vertex_map = source_deme.GetCellVertexMap();        
+        std::pair<int,int> cells = source_deme.GetCellsToLink();
+        
+        // First verify that both of the cells in question are in the network.
+        if(vertex_map.find(cells.first)==vertex_map.end()
+           || vertex_map.find(cells.second)==vertex_map.end()) {
+          continue;
+        }
+        
+        // We're also going to make sure that the network has a chance to fill up.
+        // This is to discourage extra work.
+        if(boost::num_vertices(network) < (unsigned)source_deme.GetSize()) {
+          continue;
+        }
+        
+        // Ok, they're both in the network.  From the src, get the distance to
+        // all other vertices.
+        typedef cDeme::Network::vertices_size_type size_type;
+        typedef std::vector<size_type> DistanceVector;
+        DistanceVector dv(boost::num_vertices(network),0);
+        DistanceVisitor<size_type*> visitor(&dv[0]);
+        cDeme::Network::vertex_descriptor src = vertex_map[cells.first];
+        cDeme::Network::vertex_descriptor dst = vertex_map[cells.second];
+        boost::breadth_first_search(network, src, boost::visitor(visitor));
+        
+        // Now, if the distance from src to dst is 0, we know there is no path.
+        if(dv[dst]==0) continue;
+        
+        // We've determined that there is a path; replication will proceed.
+        m_world->GetStats().TopologyReplication(network);
+        source_germline_merit = pow((double)boost::num_vertices(network) - 1 - dv[dst], 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-06-13 21:00:25 UTC (rev 1678)
+++ branches/dkdev/source/main/cStats.cc	2007-06-13 23:28:22 UTC (rev 1679)
@@ -914,6 +914,7 @@
 		out << "[pos=\"" << boost::get(boost::vertex_bundle, _network)[v]._x 
 		<< "," << boost::get(boost::vertex_bundle, _network)[v]._y << "!\"]";
 	}
+  
 	cDeme::Network& _network;
 };
 
@@ -929,6 +930,42 @@
 }
 
 
+struct topo_2cells_writer {
+  topo_2cells_writer(cDeme& deme) : _deme(deme), _network(_deme.GetNetwork()) { }
+	
+	template<typename VertexOrEdge>
+	void operator()(std::ostream& out, const VertexOrEdge& v) {
+    std::pair<int,int> pos = std::make_pair(boost::get(boost::vertex_bundle, _network)[v]._x,
+                                            boost::get(boost::vertex_bundle, _network)[v]._y);
+    out << "[pos=\"" << pos.first << "," << pos.second << "!\"";
+    if((pos == _deme.GetCellPosition(_deme.GetCellsToLink().first))
+       || (pos == _deme.GetCellPosition(_deme.GetCellsToLink().second))) {
+      out << ", style=filled, fillcolor=gray";
+    }
+    out << "]";
+	}
+  
+  cDeme& _deme;
+	cDeme::Network& _network;  
+};
+  
+
+void cStats::PrintEachTopology() {
+  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) > 0)
+       && network_2cells_connected(deme)) {
+      std::stringstream filename;
+      filename << "./data/topo-" << i << "-" << GetUpdate() << "u.dot";      
+      std::ofstream outfile(filename.str().c_str());
+      boost::write_graphviz(outfile, network, topo_2cells_writer(deme));
+      outfile.close();      
+    }
+  }
+}
+
+
 void cStats::PrintLastGermline() {
   assert(m_world->GetConfig().DEMES_USE_GERMLINE.Get());
   if(_deme_last_germline.Size() > 0) {

Modified: branches/dkdev/source/main/cStats.h
===================================================================
--- branches/dkdev/source/main/cStats.h	2007-06-13 21:00:25 UTC (rev 1678)
+++ branches/dkdev/source/main/cStats.h	2007-06-13 23:28:22 UTC (rev 1679)
@@ -565,6 +565,7 @@
   void TopologyReplication(cDeme::Network& network);
   void PrintTopologyData(const cString& filename);
   void PrintLastTopology();
+  void PrintEachTopology();
   
   // Demes
   void DemeReplication(cDeme& deme);




More information about the Avida-cvs mailing list