[Avida-SVN] r1875 - in branches/energy_dev/source: actions main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Tue Jul 31 13:08:51 PDT 2007


Author: beckma24
Date: 2007-07-31 16:08:51 -0400 (Tue, 31 Jul 2007)
New Revision: 1875

Modified:
   branches/energy_dev/source/actions/PrintActions.cc
   branches/energy_dev/source/main/cDeme.cc
   branches/energy_dev/source/main/cDeme.h
   branches/energy_dev/source/main/cPopulation.cc
   branches/energy_dev/source/main/cPopulation.h
   branches/energy_dev/source/main/cResource.h
Log:
Added relative cell referencing to deme-level resources

Modified: branches/energy_dev/source/actions/PrintActions.cc
===================================================================
--- branches/energy_dev/source/actions/PrintActions.cc	2007-07-31 16:40:28 UTC (rev 1874)
+++ branches/energy_dev/source/actions/PrintActions.cc	2007-07-31 20:08:51 UTC (rev 1875)
@@ -2348,10 +2348,10 @@
   action_lib->Register<cActionPrintPhenotypeStatus>("PrintPhenotypeStatus");
   action_lib->Register<cActionPrintDemeStats>("PrintDemeStats");
 	
-	//Coalescence Clade Actions
-	action_lib->Register<cActionPrintCCladeCounts>("PrintCCladeCounts");
+  //Coalescence Clade Actions
+  action_lib->Register<cActionPrintCCladeCounts>("PrintCCladeCounts");
   action_lib->Register<cActionPrintCCladeFitnessHistogram>("PrintCCladeFitnessHistogram");
-	action_lib->Register<cActionPrintCCladeRelativeFitnessHistogram>("PrintCCladeRelativeFitnessHistogram");
+  action_lib->Register<cActionPrintCCladeRelativeFitnessHistogram>("PrintCCladeRelativeFitnessHistogram");
 	
   
   // Processed Data
@@ -2366,8 +2366,8 @@
   action_lib->Register<cActionPrintDominantGenotype>("PrintDominantGenotype");
   action_lib->Register<cActionPrintDominantParasiteGenotype>("PrintDominantParasiteGenotype");
   action_lib->Register<cActionPrintDetailedFitnessData>("PrintDetailedFitnessData");
-	action_lib->Register<cActionPrintLogFitnessHistogram>("PrintLogFitnessHistogram");
-	action_lib->Register<cActionPrintRelativeFitnessHistogram>("PrintRelativeFitnessHistogram");
+  action_lib->Register<cActionPrintLogFitnessHistogram>("PrintLogFitnessHistogram");
+  action_lib->Register<cActionPrintRelativeFitnessHistogram>("PrintRelativeFitnessHistogram");
   action_lib->Register<cActionPrintGeneticDistanceData>("PrintGeneticDistanceData");
   action_lib->Register<cActionPrintPopulationDistanceData>("PrintPopulationDistanceData");
   action_lib->Register<cActionPrintDebug>("PrintDebug");
@@ -2379,7 +2379,7 @@
   action_lib->Register<cActionPrintViableTasksData>("PrintViableTasksData");
   action_lib->Register<cActionPrintTreeDepths>("PrintTreeDepths");
   
-	action_lib->Register<cActionPrintGenomicSiteEntropy>("PrintGenomicSiteEntropy");
+  action_lib->Register<cActionPrintGenomicSiteEntropy>("PrintGenomicSiteEntropy");
 	
   // Grid Information Dumps
   action_lib->Register<cActionDumpMemory>("DumpMemory");

Modified: branches/energy_dev/source/main/cDeme.cc
===================================================================
--- branches/energy_dev/source/main/cDeme.cc	2007-07-31 16:40:28 UTC (rev 1874)
+++ branches/energy_dev/source/main/cDeme.cc	2007-07-31 20:08:51 UTC (rev 1875)
@@ -22,6 +22,7 @@
  */
 
 #include "cDeme.h"
+#include "cResource.h"
 
 
 void cDeme::Setup(const tArray<int> & in_cells, int in_width)
@@ -61,14 +62,9 @@
 {
   birth_count = 0; 
   _age = 0;
-  
   deme_resource_count.ReinitializeResources();
 }
 
