[avida-cvs] avida CVS commits: /current/source/event cPopulation.events cPopulation_construct_event_auto.ci cPopulation_descr.ci cPopulation_enums_auto.ci cPopulation_event_list cPopulation_name2enum_auto.ci cPopulation_process_auto.ci /current/source/main population.cc

mercere99 avida-cvs at alife.org
Sun Oct 12 21:07:51 PDT 2003


mercere99		Sun Oct 12 13:07:51 2003 EDT

  Modified files:              
    /avida/current/source/event	cPopulation.events 
                               	cPopulation_construct_event_auto.ci 
                               	cPopulation_descr.ci 
                               	cPopulation_enums_auto.ci 
                               	cPopulation_event_list 
                               	cPopulation_name2enum_auto.ci 
                               	cPopulation_process_auto.ci 
    /avida/current/source/main	population.cc 
  Log:
  Added in three new events to modify the topology of a population:
    sever_column : sever a full column of cells
    connect_cells : connect two cells together
    disconnect_cells : disconnect two cells from each other.
  
  
  
-------------- next part --------------
Index: avida/current/source/event/cPopulation.events
diff -u avida/current/source/event/cPopulation.events:1.44 avida/current/source/event/cPopulation.events:1.45
--- avida/current/source/event/cPopulation.events:1.44	Wed Sep 24 15:58:36 2003
+++ avida/current/source/event/cPopulation.events	Sun Oct 12 13:07:50 2003
@@ -1576,6 +1576,115 @@
 cAnalyzeUtil::PrintTreeDepths(population, fp);
 
 
+########## Grid Structure ############
+sever_grid_col
+:descr:
+/**
+* Remove the connections between cells along a column in an avida grid.
+* Arguments:
+*  col_id:  indicats the number of columns to the left of the cut.
+*           default (or -1) = cut population in half
+*  min_row: First row to start cutting from
+*           default = 0
+*  max_row: Last row to cut to
+*           default (or -1) = last row in population.
+**/
+:args:
+int col_id -1
+int min_row 0
+int max_row -1
+:body:
+const int world_x = population->GetWorldX();
+const int world_y = population->GetWorldY();
+if (col_id == -1) col_id = world_x / 2;
+if (max_row == -1) max_row = world_y;
+if (col_id < 0 || col_id >= world_x) {
+  cerr << "Event Error: Column ID " << col_id
+       << " out of range for sever_grid_col" << endl;
+  return;
+}
+// Loop through all of the rows and make the cut on each...
+for (int row_id = min_row; row_id < max_row; row_id++) {
+  int idA = row_id * world_x + col_id;
+  int idB  = Neighbor(idA, world_x, world_y, -1,  0);
+  int idA0 = Neighbor(idA, world_x, world_y,  0, -1);
+  int idA1 = Neighbor(idA, world_x, world_y,  0,  1);
+  int idB0 = Neighbor(idA, world_x, world_y, -1, -1);
+  int idB1 = Neighbor(idA, world_x, world_y, -1,  1);
+  cPopulationCell & cellA = population->GetCell(idA);
+  cPopulationCell & cellB = population->GetCell(idB);
+  tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
+  tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
+  cellA_list.Remove(&population->GetCell(idB));
+  cellA_list.Remove(&population->GetCell(idB0));
+  cellA_list.Remove(&population->GetCell(idB1));
+  cellB_list.Remove(&population->GetCell(idA));
+  cellB_list.Remove(&population->GetCell(idA0));
+  cellB_list.Remove(&population->GetCell(idA1));
+}
+
+connect_cells
+:descr:
+/**
+* Connects a pair of specified cells.
+* Arguments:
+*  cellA_x, cellA_y, cellB_x, cellB_y
+**/
+:args:
+int cellA_x
+int cellA_y
+int cellB_x
+int cellB_y
+:body:
+const int world_x = population->GetWorldX();
+const int world_y = population->GetWorldY();
+if (cellA_x < 0 || cellA_x >= world_x ||
+    cellA_y < 0 || cellA_y >= world_y ||
+    cellB_x < 0 || cellB_x >= world_x ||
+    cellB_y < 0 || cellB_y >= world_y) {
+  cerr << "Event 'connect_cells' cell out of range." << endl;
+  return;
+}
+int idA = cellA_y * world_x + cellA_x;
+int idB = cellB_y * world_x + cellB_x;
+cPopulationCell & cellA = population->GetCell(idA);
+cPopulationCell & cellB = population->GetCell(idB);
+tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
+tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
+cellA_list.PushRear(&cellB);
+cellB_list.PushRear(&cellA);
+
+disconnect_cells
+:descr:
+/**
+* Connects a pair of specified cells.
+* Arguments:
+*  cellA_x, cellA_y, cellB_x, cellB_y
+**/
+:args:
+int cellA_x
+int cellA_y
+int cellB_x
+int cellB_y
+:body:
+const int world_x = population->GetWorldX();
+const int world_y = population->GetWorldY();
+if (cellA_x < 0 || cellA_x >= world_x ||
+    cellA_y < 0 || cellA_y >= world_y ||
+    cellB_x < 0 || cellB_x >= world_x ||
+    cellB_y < 0 || cellB_y >= world_y) {
+  cerr << "Event 'connect_cells' cell out of range." << endl;
+  return;
+}
+int idA = cellA_y * world_x + cellA_x;
+int idB = cellB_y * world_x + cellB_x;
+cPopulationCell & cellA = population->GetCell(idA);
+cPopulationCell & cellB = population->GetCell(idB);
+tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
+tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
+cellA_list.Remove(&cellB);
+cellB_list.Remove(&cellA);
+
 ########## Resources ############
 inject_resource
 :descr:
Index: avida/current/source/event/cPopulation_construct_event_auto.ci
diff -u avida/current/source/event/cPopulation_construct_event_auto.ci:1.6 avida/current/source/event/cPopulation_construct_event_auto.ci:1.7
--- avida/current/source/event/cPopulation_construct_event_auto.ci:1.6	Wed Sep 24 15:58:36 2003
+++ avida/current/source/event/cPopulation_construct_event_auto.ci	Sun Oct 12 13:07:50 2003
@@ -253,6 +253,15 @@
     case cPopulationEventFactory::EVENT_print_tree_depths :
       event = new cPopulationEventprint_tree_depths(arg_list);
       break;
+    case cPopulationEventFactory::EVENT_sever_grid_col :
+      event = new cPopulationEventsever_grid_col(arg_list);
+      break;
+    case cPopulationEventFactory::EVENT_connect_cells :
+      event = new cPopulationEventconnect_cells(arg_list);
+      break;
+    case cPopulationEventFactory::EVENT_disconnect_cells :
+      event = new cPopulationEventdisconnect_cells(arg_list);
+      break;
     case cPopulationEventFactory::EVENT_inject_resource :
       event = new cPopulationEventinject_resource(arg_list);
       break;
Index: avida/current/source/event/cPopulation_descr.ci
diff -u avida/current/source/event/cPopulation_descr.ci:1.6 avida/current/source/event/cPopulation_descr.ci:1.7
--- avida/current/source/event/cPopulation_descr.ci:1.6	Wed Sep 24 15:58:36 2003
+++ avida/current/source/event/cPopulation_descr.ci	Sun Oct 12 13:07:50 2003
@@ -84,8 +84,11 @@
   cEventEntry( "dump_fitness_grid", "Writes out all fitness values of the organisms currently in the\npopulation.\n\nThe output file is called \"fgrid.*.out\", where '*' is replaced by the\nnumber of the current update.\n" ),
   cEventEntry( "dump_genotype_grid", "Writes out all genotype id values of the organisms currently in the\npopulation.\n\nThe output file is called \"idgrid.*.out\", where '*' is replaced by the\nnumber of the current update.\n" ),
   cEventEntry( "print_tree_depths", "Reconstruction of phylogenetic trees.\n" ),
