[Avida-SVN] r3150 - in development/source: actions main

connel42 at myxo.css.msu.edu connel42 at myxo.css.msu.edu
Thu Feb 19 08:19:24 PST 2009


Author: connel42
Date: 2009-02-19 11:19:24 -0500 (Thu, 19 Feb 2009)
New Revision: 3150

Modified:
   development/source/actions/PrintActions.cc
   development/source/main/cPopulation.cc
   development/source/main/cPopulation.h
Log:
Added event to print the distribution of energy among organisms

Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2009-02-16 15:01:25 UTC (rev 3149)
+++ development/source/actions/PrintActions.cc	2009-02-19 16:19:24 UTC (rev 3150)
@@ -2556,17 +2556,30 @@
 };
 
 class cActionPrintDemeEnergySharingStats : public cAction
+{
+public:
+  cActionPrintDemeEnergySharingStats(cWorld* world, const cString& args) : cAction(world, args) { ; }
+    
+  static const cString GetDescription() { return "No Arguments"; }
+    
+  void Process(cAvidaContext& ctx)
   {
-  public:
-    cActionPrintDemeEnergySharingStats(cWorld* world, const cString& args) : cAction(world, args) { ; }
+    m_world->GetPopulation().PrintDemeEnergySharingStats();
+  }
+};
+
+class cActionPrintDemeEnergyDistributionStats : public cAction
+{
+public:
+  cActionPrintDemeEnergyDistributionStats(cWorld* world, const cString& args) : cAction(world, args) { ; }
     
-    static const cString GetDescription() { return "No Arguments"; }
+  static const cString GetDescription() { return "No Arguments"; }
     
-    void Process(cAvidaContext& ctx)
-    {
-      m_world->GetPopulation().PrintDemeEnergySharingStats();
-    }
-  };
+  void Process(cAvidaContext& ctx)
+  {
+    m_world->GetPopulation().PrintDemeEnergyDistributionStats();
+  }
+};
 
 class cActionPrintDemeDonorStats : public cAction
 {
@@ -2747,6 +2760,7 @@
   action_lib->Register<cActionPrintDemeAllStats>("PrintDemeStats"); //duplicate of previous
   action_lib->Register<cActionPrintDemesTotalAvgEnergy>("PrintDemesTotalAvgEnergy");
   action_lib->Register<cActionPrintDemeEnergySharingStats>("PrintDemeEnergySharingStats");
+  action_lib->Register<cActionPrintDemeEnergyDistributionStats>("PrintDemeEnergyDistributionStats");
   action_lib->Register<cActionPrintDemeDonorStats>("PrintDemeDonorStats");
   action_lib->Register<cActionPrintDemeSpacialEnergy>("PrintDemeSpacialEnergyStats");
   action_lib->Register<cActionPrintDemeSpacialSleep>("PrintDemeSpacialSleepStats");

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2009-02-16 15:01:25 UTC (rev 3149)
+++ development/source/main/cPopulation.cc	2009-02-19 16:19:24 UTC (rev 3150)
@@ -2631,7 +2631,6 @@
 
 // Print some stats about the energy sharing behavior of each deme
 void cPopulation::PrintDemeEnergySharingStats() {
-  //TODO: BDC: move this from covering the population to per deme or deme average
   const int num_demes = deme_array.GetSize();
   cStats& stats = m_world->GetStats();
   cDataFile & df_donor = m_world->GetDataFile("deme_energy_sharing.dat");
@@ -2679,9 +2678,59 @@
   df_donor.Write(amount_applied/num_demes, "Average total amount of donated energy applied per deme");
   df_donor.Endl();  
   
-}
+} //End PrintDemeEnergySharingStats()
 
 
+// Print some stats about the distribution of energy among organisms in a deme
+void cPopulation::PrintDemeEnergyDistributionStats() {
+  const int num_demes = deme_array.GetSize();
+  cStats& stats = m_world->GetStats();
+  cString comment;
+  
+  cDoubleSum deme_energy_distribution;
+
+  cDoubleSum overall_average;
+  cDoubleSum overall_variance;
+  cDoubleSum overall_stddev;
+  
+  cDataFile & df_dist = m_world->GetDataFile("deme_energy_distribution.dat");
+  comment.Set("Average distribution of energy among organisms in each of %d %d x %d demes", num_demes, m_world->GetConfig().WORLD_X.Get(), m_world->GetConfig().WORLD_Y.Get()/num_demes);
+  df_dist.WriteComment(comment);
+  df_dist.WriteTimeStamp();
+  df_dist.Write(stats.GetUpdate(), "Update");
+      
+  for (int deme_id = 0; deme_id < num_demes; deme_id++) {
+    const cDeme & cur_deme = deme_array[deme_id];
+    
+    for (int i = 0; i < cur_deme.GetSize(); i++) {
+      
+      int cur_cell = cur_deme.GetCellID(i);
+      if (cell_array[cur_cell].IsOccupied() == false) {
+        //TODO: BDC: Get energy of cell and add that instead
+        deme_energy_distribution.Add(cur_deme.GetCellEnergy(cur_cell));
+        continue;
+      }
+      //TODO: add 0 for this deme
+      
+      deme_energy_distribution.Add(GetCell(cur_cell).GetOrganism()->GetPhenotype().GetStoredEnergy());
+    }
+    
+    overall_average.Add(deme_energy_distribution.Average());
+    overall_variance.Add(deme_energy_distribution.Variance());
+    overall_stddev.Add(deme_energy_distribution.StdDeviation());
+    deme_energy_distribution.Clear();
+  
+  }
+  
+  df_dist.Write(overall_average.Average(), "Average of Average Energy Level");
+  df_dist.Write(overall_variance.Average(), "Average of Energy Level Variance");
+  df_dist.Write(overall_stddev.Average(), "Average of Energy Level Standard Deviations");
+  
+  df_dist.Endl();
+  
+} //End PrintDemeEnergyDistributionStats()
+
+
 void cPopulation::PrintDemeDonor() {
   cStats& stats = m_world->GetStats();
   const int num_demes = deme_array.GetSize();

Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h	2009-02-16 15:01:25 UTC (rev 3149)
+++ development/source/main/cPopulation.h	2009-02-19 16:19:24 UTC (rev 3150)
@@ -230,6 +230,7 @@
   void PrintDemeAllStats();
   void PrintDemeTestamentStats(const cString& filename);
   void PrintDemeEnergySharingStats();
+  void PrintDemeEnergyDistributionStats();
   void PrintDemeDonor();
   void PrintDemeFitness();
   void PrintDemeGestationTime();




More information about the Avida-cvs mailing list