[Avida-SVN] r2084 - in branches/energy: Avida.xcodeproj source/actions source/cpu source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Wed Sep 12 07:44:45 PDT 2007


Author: beckma24
Date: 2007-09-12 10:44:44 -0400 (Wed, 12 Sep 2007)
New Revision: 2084

Modified:
   branches/energy/Avida.xcodeproj/project.pbxproj
   branches/energy/source/actions/EnvironmentActions.cc
   branches/energy/source/actions/PopulationActions.cc
   branches/energy/source/actions/PrintActions.cc
   branches/energy/source/cpu/cHardwareCPU.cc
   branches/energy/source/main/cDeme.cc
   branches/energy/source/main/cDeme.h
   branches/energy/source/main/cDemeCellEvent.cc
   branches/energy/source/main/cDemeCellEvent.h
   branches/energy/source/main/cOrgMessagePredicate.h
   branches/energy/source/main/cPopulation.cc
   branches/energy/source/main/cPopulation.h
   branches/energy/source/main/cStats.cc
   branches/energy/source/main/cStats.h
Log:
Added a predicate satisfied case to ReplcateDemes.  When the user defined predicate is satisfied then the deme replicated.  So far the predicate is message based, but it can easily be extended to general predicates.

Modified cell events so that they can have a static or random position within a deme.

Added some simple stats that track and print the average/stdError age, births, and orgs within demes.

Added message predicate that is true when an event's ID have been received by an organism at the center of the deme.


Modified: branches/energy/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/energy/Avida.xcodeproj/project.pbxproj	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/Avida.xcodeproj/project.pbxproj	2007-09-12 14:44:44 UTC (rev 2084)
@@ -212,6 +212,23 @@
 		};
 /* End PBXBuildRule section */
 
+/* Begin PBXBuildStyle section */
+		B5195F300C95A1D400E398BD /* Development */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = NO;
+			};
+			name = Development;
+		};
+		B5195F310C95A1D400E398BD /* Deployment */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+			};
+			name = Deployment;
+		};
+/* End PBXBuildStyle section */
+
 /* Begin PBXContainerItemProxy section */
 		56F555DA0C3B36FC00E2E929 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
@@ -1779,6 +1796,12 @@
 		DCC30C4D0762532C008F7A48 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
+			buildSettings = {
+			};
+			buildStyles = (
+				B5195F300C95A1D400E398BD /* Development */,
+				B5195F310C95A1D400E398BD /* Deployment */,
+			);
 			hasScannedForEncodings = 0;
 			mainGroup = DCC30C490762532C008F7A48;
 			productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;

Modified: branches/energy/source/actions/EnvironmentActions.cc
===================================================================
--- branches/energy/source/actions/EnvironmentActions.cc	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/actions/EnvironmentActions.cc	2007-09-12 14:44:44 UTC (rev 2084)
@@ -461,6 +461,7 @@
   int m_x1, m_y1, m_x2, m_y2; // bounding box of event in deme
   int m_delay; // deme age when event occurs
   int m_duration; // length of event; subverted when deme is reset
+  bool m_static_pos;
   
 public:
   cActionDelayedDemeEvent(cWorld* world, const cString& args) : cAction(world, args), m_x1(-1), m_y1(-1), m_x2(-1), m_y2(-1), m_delay(-1), m_duration(-1)
@@ -472,16 +473,17 @@
     if (largs.GetSize()) m_y2 = largs.PopWord().AsInt();
     if (largs.GetSize()) m_delay = largs.PopWord().AsInt();
     if (largs.GetSize()) m_duration = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_static_pos = largs.PopWord().AsInt();
   }
   
-  static const cString GetDescription() { return "Arguments: <int x1> <int y1> <int x2> <int y2> <int delay> <int duraion>"; }
+  static const cString GetDescription() { return "Arguments: <int x1> <int y1> <int x2> <int y2> <int delay> <int duraion> <int static_position>"; }
   
   void Process(cAvidaContext& ctx)
   {
     cPopulation& pop = m_world->GetPopulation();
     int numDemes = pop.GetNumDemes();
     for(int i = 0; i < numDemes; i++) {
-      pop.GetDeme(i).SetCellEvent(m_x1, m_y1, m_x2, m_y2, m_delay, m_duration);
+      pop.GetDeme(i).SetCellEvent(m_x1, m_y1, m_x2, m_y2, m_delay, m_duration, m_static_pos);
     }
   }
 };

