[Avida-SVN] r1766 - in development: Avida.xcodeproj source/main source/targets/viewer-fltk source/targets/viewer-text source/tools
ofria at myxo.css.msu.edu
ofria at myxo.css.msu.edu
Mon Jul 9 11:24:41 PDT 2007
Author: ofria
Date: 2007-07-09 14:24:41 -0400 (Mon, 09 Jul 2007)
New Revision: 1766
Modified:
development/Avida.xcodeproj/project.pbxproj
development/source/main/cPopulation.cc
development/source/main/cPopulation.h
development/source/targets/viewer-fltk/viewer-fltk.cc
development/source/targets/viewer-text/viewer-text.cc
development/source/tools/cTopology.h
Log:
Fixed some problems in topology that threw off runs with a non-square grid.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2007-07-09 18:03:31 UTC (rev 1765)
+++ development/Avida.xcodeproj/project.pbxproj 2007-07-09 18:24:41 UTC (rev 1766)
@@ -780,7 +780,7 @@
70DCAC77097AF730002F8733 /* key_chart */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = key_chart; sourceTree = "<group>"; };
70DCAC78097AF730002F8733 /* viewer.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = viewer.cc; sourceTree = "<group>"; };
70DCAC9B097AF7C0002F8733 /* primitive.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = primitive.cc; sourceTree = "<group>"; };
- 70DCAD1C097AF7CC002F8733 /* avida-s */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = "avida-s"; sourceTree = BUILT_PRODUCTS_DIR; };
+ 70DCAD1C097AF7CC002F8733 /* avida-s */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "avida-s"; sourceTree = BUILT_PRODUCTS_DIR; };
70DCAD1F097AF81A002F8733 /* AvidaScript.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AvidaScript.h; sourceTree = "<group>"; };
70DCAD20097AF81A002F8733 /* cLexer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cLexer.h; sourceTree = "<group>"; };
70DCAD21097AF81A002F8733 /* cLexer.l */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.lex; path = cLexer.l; sourceTree = "<group>"; };
@@ -825,7 +825,7 @@
DCC315CE076253A5008F7A48 /* environment.rotate */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = environment.rotate; sourceTree = "<group>"; };
DCC315D0076253A5008F7A48 /* task_event_gen.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.cc; sourceTree = "<group>"; };
DCC315D1076253A5008F7A48 /* task_event_gen.old.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.old.cc; sourceTree = "<group>"; };
- DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
+ DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2007-07-09 18:03:31 UTC (rev 1765)
+++ development/source/main/cPopulation.cc 2007-07-09 18:24:41 UTC (rev 1766)
@@ -81,12 +81,13 @@
// Avida specific information.
world_x = world->GetConfig().WORLD_X.Get();
world_y = world->GetConfig().WORLD_Y.Get();
- int num_demes = m_world->GetConfig().NUM_DEMES.Get();
- const int num_cells = world_x * world_y;
+ int num_demes = m_world->GetConfig().NUM_DEMES.Get();
+ const int num_cells = world_x * world_y;
const int geometry = world->GetConfig().WORLD_GEOMETRY.Get();
- if(m_world->GetConfig().ENERGY_CAP.Get() == -1)
+ if(m_world->GetConfig().ENERGY_CAP.Get() == -1) {
m_world->GetConfig().ENERGY_CAP.Set(INT_MAX);
+ }
if(m_world->GetConfig().LOG_SLEEP_TIMES.Get() == 1) {
sleep_log = new tVector<pair<int,int> >[world_x*world_y];
@@ -95,14 +96,13 @@
if (world->GetVerbosity() > VERBOSE_NORMAL) {
cout << "Building world " << world_x << "x" << world_y << " = " << num_cells << " organisms." << endl;
switch(geometry) {
- case nGeometry::GRID: { cout << "Geometry: Bounded grid" << endl; break; }
- case nGeometry::TORUS: { cout << "Geometry: Torus" << endl; break; }
- case nGeometry::CLIQUE: { cout << "Geometry: Clique" << endl; break; }
- case nGeometry::HEX: { cout << "Geometry: Hex" << endl; break; }
- default: {
- cout << "Unknown geometry!" << endl;
- assert(false);
- }
+ case nGeometry::GRID: { cout << "Geometry: Bounded grid" << endl; break; }
+ case nGeometry::TORUS: { cout << "Geometry: Torus" << endl; break; }
+ case nGeometry::CLIQUE: { cout << "Geometry: Clique" << endl; break; }
+ case nGeometry::HEX: { cout << "Geometry: Hex" << endl; break; }
+ default:
+ cout << "Unknown geometry!" << endl;
+ assert(false);
}
}
@@ -110,80 +110,69 @@
#ifdef DEBUG
const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
#endif
- if(num_demes > 0) {
- assert(birth_method != POSITION_CHILD_FULL_SOUP_ELDEST);
- assert(birth_method != POSITION_CHILD_FULL_SOUP_ELDEST);
- } else {
- assert(birth_method != POSITION_CHILD_DEME_RANDOM);
- num_demes = 1; // One population == one deme.
- }
-
+ if(num_demes > 0) {
+ assert(birth_method != POSITION_CHILD_FULL_SOUP_ELDEST);
+ } else {
+ assert(birth_method != POSITION_CHILD_DEME_RANDOM);
+ num_demes = 1; // One population == one deme.
+ }
+
// Allocate the cells, resources, and market.
- cell_array.Resize(num_cells);
- resource_count.ResizeSpatialGrids(world_x, world_y);
- market.Resize(MARKET_SIZE);
+ cell_array.Resize(num_cells);
+ resource_count.ResizeSpatialGrids(world_x, world_y);
+ market.Resize(MARKET_SIZE);
// Setup the cells. Do things that are not dependent upon topology here.
- for(int i=0; i<num_cells; ++i) {
- cell_array[i].Setup(world, i, environment.GetMutRates(), i%world_x, i/world_x);
+ for(int i=0; i<num_cells; ++i) {
+ cell_array[i].Setup(world, i, environment.GetMutRates(), i%world_x, i/world_x);
// Setup the reaper queue.
- if (world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST) {
- reaper_queue.Push(&(cell_array[i]));
- }
- }
-
- // What are the sizes of the demes that we're creating?
- const int deme_size_x = world_x;
- const int deme_size_y = world_y / num_demes;
- const int deme_size = deme_size_x * deme_size_y;
- deme_array.Resize(num_demes);
-
+ if (world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST) {
+ reaper_queue.Push(&(cell_array[i]));
+ }
+ }
+
+ // What are the sizes of the demes that we're creating?
+ const int deme_size_x = world_x;
+ const int deme_size_y = world_y / num_demes;
+ const int deme_size = deme_size_x * deme_size_y;
+ deme_array.Resize(num_demes);
+
// Setup the deme structures.
- tArray<int> deme_cells(deme_size);
- for (int deme_id = 0; deme_id < num_demes; deme_id++) {
- for (int offset = 0; offset < deme_size; offset++) {
- int cell_id = deme_id * deme_size + offset;
- deme_cells[offset] = cell_id;
- cell_array[cell_id].SetDemeID(deme_id);
- }
- deme_array[deme_id].Setup(deme_cells, deme_size_x);
- }
+ tArray<int> deme_cells(deme_size);
+ for (int deme_id = 0; deme_id < num_demes; deme_id++) {
+ for (int offset = 0; offset < deme_size; offset++) {
+ int cell_id = deme_id * deme_size + offset;
+ deme_cells[offset] = cell_id;
+ cell_array[cell_id].SetDemeID(deme_id);
+ }
+ deme_array[deme_id].Setup(deme_cells, deme_size_x);
+ }
// Setup the topology.
// What we're doing here is chopping the cell_array up into num_demes pieces.
// Note that having 0 demes (one population) is the same as having 1 deme. Then
// we send the cells that comprise each deme into the topology builder.
- for(int i=0; i<num_cells; i+=deme_size) {
- switch(geometry) {
- // We're cheating here; we're using the random access nature of an iterator
- // to index beyond the end of the cell_array.
- case nGeometry::GRID: {
- build_grid(&cell_array.begin()[i], &cell_array.begin()[i+deme_size],
- deme_size_x, deme_size_y);
- break;
- }
- case nGeometry::TORUS: {
- build_torus(&cell_array.begin()[i], &cell_array.begin()[i+deme_size],
- deme_size_x, deme_size_y);
- break;
- }
- case nGeometry::CLIQUE: {
- build_clique(&cell_array.begin()[i], &cell_array.begin()[i+deme_size],
- deme_size_x, deme_size_y);
- break;
- }
- case nGeometry::HEX: {
- build_hex(&cell_array.begin()[i], &cell_array.begin()[i+deme_size],
- deme_size_x, deme_size_y);
- break;
- }
- default: {
- assert(false);
- }
- }
- }
-
-
+ for(int i=0; i<num_cells; i+=deme_size) {
+ // We're cheating here; we're using the random access nature of an iterator
+ // to index beyond the end of the cell_array.
+ switch(geometry) {
+ case nGeometry::GRID:
+ build_grid(&cell_array.begin()[i], &cell_array.begin()[i+deme_size], deme_size_x, deme_size_y);
+ break;
+ case nGeometry::TORUS:
+ build_torus(&cell_array.begin()[i], &cell_array.begin()[i+deme_size], deme_size_x, deme_size_y);
+ break;
+ case nGeometry::CLIQUE:
+ build_clique(&cell_array.begin()[i], &cell_array.begin()[i+deme_size], deme_size_x, deme_size_y);
+ break;
+ case nGeometry::HEX:
+ build_hex(&cell_array.begin()[i], &cell_array.begin()[i+deme_size], deme_size_x, deme_size_y);
+ break;
+ default:
+ assert(false);
+ }
+ }
+
BuildTimeSlicer(0);
// Setup the resources...
Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h 2007-07-09 18:03:31 UTC (rev 1765)
+++ development/source/main/cPopulation.h 2007-07-09 18:24:41 UTC (rev 1766)
@@ -138,7 +138,7 @@
void InjectClone(int cell_id, cOrganism& orig_org);
void LineageSetupOrganism(cOrganism* organism, cLineage* lineage, int lin_label, cGenotype* parent_genotype = NULL);
- void CCladeSetupOrganism(cOrganism* organism);
+ void CCladeSetupOrganism(cOrganism* organism);
// Must be called to activate *any* organism in the population.
void ActivateOrganism(cAvidaContext& ctx, cOrganism* in_organism, cPopulationCell& target_cell);
Modified: development/source/targets/viewer-fltk/viewer-fltk.cc
===================================================================
--- development/source/targets/viewer-fltk/viewer-fltk.cc 2007-07-09 18:03:31 UTC (rev 1765)
+++ development/source/targets/viewer-fltk/viewer-fltk.cc 2007-07-09 18:24:41 UTC (rev 1766)
@@ -1,8 +1,8 @@
/*
- * viewer.cc
+ * viewer-fltk.cc
* Avida
*
- * Created by Charles on 7/1/07
+ * Created by Charles on 7/8/07
* Copyright 1999-2007 Michigan State University. All rights reserved.
*
*
@@ -49,13 +49,8 @@
// Test to see if we should be in analyze mode only...
if (world->GetConfig().ANALYZE_MODE.Get() > 0); // @CAO Do something here...
- cout << "We Made IT! Now we stop." << endl;
-
- driver = new cDriver_TextViewer(world);
-
- cout << "And a bit more for the console to swallow..." << endl;
-
-
+ // Turn control over to the driver!
+ driver = new cDriver_FLTKViewer(world);
driver->Run();
// Exit Nicely
Modified: development/source/targets/viewer-text/viewer-text.cc
===================================================================
--- development/source/targets/viewer-text/viewer-text.cc 2007-07-09 18:03:31 UTC (rev 1765)
+++ development/source/targets/viewer-text/viewer-text.cc 2007-07-09 18:24:41 UTC (rev 1766)
@@ -1,5 +1,5 @@
/*
- * viewer.cc
+ * viewer-text.cc
* Avida
*
* Created by Charles on 7/1/07
@@ -49,13 +49,8 @@
// Test to see if we should be in analyze mode only...
if (world->GetConfig().ANALYZE_MODE.Get() > 0); // @CAO Do something here...
- cout << "We Made IT! Now we stop." << endl;
-
+ // And run the driver!
driver = new cDriver_TextViewer(world);
-
- cout << "And a bit more for the console to swallow..." << endl;
-
-
driver->Run();
// Exit Nicely
Modified: development/source/tools/cTopology.h
===================================================================
--- development/source/tools/cTopology.h 2007-07-09 18:03:31 UTC (rev 1765)
+++ development/source/tools/cTopology.h 2007-07-09 18:24:41 UTC (rev 1766)
@@ -17,21 +17,21 @@
and connections DO wrap around the logical edges of the torus.
*/
template< typename InputIterator >
-void build_torus(InputIterator begin, InputIterator end, unsigned int rowSize, unsigned int colSize) {
+void build_torus(InputIterator begin, InputIterator end, unsigned int x_size, unsigned int y_size) {
// Get the offset from the start of this range. This is used to modify the
// parameters and return for GridNeighbor.
int offset = begin->GetID();
for(InputIterator i=begin; i!=end; ++i) {
// The majority of all connections.
- i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, -1, -1)]);
- i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 0, -1)]);
- i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 1, -1)]);
- i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 1, 0)]);
- i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 1, 1)]);
- i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 0, 1)]);
- i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, -1, 1)]);
- i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, -1, 0)]);
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, -1, -1)]);
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 0, -1)]);
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 1, -1)]);
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 1, 0)]);
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 1, 1)]);
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 0, 1)]);
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, -1, 1)]);
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, -1, 0)]);
}
}
@@ -41,36 +41,36 @@
and connections do NOT wrap around the logical edges of the grid.
*/
template< typename InputIterator >
-void build_grid(InputIterator begin, InputIterator end, unsigned int rowSize, unsigned int colSize) {
+void build_grid(InputIterator begin, InputIterator end, unsigned int x_size, unsigned int y_size) {
// Start with a torus.
- build_torus(begin, end, rowSize, colSize);
+ build_torus(begin, end, x_size, y_size);
int offset = begin->GetID();
// And now remove the connections that wrap around.
for(InputIterator i=begin; i!=end; ++i) {
int id = i->GetID();
- unsigned int x = (id-offset) % colSize;
- unsigned int y = (id-offset) / colSize;
+ unsigned int x = (id-offset) % y_size;
+ unsigned int y = (id-offset) / y_size;
if(x==0) {
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, -1, -1)]);
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, -1, 0)]);
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, -1, 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)]);
}
- if(x==(colSize-1)) {
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 1, -1)]);
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 1, 0)]);
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 1, 1)]);
+ if(x==(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, 1, 0)]);
+ i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 1, 1)]);
}
if(y==0) {
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, -1, -1)]);
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 0, -1)]);
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 1, -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)]);
}
- if(y==(rowSize-1)) {
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, -1, 1)]);
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 0, 1)]);
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 1, 1)]);
+ if(y==(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, 0, 1)]);
+ i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, x_size, y_size, 1, 1)]);
}
}
}
@@ -80,7 +80,7 @@
In a clique, each cell is connected to all other cells in the given range.
*/
template< typename InputIterator >
-void build_clique(InputIterator begin, InputIterator end, unsigned int rowSize, unsigned int colSize) {
+void build_clique(InputIterator begin, InputIterator end, unsigned int x_size, unsigned int y_size) {
for(InputIterator i=begin; i!=end; ++i) {
for(InputIterator j=begin; j!=end; ++j) {
if(j!=i) {
@@ -96,14 +96,14 @@
edges.
*/
template< typename InputIterator >
-void build_hex(InputIterator begin, InputIterator end, unsigned int rowSize, unsigned int colSize) {
+void build_hex(InputIterator begin, InputIterator end, unsigned int x_size, unsigned int y_size) {
// Start with a grid:
- build_grid(begin, end, rowSize, colSize);
+ build_grid(begin, end, x_size, y_size);
int offset = begin->GetID();
// ... and remove connections to the NE,SW:
for(InputIterator i=begin; i!=end; ++i) {
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, 1, -1)]);
- i->ConnectionList().Remove(&begin[GridNeighbor(i->GetID()-offset, colSize, rowSize, -1, 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, 1)]);
}
}
More information about the Avida-cvs
mailing list