[Avida-SVN] r3219 - branches/bdc-coop/source/actions
connel42 at myxo.css.msu.edu
connel42 at myxo.css.msu.edu
Fri Apr 24 11:33:51 PDT 2009
Author: connel42
Date: 2009-04-24 14:33:51 -0400 (Fri, 24 Apr 2009)
New Revision: 3219
Modified:
branches/bdc-coop/source/actions/PopulationActions.cc
Log:
Updated how neighbor cell set is calculated in the kill within radius action
Modified: branches/bdc-coop/source/actions/PopulationActions.cc
===================================================================
--- branches/bdc-coop/source/actions/PopulationActions.cc 2009-04-24 04:04:03 UTC (rev 3218)
+++ branches/bdc-coop/source/actions/PopulationActions.cc 2009-04-24 18:33:51 UTC (rev 3219)
@@ -2744,7 +2744,10 @@
{
double level;
int target_cell;
-
+ int current_cell;
+ const int geometry = m_world->GetConfig().WORLD_GEOMETRY.Get();
+
+ assert(geometry == 1);
assert(m_numzones >= 0);
assert(m_radius >= 0);
@@ -2753,28 +2756,54 @@
for(int i=0; i < m_numzones; i++) {
target_cell = m_world->GetRandom().GetInt(0, m_world->GetPopulation().GetSize()-1);
+
+ const int world_x = m_world->GetPopulation().GetWorldX();
+ const int world_y = m_world->GetPopulation().GetWorldY();
+ const int target_row = floor(target_cell/world_x);
+ const int target_col = target_cell % world_x;
+
+ const int start_row = max(0, target_row - m_radius);
+ const int end_row = min(world_y - 1, target_row + m_radius);
+ const int start_col = max(0, target_col - m_radius);
+ const int end_col = min(world_x - 1, target_col + m_radius);
+
+ //cout << "BDCDEBUG: World X=" << world_x << " WORLD_Y=" << world_y << " target cell " << target_cell << " is in row " << target_row << " and column " << target_col << endl;
+ //cout << "BDCDEBUG: Cells within " << m_radius << " of target cell " << target_cell << " span rows " << start_row << " through " << end_row << " and columns " << start_col << " through " << end_col << endl;
+
+ for (int r = start_row; r <= end_row; r++) {
+ for (int c = start_col; c <= end_col; c++) {
+ current_cell = (r * world_x) + c;
+
+ level = m_world->GetPopulation().GetResourceCount().GetSpatialResource(res_id).GetAmount(current_cell);
+
+ if(level < m_threshold) {
+ m_world->GetPopulation().KillOrganism(m_world->GetPopulation().GetCell(current_cell));
+ m_world->GetStats().IncNumOrgsKilled();
+ }
+
+ }
+ }
+
+
+ /*
+ NOTE: this code is cleaner and more flexible wrt geometries, but the acquired neighboring cells list didn't seem to be right
cPopulationCell& cell = m_world->GetPopulation().GetCell(target_cell);
std::set<cPopulationCell*> cell_set;
cell.GetNeighboringCells(cell_set, m_radius);
- //cout << "BDCDEBUG: num kill zones is " << m_numzones << endl;
- //cout << "BDCDEBUG: kill center is at " << target_cell << endl;
- //cout << "BDCDEBUG: radius is " << m_radius << endl;
- //cout << "BDCDEBUG: size of neighboring cell set is " << cell_set.size() << endl;
-
for(std::set<cPopulationCell*>::iterator i=cell_set.begin(); i!=cell_set.end(); ++i) {
level = m_world->GetPopulation().GetResourceCount().GetSpatialResource(res_id).GetAmount((*i)->GetID());
if(level < m_threshold) {
- //cout << "BDCDEBUG: organism at cell " << (*i)->GetID() << " has a resource level of " << level << " (below threshold of " << m_threshold << ") and will be killed" << endl;
m_world->GetPopulation().KillOrganism(m_world->GetPopulation().GetCell(target_cell));
m_world->GetStats().IncNumOrgsKilled();
}
- //else { cout << "BDCDEBUG: organism at cell " << (*i)->GetID() << " has a resource level of " << level << " (above threshold of " << m_threshold << ") and will NOT be killed" << endl; }
-
} //End iterating through list of neighbor cells
+ */
+
+
} //End iterating through kill zones
} //End Process()
@@ -2815,7 +2844,10 @@
{
double level;
int target_cell;
+ int current_cell;
+ const int geometry = m_world->GetConfig().WORLD_GEOMETRY.Get();
+ assert(geometry == 1);
assert(m_numzones >= 0);
assert(m_radius >= 0);
@@ -2825,21 +2857,52 @@
for(int i=0; i < m_numzones; i++) {
target_cell = m_world->GetRandom().GetInt(0, m_world->GetPopulation().GetSize()-1);
- cPopulationCell& cell = m_world->GetPopulation().GetCell(target_cell);
- std::set<cPopulationCell*> cell_set;
- cell.GetNeighboringCells(cell_set, m_radius);
+ const int world_x = m_world->GetPopulation().GetWorldX();
+ const int world_y = m_world->GetPopulation().GetWorldY();
+ const int target_row = floor(target_cell/world_x);
+ const int target_col = target_cell % world_x;
- for(std::set<cPopulationCell*>::iterator i=cell_set.begin(); i!=cell_set.end(); ++i) {
- level = m_world->GetPopulation().GetResourceCount().GetSpatialResource(res_id).GetAmount((*i)->GetID());
-
- if(level > m_threshold) {
- m_world->GetPopulation().KillOrganism(m_world->GetPopulation().GetCell(target_cell));
- m_world->GetStats().IncNumOrgsKilled();
+ const int start_row = max(0, target_row - m_radius);
+ const int end_row = min(world_y - 1, target_row + m_radius);
+ const int start_col = max(0, target_col - m_radius);
+ const int end_col = min(world_x - 1, target_col + m_radius);
+
+ //cout << "BDCDEBUG: World X=" << world_x << " WORLD_Y=" << world_y << " target cell " << target_cell << " is in row " << target_row << " and column " << target_col << endl;
+ //cout << "BDCDEBUG: Cells within " << m_radius << " of target cell " << target_cell << " span rows " << start_row << " through " << end_row << " and columns " << start_col << " through " << end_col << endl;
+
+ for (int r = start_row; r <= end_row; r++) {
+ for (int c = start_col; c <= end_col; c++) {
+ current_cell = (r * world_x) + c;
+
+ level = m_world->GetPopulation().GetResourceCount().GetSpatialResource(res_id).GetAmount(current_cell);
+
+ if(level > m_threshold) {
+ m_world->GetPopulation().KillOrganism(m_world->GetPopulation().GetCell(current_cell));
+ m_world->GetStats().IncNumOrgsKilled();
+ }
+
}
-
- } //End iterating through list of neighbor cells
+ }
+
+ /*
+ NOTE: this code is cleaner and more flexible wrt geometries, but the acquired neighboring cells list didn't seem to be right
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(target_cell);
+
+ std::set<cPopulationCell*> cell_set;
+ cell.GetNeighboringCells(cell_set, m_radius);
+
+ for(std::set<cPopulationCell*>::iterator i=cell_set.begin(); i!=cell_set.end(); ++i) {
+ level = m_world->GetPopulation().GetResourceCount().GetSpatialResource(res_id).GetAmount((*i)->GetID());
+
+ if(level > m_threshold) {
+ m_world->GetPopulation().KillOrganism(m_world->GetPopulation().GetCell(target_cell));
+ m_world->GetStats().IncNumOrgsKilled();
+ }
+ } //End iterating through list of neighbor cells
+ */
+
} //End iterating through kill zones
} //End Process()
More information about the Avida-cvs
mailing list