Modified: branches/energy/source/actions/PopulationActions.cc
===================================================================
--- branches/energy/source/actions/PopulationActions.cc	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/actions/PopulationActions.cc	2007-09-12 14:44:44 UTC (rev 2084)
@@ -1006,6 +1006,7 @@
     else if (in_trigger == "full_deme") m_rep_trigger = 1;
     else if (in_trigger == "corners") m_rep_trigger = 2;
     else if (in_trigger == "deme-age") m_rep_trigger = 3;
+    else if (in_trigger == "sat-msg-pred") m_rep_trigger = 4;
     else {
       cString err("Unknown replication trigger '");
       err += in_trigger;
@@ -1059,6 +1060,21 @@
   }
 };
 
+/*
+ 
+*/
+class cActionPred_DemeEventReceivedCenter : public cAction
+{
+public:
+  cActionPred_DemeEventReceivedCenter(cWorld* world, const cString& args) : cAction(world, args) { ; }
+  
+  static const cString GetDescription() { return "No Arguments"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    m_world->GetPopulation().AddDemeEventReceivedPred();
+  }
+};
 
 /*
  Designed to serve as a control for the compete_demes. Each deme is 
@@ -1552,6 +1568,7 @@
   action_lib->Register<cActionDivideDemes>("DivideDemes");
   action_lib->Register<cActionResetDemes>("ResetDemes");
   action_lib->Register<cActionCopyDeme>("CopyDeme");
+  action_lib->Register<cActionPred_DemeEventReceivedCenter>("Pred_DemeEventReceivedCenter");
   
   action_lib->Register<cActionNewTrial>("NewTrial");
   action_lib->Register<cActionCompeteOrganisms>("CompeteOrganisms");

Modified: branches/energy/source/actions/PrintActions.cc
===================================================================
--- branches/energy/source/actions/PrintActions.cc	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/actions/PrintActions.cc	2007-09-12 14:44:44 UTC (rev 2084)
@@ -69,7 +69,9 @@
 }                                                                                         /* 13 */ \
 
 STATS_OUT_FILE(PrintAverageData,            average.dat         );
+STATS_OUT_FILE(PrintDemeAverageData,        deme_average.dat    );
 STATS_OUT_FILE(PrintErrorData,              error.dat           );
+STATS_OUT_FILE(PrintDemeErrorData,          deme_error.dat      );
 STATS_OUT_FILE(PrintVarianceData,           variance.dat        );
 STATS_OUT_FILE(PrintDominantData,           dominant.dat        );
 STATS_OUT_FILE(PrintStatsData,              stats.dat           );
