[Avida-SVN] r2125 - in branches/energy/source: actions main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Thu Oct 4 07:29:25 PDT 2007
Author: beckma24
Date: 2007-10-04 10:29:20 -0400 (Thu, 04 Oct 2007)
New Revision: 2125
Modified:
branches/energy/source/actions/PopulationActions.cc
branches/energy/source/main/cDeme.cc
branches/energy/source/main/cDeme.h
branches/energy/source/main/cOrgMessagePredicate.h
branches/energy/source/main/cPopulation.cc
branches/energy/source/main/cPopulation.h
Log:
Added new message predicate that is true when an event's ID is sent to an organism in the left most column of the population. Also, added a satisifaction threshold argument to message receive predicates. Note: events do not change when a predicate is satisified unless the threshold is reached.
Modified: branches/energy/source/actions/PopulationActions.cc
===================================================================
--- branches/energy/source/actions/PopulationActions.cc 2007-10-04 12:15:21 UTC (rev 2124)
+++ branches/energy/source/actions/PopulationActions.cc 2007-10-04 14:29:20 UTC (rev 2125)
@@ -1061,22 +1061,51 @@
};
/*
-
+ Added predicate to all demes that is satisified when an event ID reaches the center of the deme
*/
class cActionPred_DemeEventReceivedCenter : public cAction
{
+private:
+ int m_times;
+
public:
- cActionPred_DemeEventReceivedCenter(cWorld* world, const cString& args) : cAction(world, args) { ; }
+ cActionPred_DemeEventReceivedCenter(cWorld* world, const cString& args) : cAction(world, args), m_times(1) {
+ cString largs(args);
+ if (largs.GetSize()) m_times = largs.PopWord().AsInt();
+ }
- static const cString GetDescription() { return "No Arguments"; }
+ static const cString GetDescription() { return "Arguments: [int times=1]"; }
void Process(cAvidaContext& ctx)
{
- m_world->GetPopulation().AddDemeEventReceivedPred();
+ m_world->GetPopulation().AddDemePred("EventReceivedCenter", m_times);
}
};
+
/*
+ Added predicate to all demes that is satisified when an event ID reaches the center of the deme
+*/
+class cActionPred_DemeEventReceivedLeftSide : public cAction
+{
+private:
+ int m_times;
+
+public:
+ cActionPred_DemeEventReceivedLeftSide(cWorld* world, const cString& args) : cAction(world, args), m_times(1) {
+ cString largs(args);
+ if (largs.GetSize()) m_times = largs.PopWord().AsInt();
+ }
+
+ static const cString GetDescription() { return "Arguments: [int times=1]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ m_world->GetPopulation().AddDemePred("EventReceivedLeftSide", m_times);
+ }
+};
+
+/*
Designed to serve as a control for the compete_demes. Each deme is
copied into itself and the parameters reset.
*/
@@ -1569,6 +1598,7 @@
action_lib->Register<cActionResetDemes>("ResetDemes");
action_lib->Register<cActionCopyDeme>("CopyDeme");
action_lib->Register<cActionPred_DemeEventReceivedCenter>("Pred_DemeEventReceivedCenter");
+ action_lib->Register<cActionPred_DemeEventReceivedLeftSide>("Pred_DemeEventReceivedLeftSide");
action_lib->Register<cActionNewTrial>("NewTrial");
action_lib->Register<cActionCompeteOrganisms>("CompeteOrganisms");
Modified: branches/energy/source/main/cDeme.cc
===================================================================
--- branches/energy/source/main/cDeme.cc 2007-10-04 12:15:21 UTC (rev 2124)
+++ branches/energy/source/main/cDeme.cc 2007-10-04 14:29:20 UTC (rev 2125)
@@ -22,8 +22,10 @@
*/
#include "cDeme.h"
+#include "cDemeCellEvent.h"
+#include "cOrgMessagePredicate.h"
#include "cPopulation.h"
-//#include "cPopulationCell.h"
+#include "cPopulationCell.h"
#include "cResource.h"
#include "cStats.h"
#include "cWorld.h"
@@ -217,15 +219,52 @@
return false;
}
-void cDeme::AddEventReceivedCenterPred() {
+void cDeme::AddEventReceivedCenterPred(int times) {
if(cell_events.GetSize() == 0) {
- cerr<<"Error: An EventReceivedPred cannot be created until a CellEvent is added.\n";
+ cerr<<"Error: An EventReceivedCenterPred 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);
+ cOrgMessagePred_EventReceivedCenter* pred = new cOrgMessagePred_EventReceivedCenter(&cell_events[i], sink_cell, times);
m_world->GetStats().AddMessagePredicate(pred);
message_pred_list.Push(pred);
}
}
+
+void cDeme::AddEventReceivedLeftSidePred(int times) {
+ if(cell_events.GetSize() == 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++) {
+ cOrgMessagePred_EventReceivedLeftSide* pred = new cOrgMessagePred_EventReceivedLeftSide(&cell_events[i], m_world->GetPopulation(), times);
+ m_world->GetStats().AddMessagePredicate(pred);
+ message_pred_list.Push(pred);
+ }
+}
+
+int cDeme::GetNumPredicates() {
+ return message_pred_list.GetSize();
+}
+
+bool cDeme::PredicatePreviouslySatisfied(int pred_id) {
+ return message_pred_list[pred_id]->PreviouslySatisfied();
+}
+
+cString cDeme::GetPredicateName(int pred_id) {
+ return message_pred_list[pred_id]->GetName();
+}
+
+void cDeme::PrintPredicate(int pred_id, std::ostream& out) {
+ message_pred_list[pred_id]->Print(out);
+}
+
+
+void cDeme::InsertInBlockedList(int cell_id, cPopulationCell* cell) {
+ cells_blocked_from_sending[cell_id] = cell;
+}
+
+void cDeme::InsertInPausedList(int cell_id, cPopulationCell* cell) {
+ cells_paused_from_sending[cell_id] = cell;
+}
Modified: branches/energy/source/main/cDeme.h
===================================================================
--- branches/energy/source/main/cDeme.h 2007-10-04 12:15:21 UTC (rev 2124)
+++ branches/energy/source/main/cDeme.h 2007-10-04 14:29:20 UTC (rev 2125)
@@ -24,14 +24,16 @@
#ifndef cDeme_h
#define cDeme_h
+#include <map>
+
#include "cDemeCellEvent.h"
#include "cGermline.h"
#include "tArray.h"
-#include "cOrgMessagePredicate.h"
-#include "cPopulationCell.h"
#include "cResourceCount.h"
#include "cStringList.h"
+class cOrgMessagePredicate;
+class cPopulationCell;
class cResource;
class cWorld;
@@ -118,14 +120,15 @@
void SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, bool static_pos);
bool MsgPredSatisfiedPreviously();
- void AddEventReceivedCenterPred();
- int GetNumPredicates() { return message_pred_list.GetSize(); }
- bool PredicatePreviouslySatisfied(int pred_id) { return message_pred_list[pred_id]->PreviouslySatisfied(); }
- cString GetPredicateName(int pred_id) { return message_pred_list[pred_id]->GetName(); }
- void PrintPredicate(int pred_id, std::ostream& out) { message_pred_list[pred_id]->Print(out); }
+ void AddEventReceivedCenterPred(int times);
+ void AddEventReceivedLeftSidePred(int times);
+ int GetNumPredicates();
+ bool PredicatePreviouslySatisfied(int pred_id);
+ cString GetPredicateName(int pred_id);
+ void PrintPredicate(int pred_id, std::ostream& out);
- void InsertInBlockedList(int cell_id, cPopulationCell* cell) { cells_blocked_from_sending[cell_id] = cell; }
- void InsertInPausedList(int cell_id, cPopulationCell* cell) { cells_paused_from_sending[cell_id] = cell; }
+ void InsertInBlockedList(int cell_id, cPopulationCell* cell);
+ void InsertInPausedList(int cell_id, cPopulationCell* cell);
};
#endif
Modified: branches/energy/source/main/cOrgMessagePredicate.h
===================================================================
--- branches/energy/source/main/cOrgMessagePredicate.h 2007-10-04 12:15:21 UTC (rev 2124)
+++ branches/energy/source/main/cOrgMessagePredicate.h 2007-10-04 14:29:20 UTC (rev 2125)
@@ -31,6 +31,7 @@
#include "cDemeCellEvent.h"
#include "cOrgMessage.h"
#include "cOrganism.h"
+#include "cPopulation.h"
#include "cStats.h"
@@ -149,22 +150,28 @@
/*! 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) :
+struct cOrgMessagePred_EventReceivedCenter : public cOrgMessagePredicate {
+ cOrgMessagePred_EventReceivedCenter(cDemeCellEvent* event, int base_station, int times) :
m_base_station(base_station)
, m_event_received(false)
, m_stats_updated(false)
- , m_event(event){ }
+ , m_event(event)
+ , m_total_times(times)
+ , m_current_times(0) { }
- ~cOrgMessagePred_EventReceived() { }
+ ~cOrgMessagePred_EventReceivedCenter() { }
virtual bool operator()(const cOrgMessage& msg) {
if(m_event->IsActive() &&
((unsigned int)m_event->GetEventID() == msg.GetData() ||
(unsigned int)m_event->GetEventID() == msg.GetLabel())) {
m_cell_ids.insert(msg.GetSender()->GetCellID());
+
if(m_base_station == msg.GetReceiver()->GetCellID()) {
- m_event_received = true;
+ m_current_times++;
+ if(m_current_times == m_total_times) {
+ m_event_received = true;
+ }
}
}
return m_event_received;
@@ -192,7 +199,7 @@
}
virtual cString GetName() {
- return "EventReceived";
+ return "EventReceivedCenter";
}
virtual void UpdateStats(cStats& stats) {
@@ -211,6 +218,88 @@
bool m_stats_updated;
cDemeCellEvent* m_event;
std::set<int> m_cell_ids;
+ int m_total_times;
+ int m_current_times;
};
+/*! A predicate that returns true if a demeCellEvent has been received but the base station
+*/
+struct cOrgMessagePred_EventReceivedLeftSide : public cOrgMessagePredicate {
+ cOrgMessagePred_EventReceivedLeftSide(cDemeCellEvent* event, cPopulation& population, int times) :
+ pop(population)
+ , m_event_received(false)
+ , m_stats_updated(false)
+ , m_event(event)
+ , m_total_times(times)
+ , m_current_times(0){ }
+
+ ~cOrgMessagePred_EventReceivedLeftSide() { }
+
+ virtual bool operator()(const cOrgMessage& msg) {
+ if(m_event->IsActive() &&
+ ((unsigned int)m_event->GetEventID() == msg.GetData() ||
+ (unsigned int)m_event->GetEventID() == msg.GetLabel())) {
+ m_cell_ids.insert(msg.GetSender()->GetCellID());
+
+ // find receiver coordinates
+ cOrganism* receiver = msg.GetReceiver();
+ int absolute_cell_ID = receiver->GetCellID();
+ int deme_id = receiver->GetOrgInterface().GetDemeID();
+ std::pair<int, int> pos = pop.GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
+
+ // does receiver have x cordinate of zero
+ if(pos.first == 0) {
+ m_current_times++;
+ if(m_current_times == m_total_times) {
+ m_event_received = true;
+ }
+ }
+ }
+ return m_event_received;
+ }
+
+ virtual void Print(std::ostream& out) {
+ out << m_event->GetEventID() << " [ ";
+ for(std::set<int>::iterator i=m_cell_ids.begin(); i!=m_cell_ids.end(); i++) {
+ out << *i << " ";
+ }
+ out << "]\n";
+
+ Reset();
+ }
+
+ virtual void Reset() {
+ m_event_received = false;
+ m_stats_updated = false;
+ m_cell_ids.clear();
+ }
+
+ virtual bool PreviouslySatisfied() {
+ return m_event_received;
+ }
+
+ virtual cString GetName() {
+ return "EventReceivedLeftSide";
+ }
+
+ virtual void UpdateStats(cStats& stats) {
+ if(m_event_received && m_stats_updated) {
+ int eventCell = m_event->GetNextEventCellID();
+ while(eventCell != -1) {
+ stats.IncPredSat(eventCell);
+ eventCell = m_event->GetNextEventCellID();
+ }
+ m_stats_updated = true;
+ }
+ }
+
+ cPopulation& pop;
+ bool m_event_received;
+ bool m_stats_updated;
+ cDemeCellEvent* m_event;
+ std::set<int> m_cell_ids;
+ int m_total_times;
+ int m_current_times;
+};
+
#endif
Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc 2007-10-04 12:15:21 UTC (rev 2124)
+++ branches/energy/source/main/cPopulation.cc 2007-10-04 14:29:20 UTC (rev 2125)
@@ -1372,9 +1372,18 @@
}
}
-void cPopulation::AddDemeEventReceivedPred() {
- for (int deme_id = 0; deme_id < deme_array.GetSize(); deme_id++) {
- deme_array[deme_id].AddEventReceivedCenterPred();
+void cPopulation::AddDemePred(cString type, int times) {
+ if(type == "EventReceivedCenter") {
+ for (int deme_id = 0; deme_id < deme_array.GetSize(); deme_id++) {
+ deme_array[deme_id].AddEventReceivedCenterPred(times);
+ }
+ } else if(type == "EventReceivedLeftSide") {
+ for (int deme_id = 0; deme_id < deme_array.GetSize(); deme_id++) {
+ deme_array[deme_id].AddEventReceivedLeftSidePred(times);
+ }
+ } else {
+ cout << "Unknown Predicate\n";
+ exit(1);
}
}
@@ -1924,9 +1933,15 @@
for(int i = 0; i < GetNumDemes(); i++) {
cDeme& deme = GetDeme(i);
for(int j = 0; j < deme.GetNumPredicates(); j++) {
- if(deme.GetPredicateName(j) == "EventReceived") {
+ if(deme.GetPredicateName(j) == "EventReceivedCenter") {
df.GetOFStream() << m_world->GetStats().GetUpdate() << " ";
deme.PrintPredicate(j, df.GetOFStream());
+ } else if(deme.GetPredicateName(j) == "EventReceivedLeftSide") {
+ df.GetOFStream() << m_world->GetStats().GetUpdate() << " ";
+ deme.PrintPredicate(j, df.GetOFStream());
+ } else {
+ cout << "Unknown predicate type. Cannot print.\n";
+ exit(1);
}
}
}
Modified: branches/energy/source/main/cPopulation.h
===================================================================
--- branches/energy/source/main/cPopulation.h 2007-10-04 12:15:21 UTC (rev 2124)
+++ branches/energy/source/main/cPopulation.h 2007-10-04 14:29:20 UTC (rev 2125)
@@ -183,7 +183,7 @@
void ResetDemes();
void CopyDeme(int deme1_id, int deme2_id);
void SpawnDeme(int deme1_id, int deme2_id=-1);
- void AddDemeEventReceivedPred();
+ void AddDemePred(cString type, int times);
// Deme-related stats methods
void PrintDemeAllStats();
More information about the Avida-cvs
mailing list