[Avida-SVN] r2185 - in branches/energy/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Wed Nov 7 13:28:02 PST 2007
Author: beckma24
Date: 2007-11-07 16:28:02 -0500 (Wed, 07 Nov 2007)
New Revision: 2185
Modified:
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/cOrgMovementPredicate.h
branches/energy/source/main/cPopulation.cc
Log:
Removed redundent GetCellPosition, linked cDemeCellEvent instances with corresponding cDeme, and added deme_id to cDeme
Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc 2007-11-07 20:26:11 UTC (rev 2184)
+++ branches/energy/source/cpu/cHardwareCPU.cc 2007-11-07 21:28:02 UTC (rev 2185)
@@ -4356,7 +4356,7 @@
bool cHardwareCPU::Inst_GetCellPosition(cAvidaContext& ctx) {
int absolute_cell_ID = organism->GetCellID();
int deme_id = organism->GetOrgInterface().GetDemeID();
- std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
+ std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetRelativeCellPosition(absolute_cell_ID);
const int xreg = FindModifiedRegister(REG_BX);
const int yreg = FindNextRegister(xreg);
GetRegister(xreg) = pos.first;
@@ -4368,7 +4368,7 @@
bool cHardwareCPU::Inst_GetCellX(cAvidaContext& ctx) {
int absolute_cell_ID = organism->GetCellID();
int deme_id = organism->GetOrgInterface().GetDemeID();
- std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
+ std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetRelativeCellPosition(absolute_cell_ID);
const int xreg = FindModifiedRegister(REG_BX);
GetRegister(xreg) = pos.first;
return true;
@@ -4378,7 +4378,7 @@
bool cHardwareCPU::Inst_GetCellY(cAvidaContext& ctx) {
int absolute_cell_ID = organism->GetCellID();
int deme_id = organism->GetOrgInterface().GetDemeID();
- std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
+ std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetRelativeCellPosition(absolute_cell_ID);
const int yreg = FindModifiedRegister(REG_BX);
GetRegister(yreg) = pos.second;
return true;
@@ -4387,7 +4387,7 @@
bool cHardwareCPU::Inst_GetDistanceFromDiagonal(cAvidaContext& ctx) {
int absolute_cell_ID = organism->GetOrgInterface().GetCellID();
int deme_id = organism->GetOrgInterface().GetDemeID();
- std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
+ std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetRelativeCellPosition(absolute_cell_ID);
const int reg = FindModifiedRegister(REG_BX);
if(pos.first > pos.second) {
Modified: branches/energy/source/main/cDeme.cc
===================================================================
--- branches/energy/source/main/cDeme.cc 2007-11-07 20:26:11 UTC (rev 2184)
+++ branches/energy/source/main/cDeme.cc 2007-11-07 21:28:02 UTC (rev 2185)
@@ -39,12 +39,13 @@
}
}
-void cDeme::Setup(const tArray<int> & in_cells, int in_width, cWorld* world)
+void cDeme::Setup(const tArray<int> & in_cells, int in_width, cWorld* world, int ID)
{
cell_ids = in_cells;
birth_count = 0;
org_count = 0;
m_world = world;
+ deme_id = ID;
// If width is negative, set it to the full number of cells.
width = in_width;
@@ -64,13 +65,13 @@
/*! Note that for this method to work, we blatantly assume that IDs are in
monotonically increasing order!! */
-std::pair<int, int> cDeme::GetCellPosition(int cellid) const
+/*std::pair<int, int> cDeme::GetCellPosition(int cellid) const
{
assert(cell_ids.GetSize()>0);
assert(GetWidth() > 0);
cellid -= cell_ids[0];
return std::make_pair(cellid % GetWidth(), cellid / GetWidth());
-}
+}*/
std::pair<int, int> cDeme::GetRelativeCellPosition(int cellid) const
{
@@ -216,12 +217,12 @@
}
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);
+ cDemeCellEvent demeEvent = cDemeCellEvent(x1, y1, x2, y2, delay, duration, width, GetHeight(), static_pos, time_to_live, this);
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);
+ cDemeCellEvent demeEvent = cDemeCellEvent(x1, y1, x2, y2, delay, duration, width, GetHeight(), static_pos, time_to_live, this);
demeEvent.DecayEventIDFromCenter();
cell_events.Add(demeEvent);
}
Modified: branches/energy/source/main/cDeme.h
===================================================================
--- branches/energy/source/main/cDeme.h 2007-11-07 20:26:11 UTC (rev 2184)
+++ branches/energy/source/main/cDeme.h 2007-11-07 21:28:02 UTC (rev 2185)
@@ -52,6 +52,7 @@
int birth_count; //!< Number of organisms that have been born into this deme since reset.
int org_count; //!< Number of organisms are currently in this deme.
int _age; //!< Age of this deme, in updates.
+ int deme_id;
cGermline _germline; //!< The germline for this deme, if used.
@@ -71,13 +72,14 @@
cDeme() : width(0), birth_count(0), org_count(0), _age(0), deme_resource_count(0) { ; }
~cDeme();
- void Setup(const tArray<int>& in_cells, int in_width = -1, cWorld* world = NULL);
+ void Setup(const tArray<int>& in_cells, int in_width = -1, cWorld* world = NULL, int ID = 0);
int GetSize() const { return cell_ids.GetSize(); }
int GetCellID(int pos) const { return cell_ids[pos]; }
int GetCellID(int x, int y) const;
+ int GetDemeID() const { return deme_id; }
//! Returns an (x,y) pair for the position of the passed-in cell ID.
- std::pair<int, int> GetCellPosition(int cellid) const;
+// std::pair<int, int> GetCellPosition(int cellid) const;
//! Returns a relative (x,y) pair within the deme for the position of the passed-in cell ID.
std::pair<int, int> GetRelativeCellPosition(int cellid) const;
Modified: branches/energy/source/main/cDemeCellEvent.cc
===================================================================
--- branches/energy/source/main/cDemeCellEvent.cc 2007-11-07 20:26:11 UTC (rev 2184)
+++ branches/energy/source/main/cDemeCellEvent.cc 2007-11-07 21:28:02 UTC (rev 2185)
@@ -1,7 +1,8 @@
#include "cDemeCellEvent.h"
+#include "cDeme.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, int time_to_live) :
+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, cDeme* deme) :
m_delay(delay)
, m_duration(duration)
, m_iter(0)
@@ -12,6 +13,7 @@
, m_active(false)
, m_static_pos(static_pos)
, m_dead (false)
+, m_deme(deme)
{
assert(x1 <= x2);
assert(y1 <= y2);
Modified: branches/energy/source/main/cDemeCellEvent.h
===================================================================
--- branches/energy/source/main/cDemeCellEvent.h 2007-11-07 20:26:11 UTC (rev 2184)
+++ branches/energy/source/main/cDemeCellEvent.h 2007-11-07 21:28:02 UTC (rev 2185)
@@ -4,6 +4,7 @@
#include <utility>
#include "tArray.h"
+class cDeme;
class cWorld;
class cDemeCellEvent {
@@ -14,14 +15,16 @@
int m_event_width, m_event_height, m_time_to_live;
bool m_use_gradient, m_active, m_static_pos, m_dead;
std::pair<std::pair<int, int>, std::pair<int, int> > center;
+ cDeme* m_deme;
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);
+ cDemeCellEvent() { cDemeCellEvent(-1, -1, -1, -1, 0, 0, 0, 0, true, 0, NULL); }
+ 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, cDeme* deme);
int GetNextEventCellID();
int GetDelay();
+ cDeme* GetDeme() const { return m_deme; }
int GetDuration();
int GetEventID();
int GetEventIDDecay(std::pair<int, int> pos);
Modified: branches/energy/source/main/cOrgMessagePredicate.h
===================================================================
--- branches/energy/source/main/cOrgMessagePredicate.h 2007-11-07 20:26:11 UTC (rev 2184)
+++ branches/energy/source/main/cOrgMessagePredicate.h 2007-11-07 21:28:02 UTC (rev 2185)
@@ -163,7 +163,9 @@
~cOrgMessagePred_EventReceivedCenter() { }
virtual bool operator()(const cOrgMessage& msg) {
- if(m_event->IsDead()) {
+ int deme_id = msg.GetSender()->GetOrgInterface().GetDemeID();
+
+ if(deme_id != m_event->GetDeme()->GetDemeID() || m_event->IsDead()) {
return false;
}
@@ -247,7 +249,9 @@
~cOrgMessagePred_EventReceivedLeftSide() { }
virtual bool operator()(const cOrgMessage& msg) {
- if(m_event->IsDead()) {
+ int deme_id = msg.GetSender()->GetOrgInterface().GetDemeID();
+
+ if(deme_id != m_event->GetDeme()->GetDemeID() || m_event->IsDead()) {
return false;
}
@@ -260,7 +264,7 @@
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);
+ std::pair<int, int> pos = pop.GetDeme(deme_id).GetRelativeCellPosition(absolute_cell_ID);
// does receiver have x cordinate of zero
if(pos.first == 0) {
Modified: branches/energy/source/main/cOrgMovementPredicate.h
===================================================================
--- branches/energy/source/main/cOrgMovementPredicate.h 2007-11-07 20:26:11 UTC (rev 2184)
+++ branches/energy/source/main/cOrgMovementPredicate.h 2007-11-07 21:28:02 UTC (rev 2185)
@@ -72,15 +72,16 @@
~cOrgMovementPred_EventMovedIntoCenter() { }
virtual bool operator()(const cOrganism& org) {
- if(m_event->IsDead()) {
+ 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();
- int deme_id = org.GetOrgInterface().GetDemeID();
- std::pair<int, int> pos = pop.GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
+ std::pair<int, int> pos = pop.GetDeme(deme_id).GetRelativeCellPosition(absolute_cell_ID);
// does receiver have x cordinate of zero
if(m_event->InCenter(pos)) {
@@ -115,14 +116,14 @@
}
virtual void UpdateStats(cStats& stats) {
-/* if(m_event_received && !m_stats_updated) {
- int eventCell = m_event->GetNextEventCellID();
+ 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; }
Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc 2007-11-07 20:26:11 UTC (rev 2184)
+++ branches/energy/source/main/cPopulation.cc 2007-11-07 21:28:02 UTC (rev 2185)
@@ -152,7 +152,7 @@
deme_cells[offset] = cell_id;
cell_array[cell_id].SetDemeID(deme_id);
}
- deme_array[deme_id].Setup(deme_cells, deme_size_x, m_world);
+ deme_array[deme_id].Setup(deme_cells, deme_size_x, m_world, deme_id);
}
// Setup the topology.
More information about the Avida-cvs
mailing list