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

connel42 at myxo.css.msu.edu connel42 at myxo.css.msu.edu
Wed Aug 26 08:06:34 PDT 2009


Author: connel42
Date: 2009-08-26 11:06:33 -0400 (Wed, 26 Aug 2009)
New Revision: 3385

Modified:
   development/source/actions/EnvironmentActions.cc
   development/source/actions/PopulationActions.cc
   development/source/actions/PrintActions.cc
   development/source/main/cPopulation.cc
   development/source/main/cPopulation.h
   development/source/main/cStats.cc
   development/source/main/cStats.h
Log:
added some deme-level actions for tracking resource levels and resource-based migrations

Modified: development/source/actions/EnvironmentActions.cc
===================================================================
--- development/source/actions/EnvironmentActions.cc	2009-08-26 14:18:52 UTC (rev 3384)
+++ development/source/actions/EnvironmentActions.cc	2009-08-26 15:06:33 UTC (rev 3385)
@@ -464,6 +464,7 @@
       
       assert(m_inflow >= 0);
       assert(m_demeid >= 0);
+      assert(m_demeid < m_world->GetConfig().NUM_DEMES.Get());
       
     }
     
@@ -530,6 +531,7 @@
       assert(m_demeid >= 0);
       assert(m_outflow <= 1.0);
       assert(m_outflow >= 0.0);
+      assert(m_demeid < m_world->GetConfig().NUM_DEMES.Get());
     }
     
     static const cString GetDescription() { return "Arguments: <int deme id> <string resource_name> <int outflow>"; }

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2009-08-26 14:18:52 UTC (rev 3384)
+++ development/source/actions/PopulationActions.cc	2009-08-26 15:06:33 UTC (rev 3385)
@@ -3553,6 +3553,7 @@
             //migrate the organism from src_cell to dest cell
           }
           
+          m_world->GetStats().IncNumMigrations();
           
         }
         

Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2009-08-26 14:18:52 UTC (rev 3384)
+++ development/source/actions/PrintActions.cc	2009-08-26 15:06:33 UTC (rev 3385)
@@ -140,6 +140,7 @@
 STATS_OUT_FILE(PrintFlowRateTuples,         flow_rate_tuples.dat);
 STATS_OUT_FILE(PrintDynamicMaxMinData,		maxmin.dat			);
 STATS_OUT_FILE(PrintNumOrgsKilledData,      orgs_killed.dat);
+STATS_OUT_FILE(PrintMigrationData,      migration.dat);
 
 // reputation
 STATS_OUT_FILE(PrintReputationData,         reputation.dat);
@@ -2901,6 +2902,19 @@
   }
 };
 
+class cActionPrintDemeGlobalResources : public cAction
+  {
+  public:
+    cActionPrintDemeGlobalResources(cWorld* world, const cString& args) : cAction(world, args) { ; }
+    
+    static const cString GetDescription() { return "No Arguments"; }
+    
+    void Process(cAvidaContext& ctx)
+    {
+      m_world->GetPopulation().PrintDemeGlobalResources();
+    }
+  };
+
 class cActionSaveDemeFounders : public cAction
 {
 private:
@@ -2966,9 +2980,33 @@
   }
 };
 
+class cActionPrintNumOrgsInDeme : public cAction
+  {
+  public:
+    cActionPrintNumOrgsInDeme(cWorld* world, const cString& args) : cAction(world, args) { ; }
+    
+    static const cString GetDescription() { return "No Arguments"; }
+    
+    void Process(cAvidaContext& ctx)
+    {
+      cDataFile & df = m_world->GetDataFile("deme_org_count.dat");
+      df.WriteComment("Avida deme resource data");
+      df.WriteTimeStamp();
+      
+      cString UpdateStr = cStringUtil::Stringf( "deme_global_resources_%07i = [ ...", m_world->GetStats().GetUpdate());
+      df.WriteRaw(UpdateStr);      
+      
+      for (int d = 0; d < m_world->GetPopulation().GetNumDemes(); d++) {
+        cDeme& deme = m_world->GetPopulation().GetDeme(d);
+        df.WriteBlockElement(d, 0, 2);
+        df.WriteBlockElement(deme.GetOrgCount(), 1, 2);
+      }
+      
+      df.WriteRaw("];");
+    }
+  };
 
 
-
 void RegisterPrintActions(cActionLibrary* action_lib)
 {
   // Stats Out Files
@@ -3035,6 +3073,7 @@
   action_lib->Register<cActionPrintDemeSpacialEnergy>("PrintDemeSpacialEnergyStats");
   action_lib->Register<cActionPrintDemeSpacialSleep>("PrintDemeSpacialSleepStats");
   action_lib->Register<cActionPrintDemeResources>("PrintDemeResourceStats");
+  action_lib->Register<cActionPrintDemeGlobalResources>("PrintDemeGlobalResources");
   action_lib->Register<cActionPrintDemeReplicationData>("PrintDemeReplicationData");
   action_lib->Register<cActionPrintDemeTreatableReplicationData>("PrintDemeTreatableReplicationData");
   action_lib->Register<cActionPrintDemeUntreatableReplicationData>("PrintDemeUntreatableReplicationData");
@@ -3115,7 +3154,8 @@
   // Print Settings
   action_lib->Register<cActionSetVerbose>("SetVerbose");
   
-  action_lib->Register<cActionPrintNumOrgsKilledData>("PrintNumOrgsKilledData");//ZOOZ
+  action_lib->Register<cActionPrintNumOrgsKilledData>("PrintNumOrgsKilledData");
+  action_lib->Register<cActionPrintMigrationData>("PrintMigrationData");
 
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionPrintAverageData>("print_average_data");
@@ -3184,4 +3224,6 @@
 	action_lib->Register<cActionPrintHGTData>("PrintHGTData");
 	
   action_lib->Register<cActionSetVerbose>("VERBOSE");
+  
+  action_lib->Register<cActionPrintNumOrgsInDeme>("PrintNumOrgsInDeme");
 }

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2009-08-26 14:18:52 UTC (rev 3384)
+++ development/source/main/cPopulation.cc	2009-08-26 15:06:33 UTC (rev 3385)
@@ -3145,6 +3145,39 @@
   df_resources.Endl();
 }
 