+  cEventEntry( "sever_grid_col", "Remove the connections between cells along a column in an avida grid.\nArguments:\n col_id:  indicats the number of columns to the left of the cut.\n          default (or -1) = cut population in half\n min_row: First row to start cutting from\n          default = 0\n max_row: Last row to cut to\n          default (or -1) = last row in population.\n" ),
+  cEventEntry( "connect_cells", "Connects a pair of specified cells.\nArguments:\n cellA_x, cellA_y, cellB_x, cellB_y\n" ),
+  cEventEntry( "disconnect_cells", "Connects a pair of specified cells.\nArguments:\n cellA_x, cellA_y, cellB_x, cellB_y\n" ),
   cEventEntry( "inject_resource", "Inject (add) a specified amount of a specified resource.\n" ),
   cEventEntry( "set_resource", "Set the resource amount to a specific level\n" ) };
 
-const int cEventDescrs::num_of_events = 87;
+const int cEventDescrs::num_of_events = 90;
 
Index: avida/current/source/event/cPopulation_enums_auto.ci
diff -u avida/current/source/event/cPopulation_enums_auto.ci:1.6 avida/current/source/event/cPopulation_enums_auto.ci:1.7
--- avida/current/source/event/cPopulation_enums_auto.ci:1.6	Wed Sep 24 15:58:36 2003
+++ avida/current/source/event/cPopulation_enums_auto.ci	Sun Oct 12 13:07:50 2003
@@ -84,6 +84,9 @@
   EVENT_dump_fitness_grid,
   EVENT_dump_genotype_grid,
   EVENT_print_tree_depths,
+  EVENT_sever_grid_col,
+  EVENT_connect_cells,
+  EVENT_disconnect_cells,
   EVENT_inject_resource,
   EVENT_set_resource,
 EVENT_NO_EVENT };
Index: avida/current/source/event/cPopulation_event_list
diff -u avida/current/source/event/cPopulation_event_list:1.6 avida/current/source/event/cPopulation_event_list:1.7
--- avida/current/source/event/cPopulation_event_list:1.6	Wed Sep 24 15:58:36 2003
+++ avida/current/source/event/cPopulation_event_list	Sun Oct 12 13:07:50 2003
@@ -85,5 +85,8 @@
 dump_fitness_grid 
 dump_genotype_grid 
 print_tree_depths  [cString filename=""]
+sever_grid_col  [int col_id=-1] [int min_row=0] [int max_row=-1]
+connect_cells  <int cellA_x> <int cellA_y> <int cellB_x> <int cellB_y>
+disconnect_cells  <int cellA_x> <int cellA_y> <int cellB_x> <int cellB_y>
 inject_resource  <cString res_name> <double res_count>
 set_resource  <cString res_name> <double res_count>
Index: avida/current/source/event/cPopulation_name2enum_auto.ci
diff -u avida/current/source/event/cPopulation_name2enum_auto.ci:1.6 avida/current/source/event/cPopulation_name2enum_auto.ci:1.7
--- avida/current/source/event/cPopulation_name2enum_auto.ci:1.6	Wed Sep 24 15:58:36 2003
+++ avida/current/source/event/cPopulation_name2enum_auto.ci	Sun Oct 12 13:07:50 2003
@@ -171,6 +171,12 @@
     return cPopulationEventFactory::EVENT_dump_genotype_grid;
   }else if (name == "print_tree_depths") {
     return cPopulationEventFactory::EVENT_print_tree_depths;
+  }else if (name == "sever_grid_col") {
+    return cPopulationEventFactory::EVENT_sever_grid_col;
+  }else if (name == "connect_cells") {
+    return cPopulationEventFactory::EVENT_connect_cells;
+  }else if (name == "disconnect_cells") {
+    return cPopulationEventFactory::EVENT_disconnect_cells;
   }else if (name == "inject_resource") {
     return cPopulationEventFactory::EVENT_inject_resource;
   }else if (name == "set_resource") {
Index: avida/current/source/event/cPopulation_process_auto.ci
diff -u avida/current/source/event/cPopulation_process_auto.ci:1.6 avida/current/source/event/cPopulation_process_auto.ci:1.7
--- avida/current/source/event/cPopulation_process_auto.ci:1.6	Wed Sep 24 15:58:36 2003
+++ avida/current/source/event/cPopulation_process_auto.ci	Sun Oct 12 13:07:50 2003
@@ -2655,6 +2655,161 @@
   }
 };
 
