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

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Tue Jul 24 13:13:30 PDT 2007


Author: beckma24
Date: 2007-07-24 16:13:30 -0400 (Tue, 24 Jul 2007)
New Revision: 1843

Modified:
   branches/energy_dev/source/actions/PrintActions.cc
   branches/energy_dev/source/cpu/cHardwareBase.cc
   branches/energy_dev/source/cpu/cHardwareCPU.cc
   branches/energy_dev/source/main/cDeme.cc
   branches/energy_dev/source/main/cPopulation.cc
   branches/energy_dev/source/main/cPopulation.h
   branches/energy_dev/source/main/cStats.cc
   branches/energy_dev/source/main/cStats.h
Log:
Moved sleep stats to cStats.  Added PrintSleepData

Modified: branches/energy_dev/source/actions/PrintActions.cc
===================================================================
--- branches/energy_dev/source/actions/PrintActions.cc	2007-07-24 20:08:23 UTC (rev 1842)
+++ branches/energy_dev/source/actions/PrintActions.cc	2007-07-24 20:13:30 UTC (rev 1843)
@@ -87,6 +87,7 @@
 STATS_OUT_FILE(PrintMarketData,             market.dat          );
 STATS_OUT_FILE(PrintSenseData,              sense.dat           );
 STATS_OUT_FILE(PrintSenseExeData,           sense_exe.dat       );
+STATS_OUT_FILE(PrintSleepData,              sleep.dat          );
 
 
 #define POP_OUT_FILE(METHOD, DEFAULT)                                                     /*  1 */ \
@@ -2340,6 +2341,7 @@
   action_lib->Register<cActionPrintMarketData>("PrintMarketData");
   action_lib->Register<cActionPrintSenseData>("PrintSenseData");
   action_lib->Register<cActionPrintSenseExeData>("PrintSenseExeData");
+  action_lib->Register<cActionPrintSleepData>("PrintSleepData");
 
   // Population Out Files
   action_lib->Register<cActionPrintPhenotypeData>("PrintPhenotypeData");

Modified: branches/energy_dev/source/cpu/cHardwareBase.cc
===================================================================
--- branches/energy_dev/source/cpu/cHardwareBase.cc	2007-07-24 20:08:23 UTC (rev 1842)
+++ branches/energy_dev/source/cpu/cHardwareBase.cc	2007-07-24 20:13:30 UTC (rev 1843)
@@ -730,9 +730,9 @@
 #if INSTRUCTION_COSTS
   assert(cur_inst.GetOp() < inst_cost.GetSize());
   
-  // check avaliable energy first
+  // TODO:  Get rid of magic number. check avaliable energy first
   double energy_req = inst_energy_cost[cur_inst.GetOp()] * (organism->GetPhenotype().GetMerit().GetDouble() / 100.0); //compensate by factor of 100
-  
+
   if(m_world->GetConfig().ENERGY_ENABLED.Get() > 0 && energy_req > 0.0) {
     if(organism->GetPhenotype().GetStoredEnergy() >= energy_req) {
       inst_energy_cost[cur_inst.GetOp()] = 0;
@@ -749,13 +749,13 @@
           pop.AddBeginSleep(cellID,m_world->GetStats().GetUpdate());
         }
         pop.GetCell(cellID).GetOrganism()->SetSleeping(true);
-        pop.incNumAsleep();
+        m_world->GetStats().incNumAsleep(pop.GetCell(cellID).GetDemeID());
       }
     } else { // not enough energy
       return false;
     }
   }
-  
+
   // If first time cost hasn't been paid off...
   if (m_has_ft_costs && inst_ft_cost[cur_inst.GetOp()] > 0) {
     inst_ft_cost[cur_inst.GetOp()]--;       // dec cost

Modified: branches/energy_dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy_dev/source/cpu/cHardwareCPU.cc	2007-07-24 20:08:23 UTC (rev 1842)
+++ branches/energy_dev/source/cpu/cHardwareCPU.cc	2007-07-24 20:13:30 UTC (rev 1843)
@@ -4058,8 +4058,8 @@
     pop.AddEndSleep(organism->GetCellID(), m_world->GetStats().GetUpdate());
   }
   int cellID = organism->GetCellID();
-  pop.GetCell(cellID).GetOrganism()->SetSleeping(false);  //this instruction get executed at the end of a sleep cycle
-  pop.decNumAsleep();
+  organism->SetSleeping(false);  //this instruction get executed at the end of a sleep cycle
+  m_world->GetStats().decNumAsleep(pop.GetCell(cellID).GetDemeID());
   if(m_world->GetConfig().APPLY_ENERGY_METHOD.Get() == 2) {
     organism->GetPhenotype().RefreshEnergy();
     organism->GetPhenotype().ApplyToEnergyStore();

Modified: branches/energy_dev/source/main/cDeme.cc
===================================================================
--- branches/energy_dev/source/main/cDeme.cc	2007-07-24 20:08:23 UTC (rev 1842)
+++ branches/energy_dev/source/main/cDeme.cc	2007-07-24 20:13:30 UTC (rev 1843)
@@ -63,6 +63,9 @@
   _age = 0;
 }
 
