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

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Wed Sep 26 15:39:32 PDT 2007


Author: dknoester
Date: 2007-09-26 18:39:32 -0400 (Wed, 26 Sep 2007)
New Revision: 2113

Modified:
   branches/dkdev/source/actions/PrintActions.cc
   branches/dkdev/source/main/cAvidaConfig.h
   branches/dkdev/source/main/cDeme.cc
   branches/dkdev/source/main/cDeme.h
   branches/dkdev/source/main/cStats.cc
   branches/dkdev/source/main/cStats.h
Log:
Added output for location of two-cells; added minimum required region size between two-cells.

Modified: branches/dkdev/source/actions/PrintActions.cc
===================================================================
--- branches/dkdev/source/actions/PrintActions.cc	2007-09-26 17:44:23 UTC (rev 2112)
+++ branches/dkdev/source/actions/PrintActions.cc	2007-09-26 22:39:32 UTC (rev 2113)
@@ -68,6 +68,7 @@
 STATS_OUT_FILE(PrintDemeData, deme.dat);
 STATS_OUT_FILE(PrintCollectionData, collection.dat);
 STATS_OUT_FILE(PrintTwoCellsData, twocells.dat);
+STATS_OUT_FILE(PrintTwoCellsLocations, location.dat);
 
 
 
@@ -1565,6 +1566,7 @@
   
   // Two-cells
   action_lib->Register<cActionPrintTwoCellsData>("PrintTwoCellsData");
+  action_lib->Register<cActionPrintTwoCellsLocations>("PrintTwoCellsLocations");
 
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionPrintAverageData>("print_average_data");

Modified: branches/dkdev/source/main/cAvidaConfig.h
===================================================================
--- branches/dkdev/source/main/cAvidaConfig.h	2007-09-26 17:44:23 UTC (rev 2112)
+++ branches/dkdev/source/main/cAvidaConfig.h	2007-09-26 22:39:32 UTC (rev 2113)
@@ -169,6 +169,8 @@
   CONFIG_ADD_VAR(GERMLINE_RANDOM_PLACEMENT, int, 0, "Whether the seed for a germline is placed randomly within the deme; 0=no.");
   CONFIG_ADD_VAR(MAX_DEME_AGE, int, 500, "The maximum age of a deme (in updates) to be used for age-based replication (default=500).");
   CONFIG_ADD_VAR(TRACK_GENOTYPES, int, 0, "Whether genotypes are tracked graphically.");
+  CONFIG_ADD_VAR(TWOCELLS_MIN_REGION_RATIO, double, 0.2, "Ratio of size of two-cells region to environment size.");
+  
   CONFIG_ADD_VAR(RANDOM_SEED, int, 0, "Random number seed (0 for based on time)");
   CONFIG_ADD_VAR(HARDWARE_TYPE, int, 0, "0 = Original CPUs\n1 = New SMT CPUs\n2 = Transitional SMT");
   

