[avida-cvs] avida CVS commits: /current/source/main config.cc config.hh population.cc /current/source/support genesis

bdbaer avida-cvs at alife.org
Thu Aug 7 17:28:33 PDT 2003


bdbaer		Thu Aug  7 09:28:33 2003 EDT

  Modified files:              
    /avida/current/source/main	population.cc config.cc config.hh 
    /avida/current/source/support	genesis 
  Log:
  Added Bounded Grid/Torus switch to population.  Leaving torus as the 
  default.
  
  
  
Index: avida/current/source/main/population.cc
diff -u avida/current/source/main/population.cc:1.111 avida/current/source/main/population.cc:1.112
--- avida/current/source/main/population.cc:1.111	Thu Jul 31 15:34:27 2003
+++ avida/current/source/main/population.cc	Thu Aug  7 09:28:32 2003
@@ -76,26 +76,76 @@
   // Avida specific information.
   world_x = cConfig::GetWorldX();
   world_y = cConfig::GetWorldY();
+  int geometry = cConfig::GetWorldGeometry();
   const int num_cells = world_x * world_y;
   cout << "Building world " << world_x << "x" << world_y
        << " = " << num_cells << " organisms." << endl;
+  if (geometry == GEOMETRY_GRID) {
+    cout << "Geometry: Bounded grid" << endl;
+  } else if (geometry == GEOMETRY_TORUS) {
+    cout << "Geometry: Torus" << endl;
+  } else {
+    cout << "Geometry: Unknown" << endl;
+  }
 
   cell_array.Resize(num_cells);
   resource_count.ResizeSpatialGrids(world_x, world_y);
-
+  
+  bool bottom_flag, top_flag, right_flag, left_flag;
   for (int cell_id = 0; cell_id < num_cells; cell_id++) {
+    int x = cell_id % world_x;
+    int y = cell_id / world_x;
     cell_array[cell_id].Setup(cell_id, default_mut_rates);
 
+
+    if ((y == 0) && (geometry == GEOMETRY_GRID)) {
+      bottom_flag = false;
+    } else {
+      bottom_flag = true;
+    }
+    if ((y == world_y-1) && (geometry == GEOMETRY_GRID)) {
+      top_flag = false;
+    } else {
+      top_flag = true;
+    }
+    if ((x == 0) && (geometry == GEOMETRY_GRID)) {
+      left_flag = false;
+    } else {
+      left_flag = true;
+    }
+    if ((x == world_x-1) && (geometry == GEOMETRY_GRID)) {
+      right_flag = false;
+    } else {
+      right_flag = true;
+    }
+
     // Setup the connection list for each cell. (Clockwise from -1 to 1)
-    tList<cPopulationCell> & conn_list = cell_array[cell_id].ConnectionList();
-    conn_list.Push(&(cell_array[Neighbor(cell_id, world_x, world_y, -1, -1)]));
-    conn_list.Push(&(cell_array[Neighbor(cell_id, world_x, world_y,  0, -1)]));
-    conn_list.Push(&(cell_array[Neighbor(cell_id, world_x, world_y, +1, -1)]));
-    conn_list.Push(&(cell_array[Neighbor(cell_id, world_x, world_y, +1,  0)]));
-    conn_list.Push(&(cell_array[Neighbor(cell_id, world_x, world_y, +1, +1)]));
-    conn_list.Push(&(cell_array[Neighbor(cell_id, world_x, world_y,  0, +1)]));
-    conn_list.Push(&(cell_array[Neighbor(cell_id, world_x, world_y, -1, +1)]));
-    conn_list.Push(&(cell_array[Neighbor(cell_id, world_x, world_y, -1,  0)]));
+
+    tList<cPopulationCell> & conn_list=cell_array[cell_id].ConnectionList();
+    if (bottom_flag && left_flag) {
+      conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, -1, -1)]));
+    }
+    if (bottom_flag) {
+      conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y,  0, -1)]));
+    }
+    if (bottom_flag && right_flag) {
+      conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, +1, -1)]));
+    }
+    if (right_flag) {
+      conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, +1,  0)]));
+    }
+    if (top_flag && right_flag) {
+      conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, +1, +1)]));
+    }
+    if (top_flag) {
+      conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y,  0, +1)]));
+    }
+    if (top_flag && left_flag) {
+      conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, -1, +1)]));
+    }
+    if (left_flag) {
+      conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, -1,  0)]));
+    }
 
     // Setup the reaper queue...
     if (cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_ELDEST) {
@@ -1039,6 +1089,7 @@
 	 << mem.AsString() << endl;
     }
   }
