[Avida-SVN] r2351 - in branches/energy/source: actions cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Thu Feb 21 06:36:31 PST 2008
Author: beckma24
Date: 2008-02-21 09:36:30 -0500 (Thu, 21 Feb 2008)
New Revision: 2351
Modified:
branches/energy/source/actions/PopulationActions.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/cOrgMovementPredicate.h
branches/energy/source/main/cOrganism.h
branches/energy/source/main/cPopulation.cc
branches/energy/source/main/cPopulation.h
branches/energy/source/main/cPopulationInterface.cc
branches/energy/source/main/cPopulationInterface.h
Log:
Added Pred_DemeEventNUniqueIndividualsMovedIntoTarget
Modified: branches/energy/source/actions/PopulationActions.cc
===================================================================
--- branches/energy/source/actions/PopulationActions.cc 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/actions/PopulationActions.cc 2008-02-21 14:36:30 UTC (rev 2351)
@@ -1191,6 +1191,29 @@
};
/*
+ Added predicate to all demes that is satisified when a number of organisms
+ reach a target cell
+*/
+class cActionPred_DemeEventEventNUniqueIndividualsMovedIntoTarget : public cAction
+{
+private:
+ int m_numorgs;
+
+public:
+ cActionPred_DemeEventEventNUniqueIndividualsMovedIntoTarget(cWorld* world, const cString& args) : cAction(world, args), m_numorgs(1) {
+ cString largs(args);
+ if (largs.GetSize()) m_numorgs = largs.PopWord().AsInt();
+ }
+
+ static const cString GetDescription() { return "Arguments: [int numorgs=1]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ m_world->GetPopulation().AddDemePred("EventNUniqueIndividualsMovedIntoTarget", m_numorgs);
+ }
+};
+
+/*
Designed to serve as a control for the compete_demes. Each deme is
copied into itself and the parameters reset.
*/
@@ -1687,6 +1710,7 @@
action_lib->Register<cActionPred_DemeEventMoveCenter>("Pred_DemeEventMoveCenter");
action_lib->Register<cActionPred_DemeEventMoveBetweenTargets>("Pred_DemeEventMoveBetweenTargets");
action_lib->Register<cActionPred_DemeEventMigrateToTargets>("Pred_DemeEventMigrateToTargets");
+ action_lib->Register<cActionPred_DemeEventEventNUniqueIndividualsMovedIntoTarget>("Pred_DemeEventNUniqueIndividualsMovedIntoTarget");
action_lib->Register<cActionNewTrial>("NewTrial");
action_lib->Register<cActionCompeteOrganisms>("CompeteOrganisms");
Modified: branches/energy/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/energy/source/cpu/cTestCPUInterface.h 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/cpu/cTestCPUInterface.h 2008-02-21 14:36:30 UTC (rev 2351)
@@ -48,7 +48,7 @@
int GetBirthCellID() { return 0; }
int GetPrevTaskCellID() { return 0; }
void AddReachedTaskCell() { }
- int GetNumTaskCellsReached() { return 0; }
+ //int GetNumTaskCellsReached() { return 0; }
int GetDemeID() const { return 0; }
void SetCellID(int in_id) { ; }
void SetBirthCellID(int in_id) { ; }
Modified: branches/energy/source/main/cDeme.cc
===================================================================
--- branches/energy/source/main/cDeme.cc 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/main/cDeme.cc 2008-02-21 14:36:30 UTC (rev 2351)
@@ -395,6 +395,19 @@
movement_pred_list.Add(pred);
}
+void cDeme::AddEventEventNUniqueIndividualsMovedIntoTargetPred(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_EventNUniqueIndividualsMovedIntoTarget* pred = new cOrgMovementPred_EventNUniqueIndividualsMovedIntoTarget(&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();
Modified: branches/energy/source/main/cDeme.h
===================================================================
--- branches/energy/source/main/cDeme.h 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/main/cDeme.h 2008-02-21 14:36:30 UTC (rev 2351)
@@ -136,6 +136,7 @@
void AddEventMoveCenterPred(int times);
void AddEventMoveBetweenTargetsPred(int times);
void AddEventMigrateToTargetsPred(int times);
+ void AddEventEventNUniqueIndividualsMovedIntoTargetPred(int times);
int GetNumMessagePredicates();
int GetNumMovementPredicates();
bool PredicatePreviouslySatisfied(int pred_id);
Modified: branches/energy/source/main/cDemeCellEvent.cc
===================================================================
--- branches/energy/source/main/cDemeCellEvent.cc 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/main/cDemeCellEvent.cc 2008-02-21 14:36:30 UTC (rev 2351)
@@ -122,6 +122,14 @@
return false;
}
+bool cDemeCellEvent::OnEventCell(int demeRelative_cell_ID) const {
+ for(int i = 0; i < m_event_cells.GetSize(); i++) {
+ if(m_event_cells[i] == demeRelative_cell_ID)
+ return true;
+ }
+ return false;
+}
+
int cDemeCellEvent::GetTimeToLive() {
if(m_dead){
return 0;
Modified: branches/energy/source/main/cDemeCellEvent.h
===================================================================
--- branches/energy/source/main/cDemeCellEvent.h 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/main/cDemeCellEvent.h 2008-02-21 14:36:30 UTC (rev 2351)
@@ -33,6 +33,7 @@
bool IsDead() const { return m_dead; }
bool IsDecayed() { return m_use_gradient; }
bool InCenter(std::pair<int, int> pos) const;
+ bool OnEventCell(int demeRelative_cell_ID) const;
void SetEventID(int ID) { m_eventID = ID; m_id_set = true;}
Modified: branches/energy/source/main/cOrgInterface.h
===================================================================
--- branches/energy/source/main/cOrgInterface.h 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/main/cOrgInterface.h 2008-02-21 14:36:30 UTC (rev 2351)
@@ -56,7 +56,7 @@
virtual int GetCellID() = 0;
virtual int GetBirthCellID() = 0;
virtual int GetPrevTaskCellID() = 0;
- virtual int GetNumTaskCellsReached() = 0;
+ //virtual int GetNumTaskCellsReached() = 0;
virtual void AddReachedTaskCell() = 0;
virtual int GetDemeID() const = 0;
virtual void SetCellID(int in_id) = 0;
Modified: branches/energy/source/main/cOrgMovementPredicate.h
===================================================================
--- branches/energy/source/main/cOrgMovementPredicate.h 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/main/cOrgMovementPredicate.h 2008-02-21 14:36:30 UTC (rev 2351)
@@ -35,6 +35,7 @@
#include <iostream>
#include <functional>
+#include <set>
#include "cDemeCellEvent.h"
#include "cOrganism.h"
@@ -384,4 +385,79 @@
+struct cOrgMovementPred_EventNUniqueIndividualsMovedIntoTarget : public cOrgMovementPredicate {
+ cOrgMovementPred_EventNUniqueIndividualsMovedIntoTarget(cDemeCellEvent* event, cPopulation& population, int unique_individuals) :
+ pop(population)
+ , m_satisfied(false)
+ , m_stats_updated(false)
+ , m_event(event)
+ , m_total_individuals(unique_individuals)
+ { }
+
+ virtual bool operator()(const cOrganism& org) {
+ int deme_id = org.GetOrgInterface().GetDemeID();
+
+ if(deme_id != m_event->GetDeme()->GetDemeID() || m_event->IsDead()) {
+ return false;
+ }
+
+ if(m_event->IsActive()) {
+ // find organism coordinates
+ int absolute_cell_ID = org.GetCellID();
+ std::pair<int, int> pos = pop.GetDeme(deme_id).GetRelativeCellPosition(absolute_cell_ID);
+
+ int relative_cell_ID = pop.GetDeme(deme_id).GetCellID(pos.first, pos.second);
+
+ // is the organism in an event cell
+ if(m_event->OnEventCell(relative_cell_ID)) {
+ unique_org_ids.insert(org.GetID());
+
+ // have enough unique organisms visited the event cells?
+ if(unique_org_ids.size() >= m_total_individuals) {
+ m_satisfied = true;
+ }
+ }
+ }
+ return m_satisfied;
+ }
+
+ virtual void Print(std::ostream& out) {
+ if(m_event->IsDead()) {
+ return;
+ }
+ // WHAT TO PRINT
+ }
+
+ virtual void Reset() {
+ m_satisfied = false;
+ m_stats_updated = false;
+ unique_org_ids.clear();
+ }
+
+ virtual bool PreviouslySatisfied() {
+ return m_satisfied;
+ }
+
+ virtual cString GetName() {
+ return "EventNUniqueIndividualsMovedIntoTarget";
+ }
+
+ virtual void UpdateStats(cStats& stats) {
+ if(m_satisfied && !m_stats_updated) {
+ m_stats_updated = true;
+ }
+ }
+
+ virtual cDemeCellEvent* GetEvent() {
+ return m_event;
+ }
+
+ cPopulation& pop;
+ bool m_satisfied;
+ bool m_stats_updated;
+ cDemeCellEvent* m_event;
+ int m_total_individuals;
+ set<int> unique_org_ids;
+};
+
#endif
Modified: branches/energy/source/main/cOrganism.h
===================================================================
--- branches/energy/source/main/cOrganism.h 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/main/cOrganism.h 2008-02-21 14:36:30 UTC (rev 2351)
@@ -210,10 +210,10 @@
int GetBirthCellID() const { return m_interface->GetBirthCellID(); }
int GetPrevTaskCellID() const { return m_interface->GetPrevTaskCellID(); }
void SetPrevTaskCellID(int id) const { m_interface->SetPrevTaskCellID(id); }
- int GetNumTaskCellsReached() const { m_interface->GetNumTaskCellsReached(); }
+ //int GetNumTaskCellsReached() const { m_interface->GetNumTaskCellsReached(); }
void AddReachedTaskCell() { m_interface->AddReachedTaskCell(); }
int GetDebugInfo() { return m_interface->Debug(); }
- int GetID() { return m_id; }
+ int GetID() const { return m_id; }
bool GetSentActive() { return m_sent_active; }
void SendValue(int value) { m_sent_active = true; m_sent_value = value; }
int RetrieveSentValue() { m_sent_active = false; return m_sent_value; }
Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/main/cPopulation.cc 2008-02-21 14:36:30 UTC (rev 2351)
@@ -1539,6 +1539,10 @@
for (int deme_id = 0; deme_id < deme_array.GetSize(); deme_id++) {
deme_array[deme_id].AddEventMigrateToTargetsPred(times);
}
+ } else if(type == "EventNUniqueIndividualsMovedIntoTarget") {
+ for (int deme_id = 0; deme_id < deme_array.GetSize(); deme_id++) {
+ deme_array[deme_id].AddEventEventNUniqueIndividualsMovedIntoTargetPred(times);
+ }
} else {
cout << "Unknown Predicate\n";
exit(1);
Modified: branches/energy/source/main/cPopulation.h
===================================================================
--- branches/energy/source/main/cPopulation.h 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/main/cPopulation.h 2008-02-21 14:36:30 UTC (rev 2351)
@@ -238,6 +238,7 @@
const tArray<double>& GetResources() const { return resource_count.GetResources(); }
const tArray<double>& GetCellResources(int cell_id) const { return resource_count.GetCellResources(cell_id); }
const tArray<double>& GetDemeResources(int deme_id) { return GetDeme(deme_id).GetDemeResourceCount().GetResources(); }
+ const tArray<double>& GetDemeCellResources(int deme_id, int cell_id) { return GetDeme(deme_id).GetDemeResourceCount().GetCellResources( GetDeme(deme_id).GetRelativeCellID(cell_id) ); }
cBirthChamber& GetBirthChamber(int id) { (void) id; return birth_chamber; }
void UpdateResources(const tArray<double>& res_change);
Modified: branches/energy/source/main/cPopulationInterface.cc
===================================================================
--- branches/energy/source/main/cPopulationInterface.cc 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/main/cPopulationInterface.cc 2008-02-21 14:36:30 UTC (rev 2351)
@@ -112,7 +112,7 @@
const tArray<double> & cPopulationInterface::GetDemeResources(int deme_id)
{
- return m_world->GetPopulation().GetDemeResources(deme_id);
+ return m_world->GetPopulation().GetDemeCellResources(deme_id, m_cell_id);
}
void cPopulationInterface::UpdateResources(const tArray<double> & res_change)
Modified: branches/energy/source/main/cPopulationInterface.h
===================================================================
--- branches/energy/source/main/cPopulationInterface.h 2008-02-20 01:17:14 UTC (rev 2350)
+++ branches/energy/source/main/cPopulationInterface.h 2008-02-21 14:36:30 UTC (rev 2351)
@@ -61,7 +61,7 @@
int GetCellID() { return m_cell_id; }
int GetBirthCellID() { return m_birth_cell_id; }
int GetPrevTaskCellID() { return m_prev_task_cell; }
- int GetNumTaskCellsReached() { return m_num_task_cells; }
+ //int GetNumTaskCellsReached() { return m_num_task_cells; }
void AddReachedTaskCell() { m_num_task_cells++; }
int GetDemeID() const { return m_deme_id; }
void SetCellID(int in_id) { m_cell_id = in_id; }
More information about the Avida-cvs
mailing list