[Avida-SVN] r2142 - in branches/energy/source: actions main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Thu Oct 18 07:49:10 PDT 2007


Author: beckma24
Date: 2007-10-18 10:49:10 -0400 (Thu, 18 Oct 2007)
New Revision: 2142

Modified:
   branches/energy/source/actions/EnvironmentActions.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
Log:
Added time-to-live to deme events

Modified: branches/energy/source/actions/EnvironmentActions.cc
===================================================================
--- branches/energy/source/actions/EnvironmentActions.cc	2007-10-15 15:08:56 UTC (rev 2141)
+++ branches/energy/source/actions/EnvironmentActions.cc	2007-10-18 14:49:10 UTC (rev 2142)
@@ -602,9 +602,11 @@
   int m_delay; // deme age when event occurs
   int m_duration; // length of event; subverted when deme is reset
   bool m_static_pos;
+  int m_time_to_live; // update when event no longer exists
   
 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)
+  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), m_static_pos(1), m_time_to_live(-1)
   {
     cString largs(args);
     if (largs.GetSize()) m_x1 = largs.PopWord().AsInt();
@@ -614,16 +616,17 @@
     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();
+    if (largs.GetSize()) m_time_to_live = largs.PopWord().AsInt();
   }
   
-  static const cString GetDescription() { return "Arguments: <int x1> <int y1> <int x2> <int y2> <int delay> <int duraion> <int static_position>"; }
+  static const cString GetDescription() { return "Arguments: <int x1> <int y1> <int x2> <int y2> <int delay> <int duraion> <int static_position> <int time_to_live>"; }
   
   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, m_static_pos);
+      pop.GetDeme(i).SetCellEvent(m_x1, m_y1, m_x2, m_y2, m_delay, m_duration, m_static_pos, m_time_to_live);
     }
   }
 };

Modified: branches/energy/source/main/cDeme.cc
===================================================================
--- branches/energy/source/main/cDeme.cc	2007-10-15 15:08:56 UTC (rev 2141)
+++ branches/energy/source/main/cDeme.cc	2007-10-18 14:49:10 UTC (rev 2142)
@@ -80,7 +80,7 @@
 
 
 void cDeme::ProcessUpdate() {
-  for(int i = 0; i < cell_events.GetSize(); i++) {
+  for(int i = 0; i < cell_events.Size(); i++) {
     cDemeCellEvent& event = cell_events[i];
     if(event.GetDelay() == _age) {
       event.ActivateEvent(m_world); //start event
@@ -121,6 +121,13 @@
     (*message_pred_list[i]).Reset();
   }
   
+  //remove old events
+  for(int i = cell_events.Size()-1; i >= 0; i--) {
+    if(cell_events[i].GetTimeToLive() < m_world->GetStats().GetUpdate()) {
+      cell_events.RemoveAt(i);
+    }
+  }
+  
   for(int i = 0; i < GetSize(); i++) {
     m_world->GetPopulation().GetCell(GetCellID(i)).SetCellData(0);
   }
@@ -198,20 +205,23 @@
   deme_resource_count.ModifyCell(cell_resources, relative_cell_id);
 }
 
-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);
-  cell_events.Push(demeEvent);
+void cDeme::SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, bool static_pos, int time_to_live) {
+  cDemeCellEvent demeEvent = cDemeCellEvent(x1, y1, x2, y2, delay, duration, width, GetHeight(), static_pos, time_to_live);
+  cell_events.Add(demeEvent);
 }
 
 int cDeme::GetNumEvents() {
-  return cell_events.GetSize();
+  return cell_events.Size();
 }
 
 cDemeCellEvent cDeme::GetEvent(int i) {
-  assert(i < cell_events.GetSize());
+  assert(i < cell_events.Size());
   return cell_events[i];
 }
 
