[Avida-SVN] r2021 - branches/energy/source/actions

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Tue Aug 28 11:50:39 PDT 2007


Author: beckma24
Date: 2007-08-28 14:50:39 -0400 (Tue, 28 Aug 2007)
New Revision: 2021

Modified:
   branches/energy/source/actions/PrintActions.cc
Log:
Added DumpSleepGrid print action

Modified: branches/energy/source/actions/PrintActions.cc
===================================================================
--- branches/energy/source/actions/PrintActions.cc	2007-08-28 16:09:11 UTC (rev 2020)
+++ branches/energy/source/actions/PrintActions.cc	2007-08-28 18:50:39 UTC (rev 2021)
@@ -2301,6 +2301,35 @@
   }
 };
 
+class cActionDumpSleepGrid : public cAction
+{
+private:
+  cString m_filename;
+  
+public:
+  cActionDumpSleepGrid(cWorld* world, const cString& args) : cAction(world, args), m_filename("")
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_filename = largs.PopWord();  
+  }
+  static const cString GetDescription() { return "Arguments: [string fname='']"; }
+  void Process(cAvidaContext& ctx)
+  {
+    cString filename(m_filename);
+    if (filename == "") filename.Set("grid_sleep.%d.dat", m_world->GetStats().GetUpdate());
+    ofstream& fp = m_world->GetDataFileOFStream(filename);
+    
+    for (int i = 0; i < m_world->GetPopulation().GetWorldY(); i++) {
+      for (int j = 0; j < m_world->GetPopulation().GetWorldX(); j++) {
+        cPopulationCell& cell = m_world->GetPopulation().GetCell(i * m_world->GetPopulation().GetWorldX() + j);
+        double cell_energy = (cell.IsOccupied()) ? cell.GetOrganism()->IsSleeping() : 0.0;
+        fp << cell_energy << " ";
+      }
+      fp << endl;
+    }
+    m_world->GetDataFileManager().Remove(filename);
+  }
+};
 
 class cActionDumpTaskGrid : public cAction
 {
@@ -2618,6 +2647,7 @@
   action_lib->Register<cActionDumpReceiverGrid>("DumpReceiverGrid");
   action_lib->Register<cActionDumpEnergyGrid>("DumpEnergyGrid");
   action_lib->Register<cActionDumpExecutionRatioGrid>("DumpExecutionRatioGrid");
+  action_lib->Register<cActionDumpSleepGrid>("DumpSleepGrid");
   
   // Print Settings
   action_lib->Register<cActionSetVerbose>("SetVerbose");




More information about the Avida-cvs mailing list