@@ -2604,7 +2606,9 @@
 {
   // Stats Out Files
   action_lib->Register<cActionPrintAverageData>("PrintAverageData");
+  action_lib->Register<cActionPrintDemeAverageData>("PrintDemeAverageData");
   action_lib->Register<cActionPrintErrorData>("PrintErrorData");
+  action_lib->Register<cActionPrintDemeErrorData>("PrintDemeErrorData");
   action_lib->Register<cActionPrintVarianceData>("PrintVarianceData");
   action_lib->Register<cActionPrintDominantData>("PrintDominantData");
   action_lib->Register<cActionPrintStatsData>("PrintStatsData");

Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/cpu/cHardwareCPU.cc	2007-09-12 14:44:44 UTC (rev 2084)
@@ -3097,7 +3097,11 @@
 bool cHardwareCPU::Inst_CollectCellData(cAvidaContext& ctx) {
   int cellID = organism->GetCellID();
   const int out_reg = FindModifiedRegister(REG_BX);
-  GetRegister(out_reg) = m_world->GetPopulation().GetCell(cellID).GetCellData();
+  if(cellID == -1) { //using test cpu
+    GetRegister(out_reg) = 0; //no data to collect
+  } else {
+    GetRegister(out_reg) = m_world->GetPopulation().GetCell(cellID).GetCellData();
+  }
   return true;
 }
 

Modified: branches/energy/source/main/cDeme.cc
===================================================================
--- branches/energy/source/main/cDeme.cc	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/main/cDeme.cc	2007-09-12 14:44:44 UTC (rev 2084)
@@ -25,6 +25,7 @@
 #include "cPopulation.h"
 #include "cPopulationCell.h"
 #include "cResource.h"
+#include "cStats.h"
 #include "cWorld.h"
 
 void cDeme::Setup(const tArray<int> & in_cells, int in_width, cWorld* world)
@@ -91,10 +92,16 @@
 void cDeme::Reset() 
 {
   birth_count = 0; 
-  _age = 0;  
-  //clear cell energy
+  _age = 0;
+  deme_resource_count.ReinitializeResources();
+  //reset predicates
+  for(int i = 0; i < message_pred_list.GetSize(); i++) {
+    (*message_pred_list[i]).Reset();
+  }
   
-  deme_resource_count.ReinitializeResources();
+  for(int i = 0; i < GetSize(); i++) {
+    m_world->GetPopulation().GetCell(GetCellID(i)).SetCellData(0);
+  }
 }
 
 /*! Replacing this deme's germline has the effect of changing the deme's lineage.
@@ -169,7 +176,28 @@
   deme_resource_count.ModifyCell(cell_resources, relative_cell_id);
 }
 
-void cDeme::SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration) {
-  cDemeCellEvent demeEvent = cDemeCellEvent(x1, y1, x2, y2, delay, duration, width);
+void cDeme::SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, bool static_pos) {
+  cDemeCellEvent demeEvent = cDemeCellEvent(x1, y1, x2, y2, delay, duration, width, GetHeight(), static_pos, m_world);
   cell_events.Push(demeEvent);
 }
+
+bool cDeme::MsgPredSatisfiedPreviously() {
+  for(int i = 0; i < message_pred_list.GetSize(); i++) {
+    if(message_pred_list[i]->previouslySatisfied())
+      return true;
+  }
+  return false;
+}
+
+void cDeme::AddEventReceivedCenterPred() {
+  if(cell_events.GetSize() == 0) {
+    cerr<<"Error: An EventReceivedPred cannot be created until a CellEvent is added.\n";
+    exit(1);
+  }
+  for(int i = 0; i < cell_events.GetSize(); i++) {
+    int sink_cell = GetCellID(GetSize()/2);
+    cOrgMessagePred_EventReceived* pred = new cOrgMessagePred_EventReceived(&cell_events[i], sink_cell);
+    m_world->GetStats().AddMessagePredicate(pred);
+    message_pred_list.Push(pred);
+  }
+}

Modified: branches/energy/source/main/cDeme.h
===================================================================
--- branches/energy/source/main/cDeme.h	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/main/cDeme.h	2007-09-12 14:44:44 UTC (rev 2084)
@@ -27,6 +27,7 @@
 #include "cDemeCellEvent.h"
 #include "cGermline.h"
 #include "tArray.h"
+#include "cOrgMessagePredicate.h"
 #include "cResourceCount.h"
 #include "cStringList.h"
 
@@ -55,6 +56,7 @@
   tArray<int> energy_res_ids; //!< IDs of energy resources
   
   tArray<cDemeCellEvent> cell_events;
+  tArray<cOrgMessagePredicate*> message_pred_list;
   
 public:
   cDeme() : width(0), birth_count(0), org_count(0), _age(0), deme_resource_count(0) { ; }
@@ -106,7 +108,9 @@
   void Update(double time_step) { deme_resource_count.Update(time_step); }
   int GetRelativeCellID(int absolute_cell_id) { return absolute_cell_id % GetSize(); } //!< assumes all demes are the same size
 
-  void SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration);
+  void SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, bool static_pos);
+  bool MsgPredSatisfiedPreviously();
+  void AddEventReceivedCenterPred();
 };
 
 #endif

Modified: branches/energy/source/main/cDemeCellEvent.cc
===================================================================
--- branches/energy/source/main/cDemeCellEvent.cc	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/main/cDemeCellEvent.cc	2007-09-12 14:44:44 UTC (rev 2084)
@@ -1,25 +1,34 @@
 #include "cDemeCellEvent.h"
 #include "cWorld.h"
 
-cDemeCellEvent::cDemeCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, int width) : 
+cDemeCellEvent::cDemeCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, int deme_width, int deme_height, bool static_pos, cWorld* m_world) : 
   m_delay(delay)
   , m_duration(duration)
   , m_iter(0)
+  , m_deme_width(deme_width)
+  , m_deme_height(deme_height)
   , m_active(false)
+  , m_static_pos(static_pos)
 {
   assert(x1 <= x2);
   assert(y1 <= y2);
-  assert(y1 < width && y2 < width);
+  assert(y1 < deme_width && y2 < deme_width);
   assert(delay >= 0);
   assert(duration >= 0);
   m_event_cells.ResizeClear((x2-x1+1) * (y2-y1+1));
+  int i = 0;
   
-  int i = 0;
-  for(int j = y1; j <= y2; j++) {
-    for(int k = x1; k <= x2; k++) {
-      m_event_cells[i] = j*width+k;
-      i++;
+  if(m_static_pos) {
+    for(int j = y1; j <= y2; j++) {
+      for(int k = x1; k <= x2; k++) {
+        m_event_cells[i] = j*m_deme_width+k;
+        i++;
+      }
     }
+  } else {
+    //non-static event position
+    m_event_width = x2-x1;
+    m_event_height = y2-y1;
   }
 }
 
@@ -33,6 +42,19 @@
 
 void cDemeCellEvent::ActivateEvent(cWorld* m_world) {
   m_eventID = m_world->GetRandom().GetInt(0x7FFFFFFF);
+  
+  if(!m_static_pos) {
+    //non-static event position
+    int rand_x1 = m_world->GetRandom().GetInt(m_deme_width-m_event_width);
+    int rand_y1 = m_world->GetRandom().GetInt(m_deme_height-m_event_height);
+    int i = 0;
+    for(int j = rand_y1; j <= rand_y1+m_event_height; j++) {
+      for(int k = rand_x1; k <= rand_x1+m_event_width; k++) {
+        m_event_cells[i] = j*m_deme_width+k;
+        i++;
+      }
+    }
+  }
   m_active = true;
 }
 

Modified: branches/energy/source/main/cDemeCellEvent.h
===================================================================
--- branches/energy/source/main/cDemeCellEvent.h	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/main/cDemeCellEvent.h	2007-09-12 14:44:44 UTC (rev 2084)
@@ -7,16 +7,19 @@
 class cDemeCellEvent {
 private:
   tArray<int> m_event_cells;
-  int m_delay, m_duration, m_eventID, m_iter;
-  bool m_active;
+  int m_eventID;
+  int m_delay, m_duration, m_iter, m_deme_width, m_deme_height;
+  int m_event_width, m_event_height;
+  bool m_active, m_static_pos;
   
 public:
-  cDemeCellEvent() { cDemeCellEvent(-1, -1, -1, -1, 0, 0, 0); }
-  cDemeCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, int width);
+  cDemeCellEvent() { cDemeCellEvent(-1, -1, -1, -1, 0, 0, 0, 0, true, NULL); }
+  cDemeCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, int deme_width, int deme_height, bool static_pos, cWorld* m_world);
   int GetNextEventCellID();
   int GetDelay() { return m_delay; }
   int GetDuration() { return m_duration; }
   int GetEventID() { return m_eventID; }
+  bool IsActive() { return m_active; }
 
   void ActivateEvent(cWorld* m_world);
   void DeactivateEvent();

Modified: branches/energy/source/main/cOrgMessagePredicate.h
===================================================================
--- branches/energy/source/main/cOrgMessagePredicate.h	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/main/cOrgMessagePredicate.h	2007-09-12 14:44:44 UTC (rev 2084)
@@ -28,6 +28,7 @@
 #include <functional>
 #include <set>
 
+#include "cDemeCellEvent.h"
 #include "cOrgMessage.h"
 #include "cOrganism.h"
 
@@ -42,6 +43,7 @@
   virtual bool operator()(const cOrgMessage& msg) = 0;
   virtual void Print(std::ostream& out) { }
   virtual void Reset() { }
+  virtual bool previouslySatisfied() = 0;
 };
 
 
@@ -71,6 +73,10 @@
     m_cell_ids.clear();
   }
   
+  virtual bool previouslySatisfied() {
+    return false;
+  }
+  
   unsigned int m_data;
   std::set<int> m_cell_ids;
 };
@@ -117,14 +123,51 @@
 //    out << "} "<<m_cell_ids_total_good.size();
   }
   
-  virtual void reset() { 
+  virtual void Reset() { 
     m_cell_ids.clear();
   }
   
+  virtual bool previouslySatisfied() {
+    return false;
+  }
+  
   unsigned int m_data;
   std::set<int> m_cell_ids;
   std::set<int> m_cell_ids_total_good;
 };
 
+/*! A predicate that returns true if a demeCellEvent has been received but the base station
+*/
+struct cOrgMessagePred_EventReceived : public cOrgMessagePredicate {
+  cOrgMessagePred_EventReceived(cDemeCellEvent* event, int base_station) : 
+  m_base_station(base_station)
+  , m_event_received(false)
+  , m_event(event){ }
+  
+  ~cOrgMessagePred_EventReceived() { }
+  
+  virtual bool operator()(const cOrgMessage& msg) {
+    if(m_event->IsActive() && m_base_station == msg.GetReceiver()->GetCellID() && 
+    ((unsigned int)m_event->GetEventID() == msg.GetData() || (unsigned int)m_event->GetEventID() == msg.GetLabel())) {
+      m_event_received = true;
+    }
+    return m_event_received;
+  }
+  
+  virtual void print(std::ostream& out) { 
+  }
+  
+  virtual void Reset() { 
+    m_event_received = false;
+  }
 
+  virtual bool previouslySatisfied() {
+    return m_event_received;
+  }
+    
+  int m_base_station;
+  bool m_event_received;
+  cDemeCellEvent* m_event;
+};
+
 #endif

Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/main/cPopulation.cc	2007-09-12 14:44:44 UTC (rev 2084)
@@ -1054,6 +1054,7 @@
 1: 'full_deme' - ...demes that have been filled up.
 2: 'corners'   - ...demes with upper left and lower right corners filled.
 3: 'deme-age'  - ...demes who have reached their maximum age
+4: 'sat-msg-pred'  - ...demes whose predicate was previously satisfied
 */
 
 void cPopulation::ReplicateDemes(int rep_trigger)
@@ -1097,6 +1098,10 @@
         if(source_deme.GetAge() < m_world->GetConfig().MAX_DEME_AGE.Get()) continue;
         break;
       }
