[Avida-SVN] r1380 - in branches/dkdev/source: cpu main

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Sat Mar 3 13:42:02 PST 2007


Author: dknoester
Date: 2007-03-03 16:42:02 -0500 (Sat, 03 Mar 2007)
New Revision: 1380

Modified:
   branches/dkdev/source/cpu/cHardwareCPU.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
Log:
Altered printing of deme topologies to include a fixed position for each cell.

Modified: branches/dkdev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/dkdev/source/cpu/cHardwareCPU.cc	2007-03-01 20:59:08 UTC (rev 1379)
+++ branches/dkdev/source/cpu/cHardwareCPU.cc	2007-03-03 21:42:02 UTC (rev 1380)
@@ -3450,20 +3450,24 @@
     if(!deme.IsCellID(connectTo)) return false;
   } else {
     // No; get the cell to connect to from our facing.
-    connectTo = cell.ConnectionList().GetFirst()->GetRandomCellID();
+    connectTo = cell.ConnectionList().GetFirst()->GetID();
   }
 
   // Now, are this cell and the cell we're connecting to in the network?  If no,
   // add them; if yes, then get a ref to the vertex descriptors.
-  cDeme::CellVertexMap::iterator u = cvMap.find(cell.GetRandomCellID());
+  cDeme::CellVertexMap::iterator u = cvMap.find(cell.GetID());
   if(u == cvMap.end()) {
     // Add this cell to the network.
-    u = cvMap.insert(std::make_pair(cell.GetRandomCellID(), boost::add_vertex(network))).first;
+    u = cvMap.insert(std::make_pair(cell.GetID(), 
+									boost::add_vertex(deme.GetCellPosition(cell.GetID()),
+													  network))).first;
   }
   cDeme::CellVertexMap::iterator v = cvMap.find(connectTo);
   if(v == cvMap.end()) {
     // Add the other cell to the network.
-    v = cvMap.insert(std::make_pair(connectTo, boost::add_vertex(network))).first;
+    v = cvMap.insert(std::make_pair(connectTo, 
+									boost::add_vertex(deme.GetCellPosition(connectTo),
+													  network))).first;
   }  
 
   // Finally, add the edge.  We're done.

Modified: branches/dkdev/source/main/cDeme.cc
===================================================================
--- branches/dkdev/source/main/cDeme.cc	2007-03-01 20:59:08 UTC (rev 1379)
+++ branches/dkdev/source/main/cDeme.cc	2007-03-03 21:42:02 UTC (rev 1380)
@@ -39,6 +39,16 @@
   return cell_ids[pos];
 }
 
+
+std::pair<int, int> cDeme::GetCellPosition(int cellid) const 
+{
+	assert(cell_ids.GetSize()>0);
+	// Blatantly assumes that IDs are in monotonically increasing order!!
+	cellid -= cell_ids[0];
+	return std::make_pair(cellid % GetWidth(), cellid / GetWidth());
+}
+
+
 void cDeme::Reset() 
 {
   birth_count = 0; 

Modified: branches/dkdev/source/main/cDeme.h
===================================================================
--- branches/dkdev/source/main/cDeme.h	2007-03-01 20:59:08 UTC (rev 1379)
+++ branches/dkdev/source/main/cDeme.h	2007-03-03 21:42:02 UTC (rev 1380)
@@ -16,13 +16,15 @@
 
 #include <boost/graph/adjacency_list.hpp>
 #include <map>
+#include <utility>
 #include "tArray.h"
 
 
 class cDeme {
 public:
   //! An ease-of-use typedef to support the distributed construction of a network.
-  typedef boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS> Network;
+  typedef boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS,
+	std::pair<int, int> > Network;
   //! A map of cell IDs to vertex descriptors.
   typedef std::map<int, Network::vertex_descriptor> CellVertexMap;
   
@@ -34,6 +36,7 @@
   int GetSize() const { return cell_ids.GetSize(); }
   int GetCellID(int pos) const { return cell_ids[pos]; }
   int GetCellID(int x, int y) const;
+  std::pair<int, int> GetCellPosition(int cellid) const;
 
   int GetWidth() const { return width; }
   int GetHeight() const { return cell_ids.GetSize() / width; }

Modified: branches/dkdev/source/main/cPopulation.cc
===================================================================
--- branches/dkdev/source/main/cPopulation.cc	2007-03-01 20:59:08 UTC (rev 1379)
+++ branches/dkdev/source/main/cPopulation.cc	2007-03-03 21:42:02 UTC (rev 1380)
@@ -102,7 +102,7 @@
       deme_cells[offset] = cell_id;
       cell_array[cell_id].SetDemeID(deme_id);
     }
-    deme_array[deme_id].Setup(deme_cells);
+    deme_array[deme_id].Setup(deme_cells, deme_size_x);
   }
   
   

Modified: branches/dkdev/source/main/cStats.cc
===================================================================
--- branches/dkdev/source/main/cStats.cc	2007-03-01 20:59:08 UTC (rev 1379)
+++ branches/dkdev/source/main/cStats.cc	2007-03-03 21:42:02 UTC (rev 1380)
@@ -861,21 +861,34 @@
   m_topo_lastNetwork = network;
 }
 
+// Need to fix the vertices to contain the cell position.
 
+struct topo_vertex_writer {
+	topo_vertex_writer(cDeme::Network& network) : _network(network) { }
+	
+	template<typename VertexOrEdge>
+	void operator()(std::ostream& out, const VertexOrEdge& v) {
+		out << "[pos=\"" << boost::get(boost::vertex_bundle, _network)[v].first 
+		<< "," << boost::get(boost::vertex_bundle, _network)[v].second << "!\"]";
+	}
+	cDeme::Network& _network;
+};
+
+
 void cStats::PrintTopologyData(const cString& filename) {
 	cDataFile& df = m_world->GetDataFile(filename);
 	df.WriteComment( "Topology data\n" );
 	df.WriteTimeStamp();
 	df.Write(GetUpdate(), "update" );
-  df.Write(m_topo_numReplications, "Number of deme replications.");
-  df.Write(m_topo_numEdges.Average(), "Avg. number of edges on deme replication.");
-  m_topo_numReplications = 0;
-  m_topo_numEdges.Clear();
-  df.Endl();
+	df.Write(m_topo_numReplications, "Number of deme replications.");
+	df.Write(m_topo_numEdges.Average(), "Avg. number of edges on deme replication.");
+	m_topo_numReplications = 0;
+	m_topo_numEdges.Clear();
+	df.Endl();
   
-  std::stringstream netfile;
-  netfile << "./data/topo-" << GetUpdate() << ".dot";
-  std::ofstream outfile(netfile.str().c_str());
-  boost::write_graphviz(outfile, m_topo_lastNetwork);
-  outfile.close();
+	std::stringstream netfile;
+	netfile << "./data/topo-" << GetUpdate() << ".dot";
+	std::ofstream outfile(netfile.str().c_str());
+	boost::write_graphviz(outfile, m_topo_lastNetwork, topo_vertex_writer(m_topo_lastNetwork));
+	outfile.close();
 }




More information about the Avida-cvs mailing list