[Avida-SVN] r2137 - branches/energy/source/main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Thu Oct 11 12:15:00 PDT 2007
Author: beckma24
Date: 2007-10-11 15:14:59 -0400 (Thu, 11 Oct 2007)
New Revision: 2137
Modified:
branches/energy/source/main/cPopulation.cc
Log:
Fixed problem with ReplicateDeme's 'fill deme with identical replicates and orient' case. Problem was caused by the GridNeighbor function which does not work correctly for all cells unless a torus is used. We need a topology manager! Any takers?
Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc 2007-10-11 16:24:25 UTC (rev 2136)
+++ branches/energy/source/main/cPopulation.cc 2007-10-11 19:14:59 UTC (rev 2137)
@@ -1178,28 +1178,56 @@
// 4 = deme is filled with identical oriented copies of organism
if(m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get() == 3 ||
m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get() == 4) {
+
// fill demes
+ int source_offset = source_deme.GetCellID(0);
for(int i = 0; i < source_deme.GetSize(); i++) { // source deme
- InjectGenome(i, source_germline.GetLatest(), 0);
+ int source_deme_inject_cell = source_deme.GetCellID(i);
+ InjectGenome(source_deme_inject_cell, source_germline.GetLatest(), 0);
+ if(m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get() == 4) {
+ int newFacing;
+ std::pair<int, int> pos = source_deme.GetRelativeCellPosition(source_deme_inject_cell);
+ if(pos.first != 0 && pos.second != 0) { // NW
+ // Rotate all cells to face northwest if possible
+ newFacing = GridNeighbor(source_deme_inject_cell-source_offset,source_deme.GetWidth(),
+ source_deme.GetHeight(), -1, -1) + source_offset;
+ } else if(pos.first == 0 && pos.second != 0) { // North
+ newFacing = GridNeighbor(source_deme_inject_cell-source_offset,source_deme.GetWidth(),
+ source_deme.GetHeight(), 0, -1) + source_offset;
+ } else if(pos.first != 0 && pos.second == 0) { // West
+ newFacing = GridNeighbor(source_deme_inject_cell-source_offset,source_deme.GetWidth(),
+ source_deme.GetHeight(), -1, 0) + source_offset;
+ } else if(pos.first == 0 && pos.second == 0) { // South
+ newFacing = GridNeighbor(source_deme_inject_cell-source_offset,source_deme.GetWidth(),
+ source_deme.GetHeight(), 0, 1) + source_offset;
+ }
+ cell_array[source_deme_inject_cell].Rotate(cell_array[newFacing]);
+ }
}
+
+ int target_offset = target_deme.GetCellID(0);
for(int i = 0; i < target_deme.GetSize(); i++) { // target deme
- InjectGenome(i, target_germline.GetLatest(), 0);
- }
-
- if(m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get() == 4) {
- // Rotate all cells to face northwest.
- int offset = source_deme.GetCellID(0);
- for(int i = 0; i < source_deme.GetSize(); i++) {
- cell_array[i].Rotate(cell_array[GridNeighbor(i-offset,
- source_deme.GetWidth(),
- source_deme.GetHeight(), -1, -1)+offset]);
+ int target_deme_inject_cell = target_deme.GetCellID(i);
+ InjectGenome(target_deme_inject_cell, target_germline.GetLatest(), 0);
+ if(m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get() == 4) {
+ int newFacing;
+ std::pair<int, int> pos = target_deme.GetRelativeCellPosition(target_deme_inject_cell);
+ if(pos.first != 0 && pos.second != 0) { // NW
+ // Rotate all cells to face northwest if possible
+ newFacing = GridNeighbor(target_deme_inject_cell-target_offset,target_deme.GetWidth(),
+ target_deme.GetHeight(), -1, -1) + target_offset;
+ } else if(pos.first == 0 && pos.second != 0) { // North
+ newFacing = GridNeighbor(target_deme_inject_cell-target_offset,target_deme.GetWidth(),
+ target_deme.GetHeight(), 0, -1) + target_offset;
+ } else if(pos.first != 0 && pos.second == 0) { // West
+ newFacing = GridNeighbor(target_deme_inject_cell-target_offset,target_deme.GetWidth(),
+ target_deme.GetHeight(), -1, 0) + target_offset;
+ } else if(pos.first == 0 && pos.second == 0) { // South
+ newFacing = GridNeighbor(target_deme_inject_cell-target_offset,target_deme.GetWidth(),
+ target_deme.GetHeight(), 0, 1) + target_offset;
+ }
+ cell_array[target_deme_inject_cell].Rotate(cell_array[newFacing]);
}
- offset = target_deme.GetCellID(0);
- for(int i = 0; i < target_deme.GetSize(); i++) {
- cell_array[i].Rotate(cell_array[GridNeighbor(i-offset,
- target_deme.GetWidth(),
- target_deme.GetHeight(), -1, -1)+offset]);
- }
}
} else { // 1 organism
int source_deme_inject_cell;
More information about the Avida-cvs
mailing list