+/*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

Modified: branches/energy_dev/source/main/cPopulation.cc
===================================================================
--- branches/energy_dev/source/main/cPopulation.cc	2007-07-24 20:08:23 UTC (rev 1842)
+++ branches/energy_dev/source/main/cPopulation.cc	2007-07-24 20:13:30 UTC (rev 1843)
@@ -73,7 +73,6 @@
 , schedule(NULL)
 , resource_count(world->GetEnvironment().GetResourceLib().GetSize())
 , birth_chamber(world)
-, numAsleep(0)
 , environment(world->GetEnvironment())
 , num_organisms(0)
 , sync_events(false)
@@ -577,7 +576,7 @@
 
   if(GetCell(cellID).GetOrganism()->IsSleeping()) {
     GetCell(cellID).GetOrganism()->SetSleeping(false);
-    decNumAsleep();
+    m_world->GetStats().decNumAsleep(GetCell(cellID).GetDemeID());
   }
   if(m_world->GetConfig().LOG_SLEEP_TIMES.Get() == 1) {
     if(sleep_log[cellID].Size() > 0) {
@@ -2568,10 +2567,7 @@
   // BB - Don't need to fix metabolic rate here, only on birth
 
   phenotype.SetMerit( cMerit(new_genotype->GetTestMerit(ctx)) );
-  
-  // @DMB - this appears to be debugging output
-  //cerr<<"initial energy: " << phenotype.GetStoredEnergy() <<endl<<"initial Merit: "<<phenotype.GetMerit().GetDouble()<<endl;
-  
+    
   // @CAO are these really needed?
   phenotype.SetLinesCopied( new_genotype->GetTestCopiedSize(ctx) );
   phenotype.SetLinesExecuted( new_genotype->GetTestExecutedSize(ctx) );

Modified: branches/energy_dev/source/main/cPopulation.h
===================================================================
--- branches/energy_dev/source/main/cPopulation.h	2007-07-24 20:08:23 UTC (rev 1842)
+++ branches/energy_dev/source/main/cPopulation.h	2007-07-24 20:13:30 UTC (rev 1843)
@@ -95,7 +95,6 @@
   tArray<tList<cSaleItem> > market;   // list of lists of items for sale, each list goes with 1 label
 
   tVector<pair<int,int> > *sleep_log;
-  int numAsleep;
   
   // Data Tracking...
   tList<cPopulationCell> reaper_queue; // Death order in some mass-action runs
@@ -240,10 +239,6 @@
   void AddEndSleep(int cellID, int end_time);
  
   tVector<pair<int,int> > getCellSleepLog(int i) { return sleep_log[i]; }
-  
-  int getNumAsleep() { return numAsleep; }
-  void incNumAsleep() { numAsleep++; }
-  void decNumAsleep() { numAsleep--; }
 };
 
 

Modified: branches/energy_dev/source/main/cStats.cc
===================================================================
--- branches/energy_dev/source/main/cStats.cc	2007-07-24 20:08:23 UTC (rev 1842)
+++ branches/energy_dev/source/main/cStats.cc	2007-07-24 20:13:30 UTC (rev 1843)
@@ -29,6 +29,7 @@
 #include "cEnvironment.h"
 #include "cHardwareManager.h"
 #include "cInstSet.h"
+#include "cPopulation.h"
 #include "cStringUtil.h"
 #include "cWorld.h"
 #include "cWorldDriver.h"
@@ -208,6 +209,10 @@
 
   
   genotype_map.Resize( m_world->GetConfig().WORLD_X.Get() * m_world->GetConfig().WORLD_Y.Get() );
+
+  numAsleep.Resize(m_world->GetConfig().NUM_DEMES.Get());
+  numAsleep.SetAll(0);
+
   SetupPrintDatabase();
 }
 
@@ -996,3 +1001,17 @@
   }
   df.Endl();
 }
+
+void cStats::PrintSleepData(const cString& filename){
+  cDataFile& df = m_world->GetDataFile(filename);
+
+  df.WriteComment( "Number of organisms sleeping\n" );
+  df.WriteComment("total number of organisms sleeping" );
+  
+  df.Write( GetUpdate(), "update" );
+    
+  for( int i=0; i < numAsleep.GetSize(); i++ ){
+    df.Write(numAsleep[i], cStringUtil::Stringf("DemeID %d", i));
+  }
+  df.Endl();
+}

Modified: branches/energy_dev/source/main/cStats.h
===================================================================
--- branches/energy_dev/source/main/cStats.h	2007-07-24 20:08:23 UTC (rev 1842)
+++ branches/energy_dev/source/main/cStats.h	2007-07-24 20:13:30 UTC (rev 1843)
@@ -249,6 +249,8 @@
   tArray<int> sense_last_exe_count;
   tArray<cString> sense_names;
 
+  tArray<int> numAsleep;
+
   cStats(); // @not_implemented
   cStats(const cStats&); // @not_implemented
   cStats& operator=(const cStats&); // @not_implemented
@@ -572,6 +574,10 @@
 
   int GetNumSenseSlots();
 
+  int getNumAsleep(int demeID) { return numAsleep[demeID]; }
+  void incNumAsleep(int demeID) { numAsleep[demeID]+=1; }
+  void decNumAsleep(int demeID) { numAsleep[demeID]--; }
+
   // this value gets recorded when a creature with the particular
   // fitness value gets born. It will never change to a smaller value,
   // i.e., when the maximum fitness in the population drops, this value will
@@ -605,7 +611,7 @@
   void PrintMarketData(const cString& filename);
   void PrintSenseData(const cString& filename);
   void PrintSenseExeData(const cString& filename);
-  
+  void PrintSleepData(const cString& filename);
 };
 
 




More information about the Avida-cvs mailing list