-/*void cDeme::ResetResources() {
-  
-}*/
-
 /*! Replacing this deme's germline has the effect of changing the deme's lineage.
 There's still some work to do here; the lineage labels of the Genomes in the germline
 are all messed up.
@@ -78,3 +74,25 @@
 void cDeme::ReplaceGermline(const cGermline& germline) {
 	_germline = germline;
 }
+
+void cDeme::ModifyDemeResCount(const tArray<double> & res_change, const int absolute_cell_id) {
+  // find relative cell_id in deme resource count
+  const int relative_cell_id = absolute_cell_id % GetSize();  //assumes all demes are the same size
+  deme_resource_count.ModifyCell(res_change, relative_cell_id);
+}
+
+void cDeme::SetupDemeRes(int id, cResource * res, int verbosity) {
+  const double decay = 1.0 - res->GetOutflow();
+  //addjust the resources cell list pointer here if we want CELL env. commands to be replicated in each deme
+  
+  deme_resource_count.Setup(id, res->GetName(), res->GetInitial(), 
+                           res->GetInflow(), decay,
+                           res->GetGeometry(), res->GetXDiffuse(),
+                           res->GetXGravity(), res->GetYDiffuse(), 
+                           res->GetYGravity(), res->GetInflowX1(), 
+                           res->GetInflowX2(), res->GetInflowY1(), 
+                           res->GetInflowY2(), res->GetOutflowX1(), 
+                           res->GetOutflowX2(), res->GetOutflowY1(), 
+                           res->GetOutflowY2(), res->GetCellListPtr(),
+                           verbosity);
+}

Modified: branches/energy_dev/source/main/cDeme.h
===================================================================
--- branches/energy_dev/source/main/cDeme.h	2007-07-31 16:40:28 UTC (rev 1874)
+++ branches/energy_dev/source/main/cDeme.h	2007-07-31 20:08:51 UTC (rev 1875)
@@ -29,6 +29,7 @@
 #include "cResourceCount.h"
 #include "cStringList.h"
 
+class cResource;
 
 /*! Demes are groups of cells in the population that are somehow bound together
 as a unit.  The deme object is used from within cPopulation to manage these 
@@ -88,8 +89,11 @@
     updates since the last time Reset() was called. */
   int GetAge() const { return _age; }
   
-  cResourceCount& GetDemeResourceCount() { return deme_resource_count; }
-//  void SetDemeResourceCount(cResourceCount in_res_count) { deme_resource_count = in_res_count; }
+  const cResourceCount& GetDemeResourceCount() const { return deme_resource_count; }
+  void SetDemeResourceCount(const cResourceCount in_res) { deme_resource_count = in_res; }
+  void ResizeSpatialGrids(const int in_x, const int in_y) { deme_resource_count.ResizeSpatialGrids(in_x, in_y); }
+  void ModifyDemeResCount(const tArray<double> & res_change, const int absolute_cell_id);
+  void SetupDemeRes(int id, cResource * res, int verbosity);
 };
 
 #endif

Modified: branches/energy_dev/source/main/cPopulation.cc
===================================================================
--- branches/energy_dev/source/main/cPopulation.cc	2007-07-31 16:40:28 UTC (rev 1874)
+++ branches/energy_dev/source/main/cPopulation.cc	2007-07-31 20:08:51 UTC (rev 1875)
@@ -187,7 +187,6 @@
     if(res->GetDemeResource())
       num_deme_res++;
   }
-  cerr<< resource_lib.GetSize() << " " << num_deme_res << endl;
   
   cResourceCount tmp_res_count(resource_lib.GetSize() - num_deme_res);
   resource_count = tmp_res_count;
@@ -195,9 +194,12 @@
   
   for(int i = 0; i < GetNumDemes(); i++) {
     cResourceCount tmp_deme_res_count(num_deme_res);
-    GetDeme(i).GetDemeResourceCount() = tmp_deme_res_count;
+    GetDeme(i).SetDemeResourceCount(tmp_deme_res_count);
     //TODO: make sure grid is the right grid/size
-    GetDeme(i).GetDemeResourceCount().ResizeSpatialGrids(world_x, world_y);
+    //GetDeme(i).GetDemeResourceCount().ResizeSpatialGrids(world_x, world_y);
+
+    GetDeme(i).ResizeSpatialGrids(deme_size_x, deme_size_y);
+//    GetDeme(i).GetDemeResourceCount().
   }
 
   for (int i = 0; i < resource_lib.GetSize(); i++) {
@@ -218,18 +220,8 @@
       m_world->GetStats().SetResourceName(global_res_index, res->GetName());
     } else if(res->GetDemeResource()) {
       deme_res_index++;
-      const double decay = 1.0 - res->GetOutflow();
       for(int j = 0; j < GetNumDemes(); j++) {
-        GetDeme(j).GetDemeResourceCount().Setup(global_res_index, res->GetName(), res->GetInitial(), 
-                                                res->GetInflow(), decay,
-                                                res->GetGeometry(), res->GetXDiffuse(),
-                                                res->GetXGravity(), res->GetYDiffuse(), 
-                                                res->GetYGravity(), res->GetInflowX1(), 
-                                                res->GetInflowX2(), res->GetInflowY1(), 
-                                                res->GetInflowY2(), res->GetOutflowX1(), 
-                                                res->GetOutflowX2(), res->GetOutflowY1(), 
-                                                res->GetOutflowY2(), res->GetCellListPtr(),
-                                                world->GetVerbosity() );
+        GetDeme(j).SetupDemeRes(deme_res_index, res, world->GetVerbosity());
         // could add deme resources to global resource stats here
       }
     } else {
@@ -1581,6 +1573,11 @@
       //comment.Set(cStringUtil::Stringf("Deme %d Resources %d", deme_id, res.GetResName(j)));
       const char * tmp = res.GetResName(j);
       df_resources.Write(res.Get(j), cStringUtil::Stringf("Deme %d Resources %s", deme_id, tmp)); //comment);
+      
+      if ((res.GetResourcesGeometry())[j] != nGeometry::GLOBAL) {
+        PrintDemeSpatialResData(res, j);
+      }
+
     }
   } 
   
