[Avida-SVN] r1433 - in branches/energy/source: actions cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Mon Mar 26 13:24:33 PDT 2007
Author: beckma24
Date: 2007-03-26 16:24:32 -0400 (Mon, 26 Mar 2007)
New Revision: 1433
Modified:
branches/energy/source/actions/PrintActions.cc
branches/energy/source/cpu/cHardwareCPU.cc
branches/energy/source/main/cPopulation.cc
branches/energy/source/main/cPopulation.h
Log:
Added output file that logs the number of organisms sleeping.
Fixed data logging bug that occurred when an organism was killed while sleeping.
Modified: branches/energy/source/actions/PrintActions.cc
===================================================================
--- branches/energy/source/actions/PrintActions.cc 2007-03-26 13:29:34 UTC (rev 1432)
+++ branches/energy/source/actions/PrintActions.cc 2007-03-26 20:24:32 UTC (rev 1433)
@@ -274,13 +274,12 @@
}
};
-/********* BEGIN ********/
-class cActionPrintSleepData : public cAction
+class cActionPrintSleepLog : public cAction
{
private:
cString m_filename;
public:
- cActionPrintSleepData(cWorld* world, const cString& args) : cAction(world, args) { }
+ cActionPrintSleepLog(cWorld* world, const cString& args) : cAction(world, args) { }
static const cString GetDescription() { return "Arguments: [string fname=\"sleep.dat\"]"; }
@@ -307,8 +306,35 @@
df.Flush();
}
};
+
+/********* BEGIN ********/
+class cActionPrintSleepCount : public cAction
+{
+private:
+ cString m_filename;
+public:
+ cActionPrintSleepCount(cWorld* world, const cString& args) : cAction(world, args) { }
+
+ static const cString GetDescription() { return "Arguments: [string fname=\"sleepCount.dat\"]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ m_filename.Set("sleepCount.dat", m_world->GetStats().GetUpdate());
+ cDataFile& df = m_world->GetDataFile(m_filename);
+
+ df.WriteComment("Cells sleeping count");
+ df.WriteTimeStamp();
+
+ df.Write(m_world->GetStats().GetUpdate(), "Update");
+ df.Write(m_world->GetPopulation().getNumAsleep(), "Number of orgs. asleep");
+ df.Endl();
+ df.Flush();
+ }
+};
/********END**********/
+
+
class cActionPrintSpeciesAbundanceHistogram : public cAction
{
private:
@@ -1578,8 +1604,10 @@
action_lib->Register<cActionSetVerbose>("SetVerbose");
// Print Sleep
- action_lib->Register<cActionPrintSleepData>("PrintSleepLog");
+ action_lib->Register<cActionPrintSleepLog>("PrintSleepLog");
+ action_lib->Register<cActionPrintSleepCount>("PrintSleepCount");
+
// @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
action_lib->Register<cActionPrintAverageData>("print_average_data");
action_lib->Register<cActionPrintErrorData>("print_error_data");
Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc 2007-03-26 13:29:34 UTC (rev 1432)
+++ branches/energy/source/cpu/cHardwareCPU.cc 2007-03-26 20:24:32 UTC (rev 1433)
@@ -538,8 +538,8 @@
//subtract energy used from current org energy.
organism->GetPhenotype().ReduceEnergy(energy_req);
cString instName = m_world->GetHardwareManager().GetInstSet().GetName(cur_inst);
- if( instName == cString("sleep") || instName == cString("sleep1") ||instName == cString("sleep2") ||
- instName == cString("sleep3") || instName == cString("sleep4"))
+ if( instName == cString("sleep") || instName == cString("sleep1") || instName == cString("sleep2") ||
+ instName == cString("sleep3") || instName == cString("sleep4"))
m_world->GetPopulation().AddBeginSleep(organism->GetCellID(),m_world->GetStats().GetUpdate());
} else {
Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc 2007-03-26 13:29:34 UTC (rev 1432)
+++ branches/energy/source/main/cPopulation.cc 2007-03-26 20:24:32 UTC (rev 1433)
@@ -71,6 +71,7 @@
, environment(world->GetEnvironment())
, num_organisms(0)
, sync_events(false)
+, numAsleep(0)
{
// Avida specific information.
world_x = world->GetConfig().WORLD_X.Get();
@@ -528,6 +529,16 @@
cGenotype* genotype = organism->GetGenotype();
m_world->GetStats().RecordDeath();
+ if(m_world->GetConfig().ENERGY_ENABLED.Get()) {
+ int cellID = in_cell.GetID();
+ if(sleep_log[cellID].Size() > 0) {
+ pair<int,int> p = sleep_log[cellID][sleep_log[cellID].Size()-1];
+ if(p.second == -1) {
+ AddEndSleep(cellID,m_world->GetStats().GetUpdate());
+ }
+ }
+ }
+
tList<tListNode<cSaleItem> >* sold_items = organism->GetSoldItems();
if (sold_items)
{
@@ -2248,7 +2259,7 @@
if(m_world->GetConfig().ENERGY_ENABLED.Get()) { //TODO -- check for correctness
//TODO -- add energy here
- double initial_energy = m_world->GetConfig().ENERGY_GIVEN_ON_INJECT.Get(); // PUT INSIDE IF
+ double initial_energy = m_world->GetConfig().ENERGY_GIVEN_ON_INJECT.Get();
phenotype.SetEnergy(initial_energy);
}
// BB - Don't need to fix metabolic rate here, only on birth
@@ -2461,10 +2472,16 @@
void cPopulation::AddBeginSleep(int cellID, int start_time) {
sleep_log[cellID].Add(make_pair(start_time,-1));
+ numAsleep++;
}
void cPopulation::AddEndSleep(int cellID, int end_time) {
pair<int,int> p = sleep_log[cellID][sleep_log[cellID].Size()-1];
sleep_log[cellID].RemoveAt(sleep_log[cellID].Size()-1);
sleep_log[cellID].Add(make_pair(p.first, end_time));
+ numAsleep--;
}
+
+int cPopulation::getNumAsleep() {
+ return numAsleep;
+}
Modified: branches/energy/source/main/cPopulation.h
===================================================================
--- branches/energy/source/main/cPopulation.h 2007-03-26 13:29:34 UTC (rev 1432)
+++ branches/energy/source/main/cPopulation.h 2007-03-26 20:24:32 UTC (rev 1433)
@@ -95,6 +95,7 @@
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
@@ -229,6 +230,9 @@
void AddEndSleep(int cellID, int end_time);
tVector<pair<int,int> > getCellLog(int i) { return sleep_log[i]; }
+
+ int getNumAsleep();
+
};
More information about the Avida-cvs
mailing list