+//Write deme global resource levels to a file that can be easily read into Matlab.
+//Each time this runs, a Matlab array is created that contains an array.  Each row in the array contains <deme id> <res level 0> ... <res level n>
+void cPopulation::PrintDemeGlobalResources() {
+  const int num_demes = deme_array.GetSize();
+  cDataFile & df = m_world->GetDataFile("deme_global_resources.dat");
+  df.WriteComment("Avida deme resource data");
+  df.WriteTimeStamp();
+  
+  cString UpdateStr = cStringUtil::Stringf( "deme_global_resources_%07i = [ ...", m_world->GetStats().GetUpdate());
+  df.WriteRaw(UpdateStr);
+  
+  for (int deme_id = 0; deme_id < num_demes; deme_id++) {
+    cDeme & cur_deme = deme_array[deme_id];
+    cur_deme.UpdateDemeRes();
+    
+    const cResourceCount & res = GetDeme(deme_id).GetDemeResourceCount();
+    const int num_res = res.GetSize();
+    
+    df.WriteBlockElement(deme_id, 0, num_res + 1);
+
+    for(int r = 0; r < num_res; r++) {
+      if(!res.IsSpatial(r)) {
+        df.WriteBlockElement(res.Get(r), r + 1, num_res + 1);
+      }
+      
+    } //End iterating through resources
+        
+  } //End iterating through demes
+  
+  df.WriteRaw("];");
+}
+
+
 // Write spatial energy data to a file that can easily be read into Matlab
 void cPopulation::PrintDemeSpatialEnergyData() const {
   int cellID = 0;

Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h	2009-08-26 14:18:52 UTC (rev 3384)
+++ development/source/main/cPopulation.h	2009-08-26 15:06:33 UTC (rev 3385)
@@ -247,6 +247,7 @@
   void PrintDemeMutationRate();
   void PrintDemeReceiver();
   void PrintDemeResource();
+  void PrintDemeGlobalResources();
   void PrintDemeSpatialResData(const cResourceCount& res, const int i, const int deme_id) const;
   void PrintDemeSpatialEnergyData() const;
   void PrintDemeSpatialSleepData() const;

Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc	2009-08-26 14:18:52 UTC (rev 3384)
+++ development/source/main/cStats.cc	2009-08-26 15:06:33 UTC (rev 3385)
@@ -134,6 +134,7 @@
   , m_spec_num(0)
   , m_spec_waste(0)
   , num_orgs_killed(0)
+  , num_migrations(0)
   , m_deme_num_repls(0)
 	, m_deme_num_repls_treatable(0)
 	, m_deme_num_repls_untreatable(0)
@@ -567,6 +568,7 @@
   m_spec_waste = 0;
   
   num_orgs_killed = 0;
+  num_migrations = 0;
 }
 
 void cStats::RemoveLineage(int id_num, int parent_id, int update_born, double generation_born, int total_CPUs,
@@ -2329,7 +2331,20 @@
   df.Endl();
 } //End PrintNumOrgsKilledData()
 
+void cStats::PrintMigrationData(const cString& filename)
+{
+  cDataFile& df = m_world->GetDataFile(filename);
+  
+  df.WriteComment("Number of migrations made using the migratedemes event");
+  df.WriteTimeStamp();
+  df.WriteComment("First column is the current update and the second column lists the number of migrations made");
+  
+  df.Write(m_update,   "Update");
+  df.Write(num_migrations, "Num Migrations");
+  df.Endl();
+} //End PrintMigrationData()
 
+
 /* Print information pertinent to direct reciprocity experiments*/
 void cStats::PrintDirectReciprocityData(const cString& filename){
 	cDataFile& df = m_world->GetDataFile(filename);

Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h	2009-08-26 14:18:52 UTC (rev 3384)
+++ development/source/main/cStats.h	2009-08-26 15:06:33 UTC (rev 3385)
@@ -331,6 +331,9 @@
   // Number of organisms killed by kill actions
   int num_orgs_killed;
   
+  // Number of migrations that have been made
+  int num_migrations;
+  
 
   cStats(); // @not_implemented
   cStats(const cStats&); // @not_implemented
@@ -560,6 +563,7 @@
   void IncExecuted() { num_executed++; }
   
   void IncNumOrgsKilled() { num_orgs_killed++; }
+  void IncNumMigrations() { num_migrations++; }
 
   void AddCurTask(int task_num) { task_cur_count[task_num]++; }
   void AddCurTaskQuality(int task_num, double quality) 
@@ -729,6 +733,7 @@
   int GetSpeculativeWaste() const { return m_spec_waste; }
   
   int GetNumOrgsKilled() const { return num_orgs_killed; }
+  int GetNumMigrations() const { return num_migrations; }
 
   // this value gets recorded when a creature with the particular
   // fitness value gets born. It will never change to a smaller value,
@@ -777,6 +782,7 @@
   void PrintCellVisitsData(const cString& filename);
   void PrintExtendedTimeData(const cString& filename);
   void PrintNumOrgsKilledData(const cString& filename);
+  void PrintMigrationData(const cString& filename);
   void PrintGroupsFormedData(const cString& filename);
 	void PrintGroupIds(const cString& filename);
   




More information about the Avida-cvs mailing list