@@ -1598,6 +1595,33 @@
 }
 
 
+void cPopulation::PrintDemeSpatialResData( cResourceCount res, const int i)
+{
+
+  // Write spatial data to a file that can easily be read into Matlab
+
+  cString tmpfilename = "deme_spacial_resource_";
+  tmpfilename +=  res.GetResName(i) + ".m";
+  cDataFile& df = m_world->GetDataFile(tmpfilename);
+  cString UpdateStr = cStringUtil::Stringf( "deme_%07i_", i ) + res.GetResName(i) + 
+                      cStringUtil::Stringf( "%07i", m_world->GetStats().GetUpdate() ) + " = [ ...";
+
+  df.WriteRaw(UpdateStr);
+
+  cSpatialResCount sp_res = res.GetSpatialResource(i);
+  int gridsize = sp_res.GetSize();
+  int xsize = m_world->GetConfig().WORLD_X.Get();
+
+  // write grid to file
+
+  for (int j = 0; j < gridsize; j++) {
+    df.WriteBlockElement(sp_res.GetAmount(j), j, xsize);
+  }
+  df.WriteRaw("];");
+}
+
+
+
 /**
 * This function is responsible for adding an organism to a given lineage,
  * and setting the organism's lineage label and the lineage pointer.
@@ -2473,20 +2497,10 @@
   resource_count.ModifyCell(res_change, cell_id);
 }
 
-void cPopulation::UpdateDemeResources(const tArray<double> & res_change, int deme_id)
-{
-  GetDeme(deme_id).GetDemeResourceCount().Modify(res_change);
-}
-
-void cPopulation::UpdateDemeResource(int id, double change, int deme_id)
-{
-  GetDeme(deme_id).GetDemeResourceCount().Modify(id, change);
-}
-
 void cPopulation::UpdateDemeCellResources(const tArray<double> & res_change, 
                                           const int cell_id)
 {
-  GetDeme(GetCell(cell_id).GetDemeID()).GetDemeResourceCount().ModifyCell(res_change, cell_id);
+  GetDeme(GetCell(cell_id).GetDemeID()).ModifyDemeResCount(res_change, cell_id);
 }
 
 void cPopulation::SetResource(int id, double new_level)

Modified: branches/energy_dev/source/main/cPopulation.h
===================================================================
--- branches/energy_dev/source/main/cPopulation.h	2007-07-31 16:40:28 UTC (rev 1874)
+++ branches/energy_dev/source/main/cPopulation.h	2007-07-31 20:08:51 UTC (rev 1875)
@@ -180,7 +180,8 @@
   void CopyDeme(int deme1_id, int deme2_id);
   void SpawnDeme(int deme1_id, int deme2_id=-1);
   void PrintDemeStats();
-
+  void PrintDemeSpatialResData( cResourceCount res, const int i);
+  
   // Print donation stats
   void PrintDonationStats();
 
@@ -219,8 +220,6 @@
   void UpdateResources(const tArray<double>& res_change);
   void UpdateResource(int id, double change);
   void UpdateCellResources(const tArray<double>& res_change, const int cell_id);
-  void UpdateDemeResources(const tArray<double> & res_change, int deme_id);
-  void UpdateDemeResource(int id, double change, int deme_id);
   void UpdateDemeCellResources(const tArray<double>& res_change, const int cell_id);
 
   void SetResource(int id, double new_level);

Modified: branches/energy_dev/source/main/cResource.h
===================================================================
--- branches/energy_dev/source/main/cResource.h	2007-07-31 16:40:28 UTC (rev 1874)
+++ branches/energy_dev/source/main/cResource.h	2007-07-31 20:08:51 UTC (rev 1875)
@@ -23,7 +23,7 @@
  *
  */
 
-/*! Classes to held global and local information about a given resource */
+/*! Classes to hold global and local information about a given resource */
 
 #ifndef cResource_h
 #define cResource_h




More information about the Avida-cvs mailing list