+void cDeme::ClearAllEvents() {
+  
+}
 
 bool cDeme::MsgPredSatisfiedPreviously() {
   for(int i = 0; i < message_pred_list.GetSize(); i++) {
@@ -224,11 +234,11 @@
 }
 
 void cDeme::AddEventReceivedCenterPred(int times) {
-  if(cell_events.GetSize() == 0) {
+  if(cell_events.Size() == 0) {
     cerr<<"Error: An EventReceivedCenterPred cannot be created until a CellEvent is added.\n";
     exit(1);
   }
-  for(int i = 0; i < cell_events.GetSize(); i++) {
+  for(int i = 0; i < cell_events.Size(); i++) {
     int sink_cell = GetCellID(GetSize()/2);
     cOrgMessagePred_EventReceivedCenter* pred = new cOrgMessagePred_EventReceivedCenter(&cell_events[i], sink_cell, times);
     m_world->GetStats().AddMessagePredicate(pred);
@@ -237,11 +247,11 @@
 }
 
 void cDeme::AddEventReceivedLeftSidePred(int times) {
-  if(cell_events.GetSize() == 0) {
+  if(cell_events.Size() == 0) {
     cerr<<"Error: An EventReceivedLeftSidePred cannot be created until a CellEvent is added.\n";
     exit(1);
   }
-  for(int i = 0; i < cell_events.GetSize(); i++) {
+  for(int i = 0; i < cell_events.Size(); i++) {
     cOrgMessagePred_EventReceivedLeftSide* pred = new cOrgMessagePred_EventReceivedLeftSide(&cell_events[i], m_world->GetPopulation(), times);
     m_world->GetStats().AddMessagePredicate(pred);
     message_pred_list.Push(pred);

Modified: branches/energy/source/main/cDeme.h
===================================================================
--- branches/energy/source/main/cDeme.h	2007-10-15 15:08:56 UTC (rev 2141)
+++ branches/energy/source/main/cDeme.h	2007-10-18 14:49:10 UTC (rev 2142)
@@ -28,9 +28,10 @@
 
 #include "cDemeCellEvent.h"
 #include "cGermline.h"
-#include "tArray.h"
 #include "cResourceCount.h"
 #include "cStringList.h"
+#include "tArray.h"
+#include "tVector.h"
 
 class cOrgMessagePredicate;
 class cPopulationCell;
@@ -58,7 +59,7 @@
   cResourceCount deme_resource_count; //!< Resources available to the deme
   tArray<int> energy_res_ids; //!< IDs of energy resources
   
-  tArray<cDemeCellEvent> cell_events;
+  tVector<cDemeCellEvent> cell_events;
   tArray<cOrgMessagePredicate*> message_pred_list;
   
   std::map<int, cPopulationCell*> cells_blocked_from_sending;
@@ -116,9 +117,10 @@
   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, bool static_pos);
+  void SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, bool static_pos, int time_to_live);
   int GetNumEvents();
   cDemeCellEvent GetEvent(int i);
+  void ClearAllEvents();
   bool MsgPredSatisfiedPreviously();
   void AddEventReceivedCenterPred(int times);
   void AddEventReceivedLeftSidePred(int times);

Modified: branches/energy/source/main/cDemeCellEvent.cc
===================================================================
--- branches/energy/source/main/cDemeCellEvent.cc	2007-10-15 15:08:56 UTC (rev 2141)
+++ branches/energy/source/main/cDemeCellEvent.cc	2007-10-18 14:49:10 UTC (rev 2142)
@@ -1,12 +1,13 @@
 #include "cDemeCellEvent.h"
 #include "cWorld.h"
 
-cDemeCellEvent::cDemeCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, int deme_width, int deme_height, bool static_pos) : 
+cDemeCellEvent::cDemeCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, int deme_width, int deme_height, bool static_pos, int time_to_live) : 
   m_delay(delay)
   , m_duration(duration)
   , m_iter(0)
   , m_deme_width(deme_width)
   , m_deme_height(deme_height)
+  , m_time_to_live(time_to_live)
   , m_active(false)
   , m_static_pos(static_pos)
 {

Modified: branches/energy/source/main/cDemeCellEvent.h
===================================================================
--- branches/energy/source/main/cDemeCellEvent.h	2007-10-15 15:08:56 UTC (rev 2141)
+++ branches/energy/source/main/cDemeCellEvent.h	2007-10-18 14:49:10 UTC (rev 2142)
@@ -9,16 +9,17 @@
   tArray<int> m_event_cells;
   int m_eventID;
   int m_delay, m_duration, m_iter, m_deme_width, m_deme_height;
-  int m_event_width, m_event_height;
+  int m_event_width, m_event_height, m_time_to_live;
   bool m_active, m_static_pos;
   
 public:
-  cDemeCellEvent() { cDemeCellEvent(-1, -1, -1, -1, 0, 0, 0, 0, true); }
-  cDemeCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, int deme_width, int deme_height, bool static_pos);
+  cDemeCellEvent() { cDemeCellEvent(-1, -1, -1, -1, 0, 0, 0, 0, true, 0); }
+  cDemeCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, int deme_width, int deme_height, bool static_pos, int time_to_live);
   int GetNextEventCellID();
   int GetDelay() { return m_delay; }
   int GetDuration() { return m_duration; }
   int GetEventID() { return m_eventID; }
+  int GetTimeToLive() { return m_time_to_live; }
   bool IsActive() { return m_active; }
 
   void ActivateEvent(cWorld* m_world);




More information about the Avida-cvs mailing list