Modified: branches/dkdev/source/main/cDeme.cc
===================================================================
--- branches/dkdev/source/main/cDeme.cc	2007-09-26 17:44:23 UTC (rev 2112)
+++ branches/dkdev/source/main/cDeme.cc	2007-09-26 22:39:32 UTC (rev 2113)
@@ -32,18 +32,21 @@
 {
   _world = world;
   cell_ids = in_cells;
-  _cellsToLink = std::make_pair(cell_ids[_world->GetRandom().GetInt(cell_ids.GetSize())],
-                                cell_ids[_world->GetRandom().GetInt(cell_ids.GetSize())]);
-  while(_cellsToLink.second == _cellsToLink.first) {
-    _cellsToLink.second = cell_ids[_world->GetRandom().GetInt(cell_ids.GetSize())];
-  }
   birth_count = 0;
   org_count = 0;
-
+  
   // If width is negative, set it to the full number of cells.
   width = in_width;
   if (width < 1) width = cell_ids.GetSize();
   
+  _cellsToLink = std::make_pair(cell_ids[_world->GetRandom().GetInt(cell_ids.GetSize())],
+                                cell_ids[_world->GetRandom().GetInt(cell_ids.GetSize())]);
+  while((_cellsToLink.second == _cellsToLink.first) 
+        || (((double)region_size(GetCellPosition(_cellsToLink.first), GetCellPosition(_cellsToLink.second))
+             / GetSize()) < _world->GetConfig().TWOCELLS_MIN_REGION_RATIO.Get())) {
+    _cellsToLink.second = cell_ids[_world->GetRandom().GetInt(cell_ids.GetSize())];
+  }
+  
   // Load up the map of random cell ids.
   if(_cellsToMsgCount.size()==0) {
     for(int i=0; i<cell_ids.GetSize(); ++i) {
@@ -236,3 +239,11 @@
   // Clustering coefficient:
   return std::accumulate(cluster_coeffs.begin(), cluster_coeffs.end(), 0.0) / cluster_coeffs.size();
 }
+
+
+unsigned int region_size(const std::pair<int,int>& one_xy, const std::pair<int,int>& two_xy) {
+  return (std::max(one_xy.first, two_xy.first) - std::min(one_xy.first, two_xy.first)+1)
+    * (std::max(one_xy.second, two_xy.second) - std::min(one_xy.second, two_xy.second)+1);
+}
+
+

Modified: branches/dkdev/source/main/cDeme.h
===================================================================
--- branches/dkdev/source/main/cDeme.h	2007-09-26 17:44:23 UTC (rev 2112)
+++ branches/dkdev/source/main/cDeme.h	2007-09-26 22:39:32 UTC (rev 2113)
@@ -159,4 +159,6 @@
 double clustering_coefficient(cDeme::Network& network);
 //! Returns a matrix of all-pairs distances.
 cDeme::DistanceMatrix all_pairs_distances(cDeme::Network& network);
+//! Returns the size of the region between the two passed-in cells (units are in cells).
+unsigned int region_size(const std::pair<int,int>& one_xy, const std::pair<int,int>& two_xy);
 #endif

Modified: branches/dkdev/source/main/cStats.cc
===================================================================
--- branches/dkdev/source/main/cStats.cc	2007-09-26 17:44:23 UTC (rev 2112)
+++ branches/dkdev/source/main/cStats.cc	2007-09-26 22:39:32 UTC (rev 2113)
@@ -1085,3 +1085,28 @@
   _two_cells_unlatched = 0;
   _two_cells_correct = 0;
 }
+
+
+/*! Prints the locations and relative sizes of the different regions represented by the
+randomly selected cells in the population. */
+void cStats::PrintTwoCellsLocations(const cString& filename) {
+  cDataFile& df = m_world->GetDataFile(filename);
+  cPopulation& pop = m_world->GetPopulation();
+  df.WriteComment("Two-cells region size and cell location information.");
+  df.WriteTimeStamp();
+  
+  for(int i=0; i<pop.GetNumDemes(); ++i) {
+    cDeme& deme = pop.GetDeme(i);
+    std::pair<int,int> cell_one = deme.GetCellPosition(deme.GetCellsToLink().first);
+    std::pair<int,int> cell_two = deme.GetCellPosition(deme.GetCellsToLink().second);
+    df.Write(i, "deme id [deme_id]");
+    df.Write(deme.GetSize(), "total environment size [env_size]");
+    df.Write((int)region_size(cell_one, cell_two), "region size [region_size]");
+    df.Write((double)region_size(cell_one,cell_two)/deme.GetSize(), "fractional region size [frac_size]");
+    df.Write(cell_one.first, "cell one x [one_x]");
+    df.Write(cell_one.second, "cell one y [one_y]");
+    df.Write(cell_two.first, "cell two x [two_x]");
+    df.Write(cell_two.second, "cell two y [two_y]");
+    df.Endl();
+  }  
+}

Modified: branches/dkdev/source/main/cStats.h
===================================================================
--- branches/dkdev/source/main/cStats.h	2007-09-26 17:44:23 UTC (rev 2112)
+++ branches/dkdev/source/main/cStats.h	2007-09-26 22:39:32 UTC (rev 2113)
@@ -623,6 +623,7 @@
   void TwoCellsRegionLatched(bool correct);
   void TwoCellsRegionUnlatched();
   void PrintTwoCellsData(const cString& filename);
+  void PrintTwoCellsLocations(const cString& filename);
 
 private:
   int _two_cells_latched; //!< Count of organisms that have latched their region and called IO.




More information about the Avida-cvs mailing list