+///// sever_grid_col /////
+
+/**
+* Remove the connections between cells along a column in an avida grid.
+* Arguments:
+*  col_id:  indicats the number of columns to the left of the cut.
+*           default (or -1) = cut population in half
+*  min_row: First row to start cutting from
+*           default = 0
+*  max_row: Last row to cut to
+*           default (or -1) = last row in population.
+**/
+
+
+class cPopulationEventsever_grid_col : public cPopulationEvent {
+private:
+  int col_id;
+  int min_row;
+  int max_row;
+public:
+  cPopulationEventsever_grid_col(const cString & in_args):
+   cPopulationEvent("sever_grid_col", in_args) {
+
+    cString args(in_args);
+    if (args == "") col_id=-1; else col_id=args.PopWord().AsInt();
+    if (args == "") min_row=0; else min_row=args.PopWord().AsInt();
+    if (args == "") max_row=-1; else max_row=args.PopWord().AsInt();
+  }
+///// sever_grid_col /////
+  void Process(){
+    const int world_x = population->GetWorldX();
+    const int world_y = population->GetWorldY();
+    if (col_id == -1) col_id = world_x / 2;
+    if (max_row == -1) max_row = world_y;
+    if (col_id < 0 || col_id >= world_x) {
+      cerr << "Event Error: Column ID " << col_id
+           << " out of range for sever_grid_col" << endl;
+      return;
+    }
+    // Loop through all of the rows and make the cut on each...
+    for (int row_id = min_row; row_id < max_row; row_id++) {
+      int idA = row_id * world_x + col_id;
+      int idB  = Neighbor(idA, world_x, world_y, -1,  0);
+      int idA0 = Neighbor(idA, world_x, world_y,  0, -1);
+      int idA1 = Neighbor(idA, world_x, world_y,  0,  1);
+      int idB0 = Neighbor(idA, world_x, world_y, -1, -1);
+      int idB1 = Neighbor(idA, world_x, world_y, -1,  1);
+      cPopulationCell & cellA = population->GetCell(idA);
+      cPopulationCell & cellB = population->GetCell(idB);
+      tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
+      tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
+      cellA_list.Remove(&population->GetCell(idB));
+      cellA_list.Remove(&population->GetCell(idB0));
+      cellA_list.Remove(&population->GetCell(idB1));
+      cellB_list.Remove(&population->GetCell(idA));
+      cellB_list.Remove(&population->GetCell(idA0));
+      cellB_list.Remove(&population->GetCell(idA1));
+    }
+  }
+};
+
+///// connect_cells /////
+
+/**
+* Connects a pair of specified cells.
+* Arguments:
+*  cellA_x, cellA_y, cellB_x, cellB_y
+**/
+
+
+class cPopulationEventconnect_cells : public cPopulationEvent {
+private:
+  int cellA_x;
+  int cellA_y;
+  int cellB_x;
+  int cellB_y;
+public:
+  cPopulationEventconnect_cells(const cString & in_args):
+   cPopulationEvent("connect_cells", in_args) {
+
+    cString args(in_args);
+    cellA_x = args.PopWord().AsInt();
+    cellA_y = args.PopWord().AsInt();
+    cellB_x = args.PopWord().AsInt();
+    cellB_y = args.PopWord().AsInt();
+  }
+///// connect_cells /////
+  void Process(){
+    const int world_x = population->GetWorldX();
+    const int world_y = population->GetWorldY();
+    if (cellA_x < 0 || cellA_x >= world_x ||
+        cellA_y < 0 || cellA_y >= world_y ||
+        cellB_x < 0 || cellB_x >= world_x ||
+        cellB_y < 0 || cellB_y >= world_y) {
+      cerr << "Event 'connect_cells' cell out of range." << endl;
+      return;
+    }
+    int idA = cellA_y * world_x + cellA_x;
+    int idB = cellB_y * world_x + cellB_x;
+    cPopulationCell & cellA = population->GetCell(idA);
+    cPopulationCell & cellB = population->GetCell(idB);
+    tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
+    tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
+    cellA_list.PushRear(&cellB);
+    cellB_list.PushRear(&cellA);
+  }
+};
+
+///// disconnect_cells /////
+
+/**
+* Connects a pair of specified cells.
+* Arguments:
+*  cellA_x, cellA_y, cellB_x, cellB_y
+**/
+
+
+class cPopulationEventdisconnect_cells : public cPopulationEvent {
+private:
+  int cellA_x;
+  int cellA_y;
+  int cellB_x;
+  int cellB_y;
+public:
+  cPopulationEventdisconnect_cells(const cString & in_args):
+   cPopulationEvent("disconnect_cells", in_args) {
+
+    cString args(in_args);
+    cellA_x = args.PopWord().AsInt();
+    cellA_y = args.PopWord().AsInt();
+    cellB_x = args.PopWord().AsInt();
+    cellB_y = args.PopWord().AsInt();
+  }
+///// disconnect_cells /////
+  void Process(){
+    const int world_x = population->GetWorldX();
+    const int world_y = population->GetWorldY();
+    if (cellA_x < 0 || cellA_x >= world_x ||
+        cellA_y < 0 || cellA_y >= world_y ||
+        cellB_x < 0 || cellB_x >= world_x ||
+        cellB_y < 0 || cellB_y >= world_y) {
+      cerr << "Event 'connect_cells' cell out of range." << endl;
+      return;
+    }
+    int idA = cellA_y * world_x + cellA_x;
+    int idB = cellB_y * world_x + cellB_x;
+    cPopulationCell & cellA = population->GetCell(idA);
+    cPopulationCell & cellB = population->GetCell(idB);
+    tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
+    tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
+    cellA_list.Remove(&cellB);
+    cellB_list.Remove(&cellA);
+  }
+};
+
 ///// inject_resource /////
 
 /**
Index: avida/current/source/main/population.cc
diff -u avida/current/source/main/population.cc:1.117 avida/current/source/main/population.cc:1.118
--- avida/current/source/main/population.cc:1.117	Wed Sep 24 15:58:37 2003
+++ avida/current/source/main/population.cc	Sun Oct 12 13:07:51 2003
@@ -96,59 +96,49 @@
   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;
+    bool has_bottom = true;
+    bool has_top = true;
+    bool has_right = true;
+    bool has_left = true;
+
+    if (geometry == GEOMETRY_GRID) {
+      if (y == 0) has_bottom = false;
+      if (y == world_y-1) has_top = false;
+      if (x == 0) has_left = false;
+      if (x == world_x-1) has_right = false;
     }
 
     // Setup the connection list for each cell. (Clockwise from -1 to 1)
 
     tList<cPopulationCell> & conn_list=cell_array[cell_id].ConnectionList();
-    if (bottom_flag && left_flag) {
+    if (has_bottom && has_left) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, -1, -1)]));
     }
-    if (bottom_flag) {
+    if (has_bottom) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y,  0, -1)]));
     }
-    if (bottom_flag && right_flag) {
+    if (has_bottom && has_right) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, +1, -1)]));
     }
-    if (right_flag) {
+    if (has_right) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, +1,  0)]));
     }
-    if (top_flag && right_flag) {
+    if (has_top && has_right) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, +1, +1)]));
     }
-    if (top_flag) {
+    if (has_top) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y,  0, +1)]));
     }
-    if (top_flag && left_flag) {
+    if (has_top && has_left) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, -1, +1)]));
     }
-    if (left_flag) {
+    if (has_left) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, -1,  0)]));
     }
 


More information about the Avida-cvs mailing list