[Avida-SVN] r2150 - in development/source: actions tools
covertar at myxo.css.msu.edu
covertar at myxo.css.msu.edu
Tue Oct 23 09:52:30 PDT 2007
Author: covertar
Date: 2007-10-23 12:52:30 -0400 (Tue, 23 Oct 2007)
New Revision: 2150
Modified:
development/source/actions/PopulationActions.cc
development/source/tools/cTopology.h
Log:
Fixes to non-square bounded grid in cTopology:
--boundry conditions were transposed
--x and y cords were caclculated using y as the width, should be x
Fixes to Join/Sever commands:
--SeverGridRow had incorrect calculation for cords of cells to be severed -- only incorrect for non-square girds
--JoinGridRow/Column no longer joins boundry of a bounded grid
Consitancy tests for Join/Sever forth comming
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2007-10-23 14:51:25 UTC (rev 2149)
+++ development/source/actions/PopulationActions.cc 2007-10-23 16:52:30 UTC (rev 2150)
@@ -1182,16 +1182,30 @@
m_world->GetDriver().RaiseException(err);
return;
}
+
// Loop through all of the rows and make the cut on each...
for (int row_id = m_min; row_id < m_max; row_id++) {
+ //col is always the same -- compute which row to make the cut
int idA = row_id * world_x + m_id;
int idB = GridNeighbor(idA, world_x, world_y, -1, 0);
+
int idA0 = GridNeighbor(idA, world_x, world_y, 0, -1);
int idA1 = GridNeighbor(idA, world_x, world_y, 0, 1);
+
int idB0 = GridNeighbor(idA, world_x, world_y, -1, -1);
int idB1 = GridNeighbor(idA, world_x, world_y, -1, 1);
+
cPopulationCell& cellA = m_world->GetPopulation().GetCell(idA);
cPopulationCell& cellB = m_world->GetPopulation().GetCell(idB);
+
+ #ifdef DEBUG
+ int temp_x = 0, temp_y = 0;
+ cellA.GetPosition(temp_x,temp_y);
+ cerr << "cellA: " << temp_x << " " << temp_y << endl;
+ cellB.GetPosition(temp_x,temp_y);
+ cerr << "cellB: " << temp_x << " " << temp_y << endl;
+ #endif
+
tList<cPopulationCell>& cellA_list = cellA.ConnectionList();
tList<cPopulationCell>& cellB_list = cellB.ConnectionList();
cellA_list.Remove(&m_world->GetPopulation().GetCell(idB));
@@ -1208,7 +1222,7 @@
///// sever_grid_row /////
/*
- Remove the connections between cells along a column in an avida grid.
+ Remove the connections between cells along a row in an avida grid.
Arguments:
row_id: indicates the number of rows above the cut.
@@ -1246,16 +1260,29 @@
m_world->GetDriver().RaiseException(err);
return;
}
- // Loop through all of the rows and make the cut on each...
+
+ // Loop through all of the cols and make the cut on each...
for (int col_id = m_min; col_id < m_max; col_id++) {
- int idA = col_id * world_y + m_id;
+ //row is always the same -- only the column changes -- could also do this in the loop
+ int idA = m_id * world_x + col_id;
int idB = GridNeighbor(idA, world_x, world_y, 0, -1);
+
int idA0 = GridNeighbor(idA, world_x, world_y, -1, 0);
int idA1 = GridNeighbor(idA, world_x, world_y, 1, 0);
+
int idB0 = GridNeighbor(idA, world_x, world_y, -1, -1);
int idB1 = GridNeighbor(idA, world_x, world_y, 1, -1);
cPopulationCell& cellA = m_world->GetPopulation().GetCell(idA);
cPopulationCell& cellB = m_world->GetPopulation().GetCell(idB);
+
+ #ifdef DEBUG
+ int temp_x = 0, temp_y = 0;
+ cellA.GetPosition(temp_x,temp_y);
+ cerr << "cellA: " << temp_x << " " << temp_y << endl;
+ cellB.GetPosition(temp_x,temp_y);
+ cerr << "cellB: " << temp_x << " " << temp_y << endl;
+ #endif
+
tList<cPopulationCell>& cellA_list = cellA.ConnectionList();
tList<cPopulationCell>& cellB_list = cellB.ConnectionList();
cellA_list.Remove(&m_world->GetPopulation().GetCell(idB));
@@ -1301,6 +1328,7 @@
{
const int world_x = m_world->GetPopulation().GetWorldX();
const int world_y = m_world->GetPopulation().GetWorldY();
+ const int geometry = m_world->GetConfig().WORLD_GEOMETRY.Get();
if (m_id == -1) m_id = world_x / 2;
if (m_max == -1) m_max = world_y;
if (m_id < 0 || m_id >= world_x) {
@@ -1310,22 +1338,35 @@
}
// Loop through all of the rows and make the cut on each...
for (int row_id = m_min; row_id < m_max; row_id++) {
+ //compute which cells to be joined -- grab them from the population
int idA = row_id * world_x + m_id;
int idB = GridNeighbor(idA, world_x, world_y, -1, 0);
cPopulationCell& cellA = m_world->GetPopulation().GetCell(idA);
cPopulationCell& cellB = m_world->GetPopulation().GetCell(idB);
- cPopulationCell& cellA0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, 0, -1));
- cPopulationCell& cellA1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, 0, 1));
- cPopulationCell& cellB0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, -1));
- cPopulationCell& cellB1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, 1));
+
+ //grab the cell lists
tList<cPopulationCell>& cellA_list = cellA.ConnectionList();
tList<cPopulationCell>& cellB_list = cellB.ConnectionList();
+
+ //these cells are always joined
if (cellA_list.FindPtr(&cellB) == NULL) cellA_list.Push(&cellB);
- if (cellA_list.FindPtr(&cellB0) == NULL) cellA_list.Push(&cellB0);
- if (cellA_list.FindPtr(&cellB1) == NULL) cellA_list.Push(&cellB1);
if (cellB_list.FindPtr(&cellA) == NULL) cellB_list.Push(&cellA);
- if (cellB_list.FindPtr(&cellA0) == NULL) cellB_list.Push(&cellA0);
- if (cellB_list.FindPtr(&cellA1) == NULL) cellB_list.Push(&cellA1);
+
+ //make sure we don't break the bounded grid at the top
+ if((nGeometry::GRID == geometry && row_id != 0) || nGeometry::GRID != geometry){
+ cPopulationCell& cellA0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, 0, -1));
+ cPopulationCell& cellB0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, -1));
+ if (cellA_list.FindPtr(&cellB0) == NULL) cellA_list.Push(&cellB0);
+ if (cellB_list.FindPtr(&cellA0) == NULL) cellB_list.Push(&cellA0);
+ }
+
+ //make sure we don't break the bounded grid at the bottom
+ if((nGeometry::GRID == geometry && row_id != (world_y-1)) || nGeometry::GRID != geometry){
+ cPopulationCell& cellA1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, 0, 1));
+ cPopulationCell& cellB1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, 1));
+ if (cellA_list.FindPtr(&cellB1) == NULL) cellA_list.Push(&cellB1);
+ if (cellB_list.FindPtr(&cellA1) == NULL) cellB_list.Push(&cellA1);
+ }
}
}
};
@@ -1363,6 +1404,7 @@
{
const int world_x = m_world->GetPopulation().GetWorldX();
const int world_y = m_world->GetPopulation().GetWorldY();
+ const int geometry = m_world->GetConfig().WORLD_GEOMETRY.Get();
if (m_id == -1) m_id = world_y / 2;
if (m_max == -1) m_max = world_x;
if (m_id < 0 || m_id >= world_y) {
@@ -1372,22 +1414,35 @@
}
// Loop through all of the rows and make the cut on each...
for (int col_id = m_min; col_id < m_max; col_id++) {
- int idA = col_id * world_y + m_id;
+ //compute which cells are beoing joined and grab them
+ int idA = m_id * world_x + col_id;
int idB = GridNeighbor(idA, world_x, world_y, 0, -1);
cPopulationCell& cellA = m_world->GetPopulation().GetCell(idA);
cPopulationCell& cellB = m_world->GetPopulation().GetCell(idB);
- cPopulationCell& cellA0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, 0));
- cPopulationCell& cellA1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, 1, 0));
- cPopulationCell& cellB0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, -1));
- cPopulationCell& cellB1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, 1, -1));
+
+ //grab the cell lists
tList<cPopulationCell>& cellA_list = cellA.ConnectionList();
tList<cPopulationCell>& cellB_list = cellB.ConnectionList();
+
+ //these cells are always joined
if (cellA_list.FindPtr(&cellB) == NULL) cellA_list.Push(&cellB);
- if (cellA_list.FindPtr(&cellB0) == NULL) cellA_list.Push(&cellB0);
- if (cellA_list.FindPtr(&cellB1) == NULL) cellA_list.Push(&cellB1);
if (cellB_list.FindPtr(&cellA) == NULL) cellB_list.Push(&cellA);
- if (cellB_list.FindPtr(&cellA0) == NULL) cellB_list.Push(&cellA0);
- if (cellB_list.FindPtr(&cellA1) == NULL) cellB_list.Push(&cellA1);
+
+ //make sure we don't break the bounded grid on the left
+ if((nGeometry::GRID == geometry && col_id != 0) || nGeometry::GRID != geometry){
+ cPopulationCell& cellA0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, 0));
+ cPopulationCell& cellB0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, -1));
+ if (cellA_list.FindPtr(&cellB0) == NULL) cellA_list.Push(&cellB0);
+ if (cellB_list.FindPtr(&cellA0) == NULL) cellB_list.Push(&cellA0);
+ }
+
+ //make cure we don't break the bounded grid on the right
+ if((nGeometry::GRID == geometry && col_id != (world_x-1)) || nGeometry::GRID != geometry){
+ cPopulationCell& cellA1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, 1, 0));
+ cPopulationCell& cellB1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, 1, -1));
+ if (cellA_list.FindPtr(&cellB1) == NULL) cellA_list.Push(&cellB1);
+ if (cellB_list.FindPtr(&cellA1) == NULL) cellB_list.Push(&cellA1);
+ }
}
}
};
Modified: development/source/tools/cTopology.h
===================================================================
--- development/source/tools/cTopology.h 2007-10-23 14:51:25 UTC (rev 2149)
+++ development/source/tools/cTopology.h 2007-10-23 16:52:30 UTC (rev 2150)
@@ -49,15 +49,15 @@
// And now remove the connections that wrap around.
for(InputIterator i=begin; i!=end; ++i) {
int id = i->GetID();
- unsigned int x = (id-offset) % y_size;
- unsigned int y = (id-offset) / y_size;
+ unsigned int x = (id-offset) % x_size;
+ unsigned int y = (id-offset) / x_size;
if(x==0) {
i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, -1, -1)]);
i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, -1, 0)]);
i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, -1, 1)]);
}
- if(x==(y_size-1)) {
+ if(x==(x_size-1)) {
i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 1, -1)]);
i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 1, 0)]);
i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 1, 1)]);
@@ -67,7 +67,7 @@
i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 0, -1)]);
i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 1, -1)]);
}
- if(y==(x_size-1)) {
+ if(y==(y_size-1)) {
i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, -1, 1)]);
i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 0, 1)]);
i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 1, 1)]);
More information about the Avida-cvs
mailing list