+      case 4: {
+        if(!(source_deme.MsgPredSatisfiedPreviously())) continue;
+        break;
+      }
       default: {
         cerr << "ERROR: Invalid replication trigger " << rep_trigger
         << " in cPopulation::ReplicateDemes()" << endl;
@@ -1328,7 +1333,6 @@
 
 // Reset Demes goes through each deme and resets the individual organisms as
 // if they were just injected into the population.
-
 void cPopulation::ResetDemes()
 {
   // re-inject all demes into themselves to reset them.
@@ -1360,6 +1364,11 @@
   }
 }
 
+void cPopulation::AddDemeEventReceivedPred() {
+  for (int deme_id = 0; deme_id < deme_array.GetSize(); deme_id++) {
+    deme_array[deme_id].AddEventReceivedCenterPred();
+  }
+}
 
 // Print out statistics about donations
                   
@@ -2068,7 +2077,22 @@
   }
 }
 
+// Loop through all the demes getting stats and doing calculations
+// which must be done on a deme by deme basis.
+void cPopulation::UpdateDemeStats() {
+  cStats& stats = m_world->GetStats();
 
+  stats.SumDemeAge().Clear();
+  stats.SumDemeBirthCount().Clear();
+  stats.SumDemeOrgCount().Clear();
+  
+  for(int i = 0; i < GetNumDemes(); i++) {
+    stats.SumDemeAge().Add(GetDeme(i).GetAge());
+    stats.SumDemeBirthCount().Add(GetDeme(i).GetBirthCount());
+    stats.SumDemeBirthCount().Add(GetDeme(i).GetOrgCount());
+  }
+}
+
 void cPopulation::UpdateOrganismStats()
 {
   // Carrying capacity @WRE 04-20-07
@@ -2394,6 +2418,7 @@
   m_world->GetClassificationManager().UpdateReset();
   
   UpdateOrganismStats();
+  UpdateDemeStats();
   UpdateGenotypeStats();
   UpdateSpeciesStats();
   UpdateDominantStats();

Modified: branches/energy/source/main/cPopulation.h
===================================================================
--- branches/energy/source/main/cPopulation.h	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/main/cPopulation.h	2007-09-12 14:44:44 UTC (rev 2084)
@@ -122,6 +122,7 @@
   void FindEmptyCell(tList<cPopulationCell>& cell_list, tList<cPopulationCell>& found_list);
 
   // Update statistics collecting...
+  void UpdateDemeStats();
   void UpdateOrganismStats();
   void UpdateGenotypeStats();
   void UpdateSpeciesStats();
@@ -182,6 +183,7 @@
   void ResetDemes();
   void CopyDeme(int deme1_id, int deme2_id);
   void SpawnDeme(int deme1_id, int deme2_id=-1);
+  void AddDemeEventReceivedPred();
 
   // Deme-related stats methods
   void PrintDemeAllStats();

Modified: branches/energy/source/main/cStats.cc
===================================================================
--- branches/energy/source/main/cStats.cc	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/main/cStats.cc	2007-09-12 14:44:44 UTC (rev 2084)
@@ -553,7 +553,20 @@
   df.Endl();
 }
 
