[Avida-SVN] r2182 - in branches/energy: Avida.xcodeproj source/actions source/cpu source/main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Tue Nov 6 12:50:51 PST 2007
Author: beckma24
Date: 2007-11-06 15:50:51 -0500 (Tue, 06 Nov 2007)
New Revision: 2182
Added:
branches/energy/source/main/cOrgMovementPredicate.h
Modified:
branches/energy/Avida.xcodeproj/project.pbxproj
branches/energy/source/actions/EnvironmentActions.cc
branches/energy/source/actions/PopulationActions.cc
branches/energy/source/cpu/cHardwareCPU.cc
branches/energy/source/cpu/cTestCPUInterface.h
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/cOrgInterface.h
branches/energy/source/main/cOrganism.h
branches/energy/source/main/cPopulation.cc
branches/energy/source/main/cPopulationInterface.h
branches/energy/source/main/cStats.cc
branches/energy/source/main/cStats.h
Log:
Added movement predicates, similar to message predicates
Modified: branches/energy/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/energy/Avida.xcodeproj/project.pbxproj 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/Avida.xcodeproj/project.pbxproj 2007-11-06 20:50:51 UTC (rev 2182)
@@ -196,6 +196,7 @@
B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */; };
B4FA25A90C5EB7880086D4B5 /* cPhenPlastGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */; };
B516AF840C91E2D400023D53 /* cDemeCellEvent.cc in Sources */ = {isa = PBXBuildFile; fileRef = B516AF790C91E24600023D53 /* cDemeCellEvent.cc */; };
+ B55F37FA0CE0DAC8006750F9 /* cOrgMovementPredicate.h in Headers */ = {isa = PBXBuildFile; fileRef = B55F37F90CE0DAC8006750F9 /* cOrgMovementPredicate.h */; };
B59AA8650CC7D99E00469456 /* nRadioStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = B59AA8640CC7D99E00469456 /* nRadioStatus.h */; };
DCD8AC1F0C8A7C30004CBE6F /* cAnalyzeGenotypeTreeStats.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCA4BEC10C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.cc */; };
/* End PBXBuildFile section */
@@ -213,6 +214,23 @@
};
/* End PBXBuildRule section */
+/* Begin PBXBuildStyle section */
+ B55F38D40CE1069F006750F9 /* Development */ = {
+ isa = PBXBuildStyle;
+ buildSettings = {
+ COPY_PHASE_STRIP = NO;
+ };
+ name = Development;
+ };
+ B55F38D50CE1069F006750F9 /* Deployment */ = {
+ isa = PBXBuildStyle;
+ buildSettings = {
+ COPY_PHASE_STRIP = YES;
+ };
+ name = Deployment;
+ };
+/* End PBXBuildStyle section */
+
/* Begin PBXContainerItemProxy section */
56F555DA0C3B36FC00E2E929 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
@@ -822,6 +840,7 @@
B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPhenPlastGenotype.cc; sourceTree = "<group>"; };
B516AF790C91E24600023D53 /* cDemeCellEvent.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = cDemeCellEvent.cc; path = source/main/cDemeCellEvent.cc; sourceTree = SOURCE_ROOT; };
B516AF7A0C91E24600023D53 /* cDemeCellEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = cDemeCellEvent.h; path = source/main/cDemeCellEvent.h; sourceTree = SOURCE_ROOT; };
+ B55F37F90CE0DAC8006750F9 /* cOrgMovementPredicate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cOrgMovementPredicate.h; sourceTree = "<group>"; };
B59AA8640CC7D99E00469456 /* nRadioStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nRadioStatus.h; sourceTree = "<group>"; };
DCA4BEC10C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cAnalyzeGenotypeTreeStats.cc; sourceTree = "<group>"; };
DCA4BEC20C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeGenotypeTreeStats.h; sourceTree = "<group>"; };
@@ -1372,6 +1391,7 @@
DCC310040762539D008F7A48 /* main */ = {
isa = PBXGroup;
children = (
+ B55F37F90CE0DAC8006750F9 /* cOrgMovementPredicate.h */,
B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */,
B4FA25800C5EB6510086D4B5 /* cPhenPlastGenotype.h */,
B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */,
@@ -1636,6 +1656,7 @@
buildActionMask = 2147483647;
files = (
B59AA8650CC7D99E00469456 /* nRadioStatus.h in Headers */,
+ B55F37FA0CE0DAC8006750F9 /* cOrgMovementPredicate.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1783,6 +1804,12 @@
DCC30C4D0762532C008F7A48 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
+ buildSettings = {
+ };
+ buildStyles = (
+ B55F38D40CE1069F006750F9 /* Development */,
+ B55F38D50CE1069F006750F9 /* Deployment */,
+ );
hasScannedForEncodings = 0;
mainGroup = DCC30C490762532C008F7A48;
productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;
Modified: branches/energy/source/actions/EnvironmentActions.cc
===================================================================
--- branches/energy/source/actions/EnvironmentActions.cc 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/actions/EnvironmentActions.cc 2007-11-06 20:50:51 UTC (rev 2182)
@@ -631,9 +631,49 @@
}
};
+
+/*******************************/
+class cActionDelayedDemeEventGradient : public cAction
+{
+private:
+ 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;
+ int m_time_to_live; // update when event no longer exists
+
+public:
+ cActionDelayedDemeEventGradient(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();
+ if (largs.GetSize()) m_y1 = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_x2 = largs.PopWord().AsInt();
+ 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();
+ 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> <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).SetCellEventGradient(m_x1, m_y1, m_x2, m_y2, m_delay, m_duration, m_static_pos, m_time_to_live);
+ }
+ }
+};
+/*******************************/
+
void RegisterEnvironmentActions(cActionLibrary* action_lib)
{
action_lib->Register<cActionDelayedDemeEvent>("DelayedDemeEvent");
+ action_lib->Register<cActionDelayedDemeEventGradient>("DelayedDemeEventGradient");
action_lib->Register<cActionInjectResource>("InjectResource");
action_lib->Register<cActionInjectScaledResource>("InjectScaledResource");
action_lib->Register<cActionOutflowScaledResource>("OutflowScaledResource");
Modified: branches/energy/source/actions/PopulationActions.cc
===================================================================
--- branches/energy/source/actions/PopulationActions.cc 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/actions/PopulationActions.cc 2007-11-06 20:50:51 UTC (rev 2182)
@@ -1007,6 +1007,8 @@
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 if (in_trigger == "sat-mov-pred") m_rep_trigger = 5;
+ else if (in_trigger == "deme-age-noBirth") m_rep_trigger = 6;
else {
cString err("Unknown replication trigger '");
err += in_trigger;
@@ -1082,7 +1084,6 @@
}
};
-
/*
Added predicate to all demes that is satisified when an event ID reaches the center of the deme
*/
@@ -1106,6 +1107,28 @@
};
/*
+ Added predicate to all demes that is satisified when an organism reaches the center of an event
+*/
+class cActionPred_DemeEventMoveCenter : public cAction
+{
+private:
+ int m_times;
+
+public:
+ cActionPred_DemeEventMoveCenter(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("EventMovedIntoCenter", m_times);
+ }
+};
+
+/*
Designed to serve as a control for the compete_demes. Each deme is
copied into itself and the parameters reset.
*/
@@ -1598,7 +1621,8 @@
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<cActionPred_DemeEventReceivedLeftSide>("Pred_DemeEventReceivedLeftSide");
+ action_lib->Register<cActionPred_DemeEventMoveCenter>("Pred_DemeEventMoveCenter");
action_lib->Register<cActionNewTrial>("NewTrial");
action_lib->Register<cActionCompeteOrganisms>("CompeteOrganisms");
Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/cpu/cHardwareCPU.cc 2007-11-06 20:50:51 UTC (rev 2182)
@@ -3817,9 +3817,6 @@
int left, right, center;
cPopulationCell mycell;
- // Get population
- cPopulation& pop = m_world->GetPopulation();
-
// Fill in left, right, center with m_cell_data via GetCellData()
// GetRegister(out_reg) = m_world->GetPopulation().GetCell(cellID).GetCellData();
mycell = m_world->GetPopulation().GetCell(organism->GetCellID());
@@ -3889,6 +3886,9 @@
// Swap inputs and facings between cells using helper function
pop.MoveOrganisms(ctx, pop.GetCell(fromcellID), pop.GetCell(destcellID));
+ // updates movement predicates
+ m_world->GetStats().Move(*organism);
+
return true;
} else {
return false;
Modified: branches/energy/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/energy/source/cpu/cTestCPUInterface.h 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/cpu/cTestCPUInterface.h 2007-11-06 20:50:51 UTC (rev 2182)
@@ -45,7 +45,7 @@
virtual ~cTestCPUInterface() { ; }
int GetCellID() { return 0; }
- int GetDemeID() { return 0; }
+ int GetDemeID() const { return 0; }
void SetCellID(int in_id) { ; }
void SetDemeID(int in_id) { ; }
Modified: branches/energy/source/main/cDeme.cc
===================================================================
--- branches/energy/source/main/cDeme.cc 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/main/cDeme.cc 2007-11-06 20:50:51 UTC (rev 2182)
@@ -24,6 +24,7 @@
#include "cDeme.h"
#include "cDemeCellEvent.h"
#include "cOrgMessagePredicate.h"
+#include "cOrgMovementPredicate.h"
#include "cPopulation.h"
#include "cPopulationCell.h"
#include "cResource.h"
@@ -87,8 +88,12 @@
int eventCell = event.GetNextEventCellID();
while(eventCell != -1) {
// place event ID in cells' data
- m_world->GetPopulation().GetCell(GetCellID(eventCell)).SetCellData(event.GetEventID());
-
+ if(event.IsDecayed()) {
+ m_world->GetPopulation().GetCell(GetCellID(eventCell)).SetCellData(event.GetEventIDDecay(GetRelativeCellPosition(eventCell)));
+ } else {
+ m_world->GetPopulation().GetCell(GetCellID(eventCell)).SetCellData(event.GetEventID());
+ }
+
// record activation of each cell in stats
std::pair<int, int> pos = GetRelativeCellPosition(eventCell);
m_world->GetStats().IncEventCount(pos.first, pos.second);
@@ -219,6 +224,12 @@
cell_events.Add(demeEvent);
}
+void cDeme::SetCellEventGradient(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);
+ demeEvent.DecayEventIDFromCenter();
+ cell_events.Add(demeEvent);
+}
+
int cDeme::GetNumEvents() {
return cell_events.Size();
}
@@ -242,6 +253,16 @@
return false;
}
+bool cDeme::MovPredSatisfiedPreviously() {
+ for(int i = 0; i < message_pred_list.Size(); i++) {
+ if(movement_pred_list[i]->PreviouslySatisfied()) {
+ movement_pred_list[i]->UpdateStats(m_world->GetStats());
+ return true;
+ }
+ }
+ return false;
+}
+
void cDeme::AddEventReceivedCenterPred(int times) {
if(cell_events.Size() == 0) {
cerr<<"Error: An EventReceivedCenterPred cannot be created until a CellEvent is added.\n";
@@ -271,10 +292,28 @@
}
}
-int cDeme::GetNumPredicates() {
+void cDeme::AddEventMoveCenterPred(int times) {
+ if(cell_events.Size() == 0) {
+ cerr<<"Error: An EventMovedIntoCenter cannot be created until a CellEvent is added.\n";
+ exit(1);
+ }
+ for(int i = 0; i < cell_events.Size(); i++) {
+ if(!cell_events[i].IsDead()) {
+ cOrgMovementPred_EventMovedIntoCenter* pred = new cOrgMovementPred_EventMovedIntoCenter(&cell_events[i], m_world->GetPopulation(), times);
+ m_world->GetStats().AddMovementPredicate(pred);
+ movement_pred_list.Add(pred);
+ }
+ }
+}
+
+int cDeme::GetNumMessagePredicates() {
return message_pred_list.Size();
}
+int cDeme::GetNumMovementPredicates() {
+ return movement_pred_list.Size();
+}
+
bool cDeme::PredicatePreviouslySatisfied(int pred_id) {
assert(pred_id < message_pred_list.Size());
return message_pred_list[pred_id]->PreviouslySatisfied();
Modified: branches/energy/source/main/cDeme.h
===================================================================
--- branches/energy/source/main/cDeme.h 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/main/cDeme.h 2007-11-06 20:50:51 UTC (rev 2182)
@@ -33,6 +33,7 @@
#include "tArray.h"
#include "tVector.h"
+class cOrgMovementPredicate;
class cOrgMessagePredicate;
class cPopulationCell;
class cResource;
@@ -61,6 +62,7 @@
tVector<cDemeCellEvent> cell_events;
tVector<cOrgMessagePredicate*> message_pred_list;
+ tVector<cOrgMovementPredicate*> movement_pred_list;
std::map<int, cPopulationCell*> cells_blocked_from_sending;
std::map<int, cPopulationCell*> cells_paused_from_sending;
@@ -118,13 +120,17 @@
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, int time_to_live);
+ void SetCellEventGradient(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();
+ bool MovPredSatisfiedPreviously();
void AddEventReceivedCenterPred(int times);
void AddEventReceivedLeftSidePred(int times);
- int GetNumPredicates();
+ void AddEventMoveCenterPred(int times);
+ int GetNumMessagePredicates();
+ int GetNumMovementPredicates();
bool PredicatePreviouslySatisfied(int pred_id);
cString GetPredicateName(int pred_id);
void PrintPredicate(int pred_id, std::ostream& out);
Modified: branches/energy/source/main/cDemeCellEvent.cc
===================================================================
--- branches/energy/source/main/cDemeCellEvent.cc 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/main/cDemeCellEvent.cc 2007-11-06 20:50:51 UTC (rev 2182)
@@ -2,15 +2,16 @@
#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, 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)
- , m_dead (false)
+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_use_gradient(false)
+, m_active(false)
+, m_static_pos(static_pos)
+, m_dead (false)
{
assert(x1 <= x2);
assert(y1 <= y2);
@@ -27,6 +28,9 @@
i++;
}
}
+ pair<int, int> centerBottomleft = make_pair((int)floor(((x2-x1)/2.0)), (int)floor(((y2-y1)/2.0)));
+ pair<int, int> centerTopRight = make_pair((int)ceil(((x2-x1)/2.0)), (int)ceil(((y2-y1)/2.0)));
+ center = make_pair(centerBottomleft, centerTopRight);
} else {
//non-static event position
m_event_width = x2-x1;
@@ -46,7 +50,7 @@
if(m_dead) {
return;
}
-
+
m_eventID = m_world->GetRandom().GetInt(0x7FFFFFFF);
if(!m_static_pos) {
//non-static event position
@@ -59,6 +63,9 @@
i++;
}
}
+ pair<int, int> centerBottomleft = make_pair((int)floor((m_event_width/2.0)), (int)floor((m_event_height/2.0)));
+ pair<int, int> centerTopRight = make_pair((int)ceil((m_event_width/2.0)), (int)ceil((m_event_height/2.0)));
+ center = make_pair(centerBottomleft, centerTopRight);
}
m_active = true;
}
@@ -84,6 +91,32 @@
return m_eventID;
}
+int cDemeCellEvent::GetEventIDDecay(pair<int, int> pos) {
+ if(m_dead){
+ return -1;
+ }
+
+ double maxd = sqrt(pow(m_deme_width-1.0 ,2) + pow(m_deme_height-1.0 ,2));//cdistance(1,1,wx,wy);
+ double top = ceil(maxd);
+ pair<double, double> centerPoint = GetCenter(); // # dx.dy -- coordinates of peak value
+ double cdistance = sqrt(pow(pos.first-centerPoint.first ,2) + pow(pos.second-centerPoint.second ,2));
+
+ // return decayed value
+ int decayed_value = (int)floor(linmap(cdistance,0.0,top,top*1.414,1.0));
+ return decayed_value;
+}
+
+std::pair<double, double> cDemeCellEvent::GetCenter() const {
+ return make_pair(center.first.first+center.second.first/2.0, center.first.second+center.second.second/2.0);
+}
+
+bool cDemeCellEvent::InCenter(pair<int, int> pos) const {
+ if((center.first <= pos) && (pos <= center.second)) {
+ return true;
+ }
+ return false;
+}
+
int cDemeCellEvent::GetTimeToLive() {
if(m_dead){
return 0;
@@ -101,3 +134,13 @@
void cDemeCellEvent::DeactivateEvent() {
m_active = false;
}
+
+double cDemeCellEvent::linmap(const double dp, const double ds, const double de, const double rs, const double re) const {
+ double rp;
+ if (0.0 == (de - ds)) { // Domain has zero length; exception should be taken
+ rp = 0.0;
+ } else {
+ rp = (dp - ds) * ((re - rs) / (de - ds)) + rs;
+ }
+ return rp;
+}
Modified: branches/energy/source/main/cDemeCellEvent.h
===================================================================
--- branches/energy/source/main/cDemeCellEvent.h 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/main/cDemeCellEvent.h 2007-11-06 20:50:51 UTC (rev 2182)
@@ -1,7 +1,9 @@
#ifndef cDemeCellEvent_h
#define cDemeCellEvent_h
+#include <utility>
#include "tArray.h"
+
class cWorld;
class cDemeCellEvent {
@@ -10,8 +12,11 @@
int m_eventID;
int m_delay, m_duration, m_iter, m_deme_width, m_deme_height;
int m_event_width, m_event_height, m_time_to_live;
- bool m_active, m_static_pos, m_dead;
+ bool m_use_gradient, m_active, m_static_pos, m_dead;
+ std::pair<std::pair<int, int>, std::pair<int, int> > center;
+ std::pair<double, double> GetCenter() const;
+
public:
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);
@@ -19,12 +24,19 @@
int GetDelay();
int GetDuration();
int GetEventID();
+ int GetEventIDDecay(std::pair<int, int> pos);
int GetTimeToLive();
bool IsActive();
- bool IsDead() { return m_dead; }
+ bool IsDead() const { return m_dead; }
+ bool IsDecayed() { return m_use_gradient; }
+ bool InCenter(std::pair<int, int> pos) const;
+ void DecayEventIDFromCenter() { m_use_gradient = true; }
void ActivateEvent(cWorld* m_world);
void DeactivateEvent();
void Terminate() { m_dead = true; }
+
+ // gradient generators
+ double linmap(const double dp, const double ds, const double de, const double rs, const double re) const;
};
#endif
Modified: branches/energy/source/main/cOrgInterface.h
===================================================================
--- branches/energy/source/main/cOrgInterface.h 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/main/cOrgInterface.h 2007-11-06 20:50:51 UTC (rev 2182)
@@ -54,7 +54,7 @@
virtual ~cOrgInterface() { ; }
virtual int GetCellID() = 0;
- virtual int GetDemeID() = 0;
+ virtual int GetDemeID() const = 0;
virtual void SetCellID(int in_id) = 0;
virtual void SetDemeID(int in_id) = 0;
Added: branches/energy/source/main/cOrgMovementPredicate.h
===================================================================
--- branches/energy/source/main/cOrgMovementPredicate.h (rev 0)
+++ branches/energy/source/main/cOrgMovementPredicate.h 2007-11-06 20:50:51 UTC (rev 2182)
@@ -0,0 +1,138 @@
+/*
+ * cOrgMovementPredicate.h
+ * Avida
+ *
+ * Created by Benjamin Beckmann on 11/6/07.
+ * Copyright 2007 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+/*
+ * cOrgMessagePredicate.h
+ * Avida
+ *
+ * Copyright 2005-2006 Michigan State University. All rights reserved.
+ * Copyright 1993-2003 California Institute of Technology.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef cOrgMovementPredicate_h
+#define cOrgMovementPredicate_h
+
+#include <iostream>
+#include <functional>
+
+#include "cDemeCellEvent.h"
+#include "cOrganism.h"
+#include "cPopulation.h"
+#include "cStats.h"
+
+
+/*! \brief An STL-compatible predicate on cOrgMessages. The intent here is to
+provide a straightforward way to track arbitrary messages *wherever* they appear
+in the population. The most utility can be had from message predicates if they're
+installed into cStats (since every message goes through cStats). */
+struct cOrgMovementPredicate : public std::unary_function<cOrganism, bool>
+{
+ virtual ~cOrgMovementPredicate() { }
+ virtual bool operator()(const cOrganism& org) = 0;
+ virtual void Print(std::ostream& out) { }
+ virtual void Reset() { }
+ virtual bool PreviouslySatisfied() = 0;
+ virtual cString GetName() = 0;
+ virtual void UpdateStats(cStats& stats) {}
+ virtual cDemeCellEvent* GetEvent() { return NULL; }
+};
+
+/*! A predicate that returns true if an organism has made it to the center of the gradient event
+*/
+struct cOrgMovementPred_EventMovedIntoCenter : public cOrgMovementPredicate {
+ cOrgMovementPred_EventMovedIntoCenter(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){ }
+
+ ~cOrgMovementPred_EventMovedIntoCenter() { }
+
+ virtual bool operator()(const cOrganism& org) {
+ if(m_event->IsDead()) {
+ return false;
+ }
+
+ if(m_event->IsActive()) {
+ // find organism coordinates
+ int absolute_cell_ID = org.GetCellID();
+ int deme_id = org.GetOrgInterface().GetDemeID();
+ std::pair<int, int> pos = pop.GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
+
+ // does receiver have x cordinate of zero
+ if(m_event->InCenter(pos)) {
+ m_current_times++;
+ if(m_current_times >= m_total_times) {
+ m_event_received = true;
+ }
+ }
+ }
+ return m_event_received;
+ }
+
+ virtual void Print(std::ostream& out) {
+ if(m_event->IsDead()) {
+ return;
+ }
+ // WHAT TO PRINT
+ }
+
+ virtual void Reset() {
+ m_event_received = false;
+ m_stats_updated = false;
+ m_current_times = 0;
+ }
+
+ virtual bool PreviouslySatisfied() {
+ return m_event_received;
+ }
+
+ virtual cString GetName() {
+ return "EventMovedIntoCenter";
+ }
+
+ 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;
+ }*/
+ }
+
+ cDemeCellEvent* GetEvent() { return m_event; }
+
+ cPopulation& pop;
+ bool m_event_received;
+ bool m_stats_updated;
+ cDemeCellEvent* m_event;
+ int m_total_times;
+ int m_current_times;
+};
+
+#endif
Modified: branches/energy/source/main/cOrganism.h
===================================================================
--- branches/energy/source/main/cOrganism.h 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/main/cOrganism.h 2007-11-06 20:50:51 UTC (rev 2182)
@@ -198,7 +198,7 @@
void Die() { m_interface->Die(); m_is_dead = true; }
void Kaboom(int dist) { m_interface->Kaboom(dist);}
void SpawnDeme() { m_interface->SpawnDeme(); }
- int GetCellID() { return m_interface->GetCellID(); }
+ int GetCellID() const { return m_interface->GetCellID(); }
int GetDebugInfo() { return m_interface->Debug(); }
int GetID() { return m_id; }
bool GetSentActive() { return m_sent_active; }
Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/main/cPopulation.cc 2007-11-06 20:50:51 UTC (rev 2182)
@@ -426,9 +426,7 @@
{
assert(in_organism != NULL);
assert(in_organism->GetGenome().GetSize() >= 1);
-// assert(in_organism->GetGenome().GetSize() >= 1);
-
in_organism->SetOrgInterface(new cPopulationInterface(m_world));
// If the organism does not have a genotype, give it one! No parent
@@ -1061,8 +1059,10 @@
0: 'all' - ...all non-empty demes in the population.
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
+3: 'deme-age' - ...demes who have reached their maximum age and are not sterile
+4: 'sat-msg-pred' - ...demes whose message predicate was previously satisfied
+5: 'sat-mov-pred' - ...demes whose movement predicate was previously satisfied
+6: 'deme-age-noBirth' - ...demes who have reached their maximum age
*/
void cPopulation::ReplicateDemes(int rep_trigger)
@@ -1112,6 +1112,15 @@
if(!(source_deme.MsgPredSatisfiedPreviously())) continue;
break;
}
+ case 5: {
+ if(!(source_deme.MovPredSatisfiedPreviously())) continue;
+ break;
+ }
+ case 6: {
+ // Replicate old demes
+ if(source_deme.GetAge() < m_world->GetConfig().MAX_DEME_AGE.Get()) continue;
+ break;
+ }
default: {
cerr << "ERROR: Invalid replication trigger " << rep_trigger
<< " in cPopulation::ReplicateDemes()" << endl;
@@ -1447,6 +1456,10 @@
for (int deme_id = 0; deme_id < deme_array.GetSize(); deme_id++) {
deme_array[deme_id].AddEventReceivedLeftSidePred(times);
}
+ } else if(type == "EventMovedIntoCenter") {
+ for (int deme_id = 0; deme_id < deme_array.GetSize(); deme_id++) {
+ deme_array[deme_id].AddEventMoveCenterPred(times);
+ }
} else {
cout << "Unknown Predicate\n";
exit(1);
@@ -1860,7 +1873,7 @@
//ignore events that are dead
- int num_predicates = GetDeme(1).GetNumPredicates();
+ int num_predicates = GetDeme(1).GetNumMessagePredicates();
tArray<int> predicateTotals(num_predicates);
tArray<cString> predicateNames(num_predicates);
predicateTotals.SetAll(0);
@@ -2002,7 +2015,7 @@
cDataFile & df = m_world->GetDataFile(filename);
for(int i = 0; i < GetNumDemes(); i++) {
cDeme& deme = GetDeme(i);
- for(int j = 0; j < deme.GetNumPredicates(); j++) {
+ for(int j = 0; j < deme.GetNumMessagePredicates(); j++) {
if(deme.GetPredicateName(j) == "EventReceivedCenter") {
df.GetOFStream() << m_world->GetStats().GetUpdate() << " ";
deme.PrintPredicate(j, df.GetOFStream());
Modified: branches/energy/source/main/cPopulationInterface.h
===================================================================
--- branches/energy/source/main/cPopulationInterface.h 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/main/cPopulationInterface.h 2007-11-06 20:50:51 UTC (rev 2182)
@@ -56,7 +56,7 @@
virtual ~cPopulationInterface() { ; }
int GetCellID() { return m_cell_id; }
- int GetDemeID() { return m_deme_id; }
+ int GetDemeID() const { return m_deme_id; }
void SetCellID(int in_id) { m_cell_id = in_id; }
void SetDemeID(int in_id) { m_deme_id = in_id; }
Modified: branches/energy/source/main/cStats.cc
===================================================================
--- branches/energy/source/main/cStats.cc 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/main/cStats.cc 2007-11-06 20:50:51 UTC (rev 2182)
@@ -37,7 +37,8 @@
#include "tDataEntry.h"
#include "cOrgMessage.h"
#include "cOrgMessagePredicate.h"
-
+#include "cOrgMovementPredicate.h"
+#include "cOrganism.h"
#include "functions.h"
#include <cfloat>
@@ -1163,8 +1164,17 @@
from_to_message_list[msg.GetSender()->GetCellID()] = msg.GetReceiver()->GetCellID();
}
+/*! This method is called whenever an organism moves.*/
+void cStats::Move(const cOrganism& org) {
+ // Check to see if this message matches any of our predicates.
+ for(movement_pred_ptr_list::iterator i=m_movement_predicates.begin();
+ i!=m_movement_predicates.end(); ++i) {
+ (**i)(org); // Predicate is responsible for tracking info about movement.
+ }
+}
-/*! This method adds a message predicate to the list of all predicates. Each predicate
+
+/*! This method adds a message predicate to the list of all message predicates. Each predicate
in the list is evaluated for every sent message.
NOTE: cStats does NOT own the predicate pointer! (It DOES NOT delete them!)
@@ -1174,6 +1184,17 @@
m_message_predicates.push_back(predicate);
}
+/*! This method adds a movement predicate to the list of all movement predicates. Each predicate
+in the list is evaluated for every organism movement.
+
+NOTE: cStats does NOT own the predicate pointer! (It DOES NOT delete them!)
+*/
+void cStats::AddMovementPredicate(cOrgMovementPredicate* predicate)
+{
+ m_movement_predicates.push_back(predicate);
+}
+
+
void cStats::RemoveMessagePredicate(cOrgMessagePredicate* predicate)
{
for(message_pred_ptr_list::iterator iter = m_message_predicates.begin(); iter != m_message_predicates.end(); iter++) {
Modified: branches/energy/source/main/cStats.h
===================================================================
--- branches/energy/source/main/cStats.h 2007-11-06 04:24:49 UTC (rev 2181)
+++ branches/energy/source/main/cStats.h 2007-11-06 20:50:51 UTC (rev 2182)
@@ -70,8 +70,10 @@
class cGenotype;
class cInjectGenotype;
class cWorld;
+class cOrganism;
class cOrgMessage;
class cOrgMessagePredicate;
+class cOrgMovementPredicate;
class cStats
{
@@ -696,6 +698,16 @@
message_pred_ptr_list m_message_predicates;
// -------- End messaging support --------
+
+ // -------- Movement support -------------
+public:
+ //! Type for a list of pointers to movement predicates.
+ typedef std::vector<cOrgMovementPredicate*> movement_pred_ptr_list;
+ void Move(const cOrganism& org);
+ void AddMovementPredicate(cOrgMovementPredicate* predicate);
+
+protected:
+ movement_pred_ptr_list m_movement_predicates;
};
More information about the Avida-cvs
mailing list