+  return true;
 }
 
 bool cPopulation::OK()
Index: avida/current/source/main/config.cc
diff -u avida/current/source/main/config.cc:1.59 avida/current/source/main/config.cc:1.60
--- avida/current/source/main/config.cc:1.59	Thu Jul 31 15:34:27 2003
+++ avida/current/source/main/config.cc	Thu Aug  7 09:28:32 2003
@@ -33,6 +33,7 @@
 int cConfig::end_condition_mode;
 int cConfig::world_x;
 int cConfig::world_y;
+int cConfig::world_geometry;
 int cConfig::rand_seed;
 double cConfig::point_mut_prob;
 double cConfig::copy_mut_prob;
@@ -117,6 +118,8 @@
 		  "Width of the Avida world");
   arch_group->Add(world_y, "100", "WORLD-Y",
 		  "Height of the Avida world");
+  arch_group->Add(world_geometry, "2", "WORLD_GEOMETRY",
+		  "1 = Bounded Grid\n2 = Torus");
   arch_group->Add(rand_seed, "0", "RANDOM_SEED",
 		  "Random number seed (0 for based on time)");
   arch_group->Add(hardware_type, "0", "HARDWARE_TYPE",
Index: avida/current/source/main/config.hh
diff -u avida/current/source/main/config.hh:1.54 avida/current/source/main/config.hh:1.55
--- avida/current/source/main/config.hh:1.54	Thu Jul 31 15:34:27 2003
+++ avida/current/source/main/config.hh	Thu Aug  7 09:28:32 2003
@@ -56,6 +56,10 @@
 #define SIZE_MERIT_LEAST       4
 #define SIZE_MERIT_SQRT_LEAST  5
 
+#define GEOMETRY_GLOBAL 0
+#define GEOMETRY_GRID   1
+#define GEOMETRY_TORUS  2
+
 class cConfig {
 protected:
   class cConfigEntryBase {
@@ -69,6 +73,7 @@
       : genesis_tag(_tag), default_value(_def), description(_desc, '\n') { ; }
     virtual ~cConfigEntryBase(){}
 
+    //    virtual ~cConfigEntryBase();
     const cString & GetTag() { return genesis_tag; }
     const cString & GetDefault() { return default_value; }
     const cStringList & GetDesc() { return description; }
@@ -170,6 +175,7 @@
   static int end_condition_mode;
   static int world_x;
   static int world_y;
+  static int world_geometry;
   static int rand_seed;
 
   // Mutations
@@ -295,6 +301,7 @@
   static int GetEndConditionMode() { return end_condition_mode; }
   static int GetWorldX()         { return world_x; }
   static int GetWorldY()         { return world_y; }
+  static int GetWorldGeometry()  { return world_geometry; }
   static int GetRandSeed()       { return rand_seed; }
 
   static double GetPointMutProb()  { return point_mut_prob; }
Index: avida/current/source/support/genesis
diff -u avida/current/source/support/genesis:1.41 avida/current/source/support/genesis:1.42
--- avida/current/source/support/genesis:1.41	Mon Jun  9 13:59:27 2003
+++ avida/current/source/support/genesis	Thu Aug  7 09:28:32 2003
@@ -13,6 +13,8 @@
 			# 1 = MAX_UPDATES _AND_ MAX_GENERATIONS is reached
 WORLD-X 60		# Width of the world in Avida mode.
 WORLD-Y 60		# Height of the world in Avida mode.
+WORLD_GEOMETRY 2        # 1 = Bounded Grid
+                        # 2 = Torus (Default)
 RANDOM_SEED 0		# Random number seed. (0 for based on time)
 HARDWARE_TYPE 0		# 0 = Original CPUs
 			# 1 = New, Stack-based CPUs






More information about the Avida-cvs mailing list