+void cStats::PrintDemeAverageData(const cString& filename)
+{
+  cDataFile& df = m_world->GetDataFile(filename);
 
+  df.WriteComment("Avida Average Deme Data");
+  df.WriteTimeStamp();
+
+  df.Write(m_update,                        "Update");
+  df.Write(sum_deme_age.Average(),          "Age");
+  df.Write(sum_deme_birth_count.Average(),  "Births");
+  df.Write(sum_deme_org_count.Average(),    "Organisms");
+  df.Endl();
+}
+
 void cStats::PrintErrorData(const cString& filename)
 {
   cDataFile& df = m_world->GetDataFile(filename);
@@ -580,7 +593,20 @@
   df.Endl();
 }
 
+void cStats::PrintDemeErrorData(const cString& filename)
+{
+  cDataFile& df = m_world->GetDataFile(filename);
 
+  df.WriteComment("Avida Average Deme Data");
+  df.WriteTimeStamp();
+
+  df.Write(m_update,                         "Update");
+  df.Write(sum_deme_age.StdError(),          "Age");
+  df.Write(sum_deme_birth_count.StdError(),  "Births");
+  df.Write(sum_deme_org_count.StdError(),    "Organisms");
+  df.Endl();
+}
+
 void cStats::PrintVarianceData(const cString& filename)
 {
   cDataFile& df = m_world->GetDataFile(filename);

Modified: branches/energy/source/main/cStats.h
===================================================================
--- branches/energy/source/main/cStats.h	2007-09-10 15:23:40 UTC (rev 2083)
+++ branches/energy/source/main/cStats.h	2007-09-12 14:44:44 UTC (rev 2084)
@@ -254,6 +254,11 @@
 
   tArray<int> numAsleep;
 
+  // simple deme stats
+  cIntSum sum_deme_age;
+  cIntSum sum_deme_birth_count;
+  cIntSum sum_deme_org_count;
+
   cStats(); // @not_implemented
   cStats(const cStats&); // @not_implemented
   cStats& operator=(const cStats&); // @not_implemented
@@ -382,7 +387,13 @@
   cDoubleSum& SumCopySize()      { return sum_copy_size; }
   cDoubleSum& SumExeSize()       { return sum_exe_size; }
   cDoubleSum& SumMemSize()       { return sum_mem_size; }
+  
+  //deme
+  cIntSum& SumDemeAge()          { return sum_deme_age; }
+  cIntSum& SumDemeBirthCount()   { return sum_deme_birth_count; }
+  cIntSum& SumDemeOrgCount()     { return sum_deme_org_count; }
 
+
 #if INSTRUCTION_COUNT
   void ZeroInst();
 #endif
@@ -414,6 +425,11 @@
   const cDoubleSum& SumExeSize() const       { return sum_exe_size; }
   const cDoubleSum& SumMemSize() const       { return sum_mem_size; }
 
+  //deme
+  const cIntSum& SumDemeAge() const          { return sum_deme_age; }
+  const cIntSum& SumDemeBirthCount() const   { return sum_deme_birth_count; }
+  const cIntSum& SumDemeOrgCount() const     { return sum_deme_org_count; }
+
   
   void IncResamplings() { ++num_resamplings; }  // @AWC 06/29/06
   void IncFailedResamplings() { ++num_failedResamplings; }  // @AWC 06/29/06
@@ -577,6 +593,11 @@
 
   int GetNumSenseSlots();
 
+  // deme
+  double GetAveDemeAge() const { return sum_deme_age.Average(); }
+  double GetAveDemeBirthCount() const { return sum_deme_birth_count.Average(); }
+  double GetAveDemeOrgCount() const { return sum_deme_org_count.Average(); }
+
   int getNumAsleep(int demeID) { return numAsleep[demeID]; }
   void incNumAsleep(int demeID) { numAsleep[demeID]++; }
   void decNumAsleep(int demeID) { numAsleep[demeID]--; }
@@ -592,7 +613,9 @@
 
   // Public calls to output data files (for events)
   void PrintAverageData(const cString& filename);
+  void PrintDemeAverageData(const cString& filename);
   void PrintErrorData(const cString& filename);
+  void PrintDemeErrorData(const cString& filename);
   void PrintVarianceData(const cString& filename);
   void PrintDominantData(const cString& filename);
   void PrintParasiteData(const cString& filename);




More information about the Avida-cvs mailing list