[Avida-SVN] r2807 - in development/source: main tools
dk at myxo.css.msu.edu
dk at myxo.css.msu.edu
Mon Sep 29 15:26:23 PDT 2008
Author: dk
Date: 2008-09-29 18:26:23 -0400 (Mon, 29 Sep 2008)
New Revision: 2807
Modified:
development/source/main/cAvidaConfig.h
development/source/main/cPopulation.cc
development/source/main/cPopulation.h
development/source/main/nGeometry.h
development/source/tools/cTopology.h
Log:
Early stages of the addition of a 3rd dimension to the Avida world. This commit merely adds the topology, config option, and some of the required changes in cPopulation.
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2008-09-29 16:15:54 UTC (rev 2806)
+++ development/source/main/cAvidaConfig.h 2008-09-29 22:26:23 UTC (rev 2807)
@@ -279,7 +279,8 @@
CONFIG_ADD_GROUP(ARCH_GROUP, "Architecture Variables");
CONFIG_ADD_VAR(WORLD_X, int, 60, "Width of the Avida world");
CONFIG_ADD_VAR(WORLD_Y, int, 60, "Height of the Avida world");
- CONFIG_ADD_VAR(WORLD_GEOMETRY, int, 2, "1 = Bounded Grid\n2 = Torus\n3 = Clique");
+ CONFIG_ADD_VAR(WORLD_Z, int, 1, "Depth of the Avida world");
+ CONFIG_ADD_VAR(WORLD_GEOMETRY, int, 2, "1 = Bounded Grid\n2 = Torus\n3 = Clique\n4 = Hexagonal grid\n5 = Lattice");
CONFIG_ADD_VAR(RANDOM_SEED, int, 0, "Random number seed (0 for based on time)");
CONFIG_ADD_VAR(HARDWARE_TYPE, int, 0, "0 = Original CPUs\n1 = New SMT CPUs\n2 = Transitional SMT\n3 = Experimental CPU\n4 = Gene Expression CPU");
CONFIG_ADD_VAR(SPECULATIVE, bool, 1, "Enable speculative execution");
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2008-09-29 16:15:54 UTC (rev 2806)
+++ development/source/main/cPopulation.cc 2008-09-29 22:26:23 UTC (rev 2807)
@@ -85,8 +85,10 @@
// Avida specific information.
world_x = world->GetConfig().WORLD_X.Get();
world_y = world->GetConfig().WORLD_Y.Get();
+ world_z = world->GetConfig().WORLD_Z.Get();
+
int num_demes = m_world->GetConfig().NUM_DEMES.Get();
- const int num_cells = world_x * world_y;
+ const int num_cells = world_x * world_y * world_z;
const int geometry = world->GetConfig().WORLD_GEOMETRY.Get();
if(m_world->GetConfig().ENERGY_CAP.Get() == -1) {
@@ -98,12 +100,13 @@
}
// Print out world details
if (world->GetVerbosity() > VERBOSE_NORMAL) {
- cout << "Building world " << world_x << "x" << world_y << " = " << num_cells << " organisms." << endl;
+ cout << "Building world " << world_x << "x" << world_y << "x" << world_z << " = " << 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; }
+ case nGeometry::LATTICE: { cout << "Geometry: Lattice" << endl; break; }
default:
cout << "Unknown geometry!" << endl;
assert(false);
@@ -114,6 +117,10 @@
if (num_demes <= 0) {
num_demes = 1; // One population == one deme.
}
+
+ // Not ready for prime time yet; need to look at how resources work in this now
+ // more complex world.
+ assert(world_z == 1);
// The following combination of options creates an infinite rotate-loop:
assert(!((m_world->GetConfig().DEMES_ORGANISM_PLACEMENT.Get()==0)
@@ -190,6 +197,9 @@
case nGeometry::HEX:
build_hex(&cell_array.begin()[i], &cell_array.begin()[i+deme_size], deme_size_x, deme_size_y);
break;
+ case nGeometry::LATTICE:
+ build_lattice(&cell_array.begin()[i], &cell_array.begin()[i+deme_size], deme_size_x, deme_size_y, world_z);
+ break;
default:
assert(false);
}
Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h 2008-09-29 16:15:54 UTC (rev 2806)
+++ development/source/main/cPopulation.h 2008-09-29 22:26:23 UTC (rev 2807)
@@ -105,7 +105,8 @@
// Other data...
int world_x; // Structured population width.
- int world_y; // Structured population
+ int world_y; // Structured population height.
+ int world_z; //!< Population depth.
int num_organisms; // Cell count with living organisms
tArray<cDeme> deme_array; // Deme structure of the population.
Modified: development/source/main/nGeometry.h
===================================================================
--- development/source/main/nGeometry.h 2008-09-29 16:15:54 UTC (rev 2806)
+++ development/source/main/nGeometry.h 2008-09-29 22:26:23 UTC (rev 2807)
@@ -33,7 +33,8 @@
GRID,
TORUS,
CLIQUE,
- HEX
+ HEX,
+ LATTICE
};
}
Modified: development/source/tools/cTopology.h
===================================================================
--- development/source/tools/cTopology.h 2008-09-29 16:15:54 UTC (rev 2806)
+++ development/source/tools/cTopology.h 2008-09-29 22:26:23 UTC (rev 2807)
@@ -107,4 +107,75 @@
}
}
+/*! Builds a 3-dimensional lattice of cells, where the dimensions of the lattice are specified by
+ x, y, and z.
+
+ A cell in the middle of the lattice is connected to 26 other cells (9 above, 9 below, and 8 on the
+ same plane). Edges do not wrap around in any direction.
+ */
+template< typename InputIterator >
+void build_lattice(InputIterator begin, InputIterator end, unsigned int x_size, unsigned int y_size, unsigned int z_size) {
+ // First we're going to create z grids each sized x by y:
+ unsigned int gridsize = x_size * y_size;
+ for(unsigned int i=0; i<z_size; ++i) {
+ build_grid(&begin[gridsize*i], &begin[gridsize*(i+1)], x_size, y_size);
+ }
+
+ // This is the offset from the beginning of the cell_array; req'd to support demes.
+ int offset = begin->GetID();
+
+ // Now, iterate through each cell, and link them to their neighbors above and below:
+ for(InputIterator i=begin; i!=end; ++i) {
+ unsigned int layer = (i->GetID()-offset) / gridsize;
+ unsigned int x = (i->GetID()-offset) % x_size;
+ unsigned int y = (i->GetID()-offset) / x_size;
+
+ // The below is a big mess. The reason it's a mess is because we have to respect the boundaries
+ // of the grid. There are probably much cleaner ways to do this, but it's complicated
+ // enough now without having to think that through. And anyway, this is only run
+ // at initialization. Feel free to fix it, however.
+ if(layer != 0) {
+ // We're not at the bottom; link to the layer below us.
+ if(x != 0) {
+ if(y != 0) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset-gridsize, x_size, y_size, -1, -1)]); }
+ if(y != (y_size-1)) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset-gridsize, x_size, y_size, -1, 1)]); }
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset-gridsize, x_size, y_size, -1, 0)]);
+ }
+
+ if(x != (x_size-1)) {
+ if(y != 0) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset-gridsize, x_size, y_size, 1, -1)]); }
+ if(y != (y_size-1)) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset-gridsize, x_size, y_size, 1, 1)]); }
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset-gridsize, x_size, y_size, 1, 0)]);
+ }
+
+ if(y != 0) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset-gridsize, x_size, y_size, 0, -1)]); }
+ if(y != (y_size-1)) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset-gridsize, x_size, y_size, 0, 1)]); }
+
+ // And now the cell right below this one:
+ i->ConnectionList().Push(&begin[i->GetID()-offset-gridsize]);
+ }
+
+ if(layer != (z_size-1)) {
+ // We're not at the top; link to the layer above us:
+ if(x != 0) {
+ if(y != 0) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset+gridsize, x_size, y_size, -1, -1)]); }
+ if(y != (y_size-1)) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset+gridsize, x_size, y_size, -1, 1)]); }
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset+gridsize, x_size, y_size, -1, 0)]);
+ }
+
+ if(x != (x_size-1)) {
+ if(y != 0) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset+gridsize, x_size, y_size, 1, -1)]); }
+ if(y != (y_size-1)) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset+gridsize, x_size, y_size, 1, 1)]); }
+ i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset+gridsize, x_size, y_size, 1, 0)]);
+ }
+
+ if(y != 0) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset+gridsize, x_size, y_size, 0, -1)]); }
+ if(y != (y_size-1)) { i->ConnectionList().Push(&begin[GridNeighbor(i->GetID()-offset+gridsize, x_size, y_size, 0, 1)]); }
+
+ // And now the cell right above this one:
+ i->ConnectionList().Push(&begin[i->GetID()-offset+gridsize]);
+ }
+ }
+}
+
#endif
More information about the Avida-cvs
mailing list