[avida-cvs] avida CVS commits: /current/source/event cPopulation.events cPopulation_enums_auto.ci /current/source/main analyze.cc analyze.hh config.cc config.hh population.cc /current/source/support genesis /current/source/tools tList.hh

mercere99 avida-cvs at alife.org
Wed Dec 10 21:56:57 PST 2003


mercere99		Wed Dec 10 13:56:57 2003 EDT

  Modified files:              
    /avida/current/source/event	cPopulation.events 
                               	cPopulation_enums_auto.ci 
    /avida/current/source/main	analyze.cc analyze.hh config.cc 
                              	config.hh population.cc 
    /avida/current/source/support	genesis 
    /avida/current/source/tools	tList.hh 
  Log:
  Created more events to control population wall creation and removal.
  
  Added analyze command "WRITE_COMPETITION", which will take all of the
  genotypes in two batches and setup events for a competition experiment
  between them.  Specifically, there will be two halves to the population
  seperated by a wall, and the wall will be lifted at a pre-determined update
  number.  I'm still debugging this command, but its looking good.
  
  
-------------- next part --------------
Index: avida/current/source/event/cPopulation.events
diff -u avida/current/source/event/cPopulation.events:1.48 avida/current/source/event/cPopulation.events:1.49
--- avida/current/source/event/cPopulation.events:1.48	Fri Dec  5 06:34:20 2003
+++ avida/current/source/event/cPopulation.events	Wed Dec 10 13:56:56 2003
@@ -1586,7 +1586,7 @@
 /**
 * 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.
+*  col_id:  indicates 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
@@ -1625,6 +1625,152 @@
   cellB_list.Remove(&population->GetCell(idA));
   cellB_list.Remove(&population->GetCell(idA0));
   cellB_list.Remove(&population->GetCell(idA1));
+}
+
+sever_grid_row
+:descr:
+/**
+* Remove the connections between cells along a column in an avida grid.
+* Arguments:
+*  row_id:  indicates the number of rows abovef the cut.
+*           default (or -1) = cut population in half
+*  min_col: First row to start cutting from
+*           default = 0
+*  max_col: Last row to cut to
+*           default (or -1) = last row in population.
+**/
+:args:
+int row_id -1
+int min_col 0
+int max_col -1
+:body:
+const int world_x = population->GetWorldX();
+const int world_y = population->GetWorldY();
+if (row_id == -1) row_id = world_y / 2;
+if (max_col == -1) max_col = world_x;
+if (row_id < 0 || row_id >= world_y) {
+  cerr << "Event Error: Row ID " << row_id
+       << " out of range for sever_grid_row" << endl;
+  return;
+}
+// Loop through all of the cols and make the cut on each...
+for (int col_id = min_col; col_id < max_col; col_id++) {
+  int idA = row_id * world_x + col_id;
+  int idB  = Neighbor(idA, world_x, world_y,  0, -1);
+  int idA0 = Neighbor(idA, world_x, world_y, -1,  0);
+  int idA1 = Neighbor(idA, world_x, world_y,  1,  0);
+  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));
+}
+
+join_grid_col
+:descr:
+/**
+* Join the connections between cells along a column in an avida grid.
+* Arguments:
+*  col_id:  indicates the number of columns to the left of the joining.
+*           default (or -1) = join population halves.
+*  min_row: First row to start joining from
+*           default = 0
+*  max_row: Last row to join 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 join_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);
+  cPopulationCell & cellA = population->GetCell(idA);
+  cPopulationCell & cellB = population->GetCell(idB);
+  cPopulationCell & cellA0 =
+	 population->GetCell(Neighbor(idA, world_x, world_y,  0, -1));
+  cPopulationCell & cellA1 =
+	 population->GetCell(Neighbor(idA, world_x, world_y,  0,  1));
+  cPopulationCell & cellB0 =
+	 population->GetCell(Neighbor(idA, world_x, world_y, -1, -1));
+  cPopulationCell & cellB1 =
+	 population->GetCell(Neighbor(idA, world_x, world_y, -1,  1));
+  tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
+  tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
+  if (cellA_list.FindPtr(&cellB)  == NULL) cellA_list.Push(&cellB);
+  if (cellA_list.FindPtr(&cellB0) == NULL) cellA_list.Push(&cellB0);
+  if (cellA_list.FindPtr(&cellB1) == NULL) cellA_list.Push(&cellB1);
+  if (cellB_list.FindPtr(&cellA)  == NULL) cellB_list.Push(&cellA);
+  if (cellB_list.FindPtr(&cellA0) == NULL) cellB_list.Push(&cellA0);
+  if (cellB_list.FindPtr(&cellA1) == NULL) cellB_list.Push(&cellA1);
+}
+
+join_grid_row
+:descr:
+/**
+* Remove the connections between cells along a column in an avida grid.
+* Arguments:
+*  row_id:  indicates the number of rows abovef the cut.
+*           default (or -1) = cut population in half
+*  min_col: First row to start cutting from
+*           default = 0
+*  max_col: Last row to cut to
+*           default (or -1) = last row in population.
+**/
+:args:
+int row_id -1
+int min_col 0
+int max_col -1
+:body:
+const int world_x = population->GetWorldX();
+const int world_y = population->GetWorldY();
+if (row_id == -1) row_id = world_y / 2;
+if (max_col == -1) max_col = world_x;
+if (row_id < 0 || row_id >= world_y) {
+  cerr << "Event Error: Row ID " << row_id
+       << " out of range for join_grid_row" << endl;
+  return;
+}
+// Loop through all of the cols and make the cut on each...
+for (int col_id = min_col; col_id < max_col; col_id++) {
+  int idA = row_id * world_x + col_id;
+  int idB  = Neighbor(idA, world_x, world_y,  0, -1);
+  cPopulationCell & cellA = population->GetCell(idA);
+  cPopulationCell & cellB = population->GetCell(idB);
+  cPopulationCell & cellA0 =
+	 population->GetCell(Neighbor(idA, world_x, world_y, -1,  0));
+  cPopulationCell & cellA1 =
+	 population->GetCell(Neighbor(idA, world_x, world_y,  1,  0));
+  cPopulationCell & cellB0 =
+	 population->GetCell(Neighbor(idA, world_x, world_y, -1, -1));
+  cPopulationCell & cellB1 =
+	 population->GetCell(Neighbor(idA, world_x, world_y,  1, -1));
+  tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
+  tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
+  if (cellA_list.FindPtr(&cellB)  == NULL) cellA_list.Push(&cellB);
+  if (cellA_list.FindPtr(&cellB0) == NULL) cellA_list.Push(&cellB0);
+  if (cellA_list.FindPtr(&cellB1) == NULL) cellA_list.Push(&cellB1);
+  if (cellB_list.FindPtr(&cellA)  == NULL) cellB_list.Push(&cellA);
+  if (cellB_list.FindPtr(&cellA0) == NULL) cellB_list.Push(&cellA0);
+  if (cellB_list.FindPtr(&cellA1) == NULL) cellB_list.Push(&cellA1);
 }
 
 connect_cells
Index: avida/current/source/event/cPopulation_enums_auto.ci
diff -u avida/current/source/event/cPopulation_enums_auto.ci:1.7 avida/current/source/event/cPopulation_enums_auto.ci:1.8
--- avida/current/source/event/cPopulation_enums_auto.ci:1.7	Sun Oct 12 13:07:50 2003
+++ avida/current/source/event/cPopulation_enums_auto.ci	Wed Dec 10 13:56:56 2003
@@ -85,6 +85,9 @@
   EVENT_dump_genotype_grid,
   EVENT_print_tree_depths,
   EVENT_sever_grid_col,
+  EVENT_sever_grid_row,
+  EVENT_join_grid_col,
+  EVENT_join_grid_row,
   EVENT_connect_cells,
   EVENT_disconnect_cells,
   EVENT_inject_resource,
Index: avida/current/source/main/analyze.cc
diff -u avida/current/source/main/analyze.cc:1.88 avida/current/source/main/analyze.cc:1.89
--- avida/current/source/main/analyze.cc:1.88	Fri Dec  5 13:39:22 2003
+++ avida/current/source/main/analyze.cc	Wed Dec 10 13:56:57 2003
@@ -2843,7 +2843,7 @@
 void cAnalyze::WriteInjectEvents(cString cur_string)
 {
   // Load in the variables...
-  cString filename("clone.dat");
+  cString filename("events_inj.cfg");
   int start_cell = 0;
   int lineage = 0;
   if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
@@ -2872,6 +2872,109 @@
 }
 
 
+void cAnalyze::WriteCompetition(cString cur_string)
+{
+  cout << "Writing Competition events..." << endl;
+
+  // Load in the variables...
+  int join_UD = 0;
+  double start_merit = 50000;
+  cString filename("events_comp.cfg");
+  int batch_A = cur_batch - 1;
+  int batch_B = cur_batch;
+  int grid_side = -1;
+  int lineage = 0;
+
+  // Make sure we have reasonable default batches.
+  if (cur_batch == 0) { batch_A = 0; batch_B = 1; }
+
+  if (cur_string.GetSize() != 0) join_UD = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) start_merit = cur_string.PopWord().AsDouble();
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  if (cur_string.GetSize() != 0) batch_A = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) batch_B = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) grid_side = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) lineage = cur_string.PopWord().AsInt();
+
+  // Check inputs...
+  if (join_UD < 0) join_UD = 0;
+  if (batch_A < 0 || batch_B < 0) {
+    cerr << "Error: Batch IDs must be positive!" << endl;
+    return;
+  }
+  
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+
+  // Count the number of organisms in each batch...
+  cAnalyzeGenotype * genotype = NULL;
+
+  int org_count_A = 0;
+  tListIterator<cAnalyzeGenotype> batchA_it(batch[batch_A].List());
+  while ((genotype = batchA_it.Next()) != NULL) {
+    org_count_A += genotype->GetNumCPUs();
+  }
+
+  int org_count_B = 0;
+  tListIterator<cAnalyzeGenotype> batchB_it(batch[batch_B].List());
+  while ((genotype = batchB_it.Next()) != NULL) {
+    org_count_B += genotype->GetNumCPUs();
+  }
+
+  int max_count = Max(org_count_A, org_count_B);
+  if (max_count > 10000) {
+    cout << "Warning: more than 10,000 organisms in sub-population!" << endl;
+  }
+
+  if (grid_side <= 0) {
+    for (grid_side = 5; grid_side < 100; grid_side += 5) {
+      if (grid_side * grid_side >= max_count) break;
+    }
+    if (verbose == true) {
+      cout << "...assuming population size "
+	   << grid_side << "x" << grid_side << "." << endl;
+    }
+  }
+
+
+  int pop_size = grid_side * grid_side;
+
+  int inject_pos = 0;
+  while ((genotype = batchA_it.Next()) != NULL) {
+    const int cur_count = genotype->GetNumCPUs();
+    const cGenome & genome = genotype->GetGenome();
+    double cur_merit = start_merit;
+    if (cur_merit < 0) cur_merit = genotype->GetMerit();
+    fp << "u 0 inject_sequence "
+       << genome.AsString() << " "
+       << inject_pos << " "
+       << inject_pos + cur_count << " "
+       << cur_merit << " "
+       << lineage << " "
+       << endl;
+    inject_pos += cur_count;
+  }
+
+  inject_pos = pop_size;
+  while ((genotype = batchB_it.Next()) != NULL) {
+    const int cur_count = genotype->GetNumCPUs();
+    const cGenome & genome = genotype->GetGenome();
+    double cur_merit = start_merit;
+    if (cur_merit < 0) cur_merit = genotype->GetMerit();
+    fp << "u 0 inject_sequence "
+       << genome.AsString() << " "
+       << inject_pos << " "
+       << inject_pos + cur_count << " "
+       << cur_merit << " "
+       << lineage+1 << " "
+       << endl;
+    inject_pos += cur_count;
+  }
+
+  fp << "u 0 sever_grid_row" << grid_side << endl;
+  fp << "u " << join_UD << " join_grid_row " << grid_side << endl;
+}
+
+
 void cAnalyze::AnalyzeMuts(cString cur_string)
 {
   cout << "Analyzing Mutations" << endl;
@@ -4407,6 +4510,7 @@
   // Build input files for avida...
   AddLibraryDef("WRITE_CLONE", &cAnalyze::WriteClone);
   AddLibraryDef("WRITE_INJECT_EVENTS", &cAnalyze::WriteInjectEvents);
+  AddLibraryDef("WRITE_COMPETITION", &cAnalyze::WriteCompetition);
 
   // Automated analysis
   AddLibraryDef("ANALYZE_MUTS", &cAnalyze::AnalyzeMuts);
Index: avida/current/source/main/analyze.hh
diff -u avida/current/source/main/analyze.hh:1.51 avida/current/source/main/analyze.hh:1.52
--- avida/current/source/main/analyze.hh:1.51	Fri Dec  5 13:39:23 2003
+++ avida/current/source/main/analyze.hh	Wed Dec 10 13:56:57 2003
@@ -152,6 +152,7 @@
   // Build Input Files for Avida
   void WriteClone(cString cur_string);
   void WriteInjectEvents(cString cur_string);
+  void WriteCompetition(cString cur_string);
 
   // Automated analysis...
   void AnalyzeMuts(cString cur_string);
Index: avida/current/source/main/config.cc
diff -u avida/current/source/main/config.cc:1.66 avida/current/source/main/config.cc:1.67
--- avida/current/source/main/config.cc:1.66	Fri Dec  5 13:39:23 2003
+++ avida/current/source/main/config.cc	Wed Dec 10 13:56:57 2003
@@ -72,6 +72,7 @@
 int cConfig::num_resources;
 int cConfig::slicing_method;
 int cConfig::birth_method;
+int cConfig::prefer_empty;
 int cConfig::death_method;
 int cConfig::alloc_method;
 int cConfig::divide_method;
@@ -162,6 +163,8 @@
   
   repro_group->Add(birth_method, "4", "BIRTH_METHOD",
 		   "0 = Replace random organism in neighborhood\n1 = Replace oldest organism in neighborhood\n2 = Replace largest Age/Merit in neighborhood\n3 = Place only in empty cells in neighborhood\n4 = Replace random from population (Mass Action)\n5 = Replace oldest in entire population (like Tierra)");
+  repro_group->Add(prefer_empty, "1", "PREFER_EMPTY",
+		   "Are empty cells given preference in offsping placement?");
   repro_group->Add(death_method, "0", "DEATH_METHOD",
 		   "0 = Never die of old age.\n1 = Die when inst executed = AGE_LIMIT (+deviation)\n2 = Die when inst executed = length*AGE_LIMIT (+dev)");
   repro_group->Add(age_limit, "5000", "AGE_LIMIT",
Index: avida/current/source/main/config.hh
diff -u avida/current/source/main/config.hh:1.59 avida/current/source/main/config.hh:1.60
--- avida/current/source/main/config.hh:1.59	Fri Dec  5 13:39:23 2003
+++ avida/current/source/main/config.hh	Wed Dec 10 13:56:57 2003
@@ -219,6 +219,7 @@
   // Methodology
   static int slicing_method;
   static int birth_method;
+  static int prefer_empty;
   static int death_method;
   static int alloc_method;
   static int divide_method;
@@ -340,6 +341,7 @@
 
   static int GetSlicingMethod() { return slicing_method; }
   static int GetBirthMethod() { return birth_method; }
+  static int GetPreferEmpty() { return prefer_empty; }
   static int GetDeathMethod() { return death_method; }
   static int GetAllocMethod() { return alloc_method; }
   static int GetDivideMethod() { return divide_method; }
@@ -434,6 +436,8 @@
 
   static void SetBirthMethod(int in_birth_method)
     { birth_method = in_birth_method; }
+  static void SetPreferEmpty(int in_prefer_empty)
+    { prefer_empty = in_prefer_empty; }
   static void SetDeathMethod(int in_death_method)
     { death_method = in_death_method; }
   static void SetAllocMethod(int in_alloc_method)
Index: avida/current/source/main/population.cc
diff -u avida/current/source/main/population.cc:1.122 avida/current/source/main/population.cc:1.123
--- avida/current/source/main/population.cc:1.122	Tue Nov 25 09:37:57 2003
+++ avida/current/source/main/population.cc	Wed Dec 10 13:56:57 2003
@@ -725,7 +725,7 @@
     }
   }
 
-  // If there are no possibilities, return NULL.
+  // If there are no possibilities, return parent.
   if (found_list.GetSize() == 0) return parent_cell;
 
   // Choose the organism randomly from those in the list, and return it.
Index: avida/current/source/support/genesis
diff -u avida/current/source/support/genesis:1.44 avida/current/source/support/genesis:1.45
--- avida/current/source/support/genesis:1.44	Wed Oct 15 17:45:16 2003
+++ avida/current/source/support/genesis	Wed Dec 10 13:56:57 2003
@@ -35,6 +35,7 @@
 		  # 3 = Place only in empty cells in neighborhood
 		  # 4 = Replace random from entire population (Mass Action)
 		  # 5 = Replace oldest in entire population (like Tierra)
+PREFER_EMPTY 1    # Are empty cells given preference in offspring placement?
 DEATH_METHOD 0    # 0 = Never die of old age.
 		  # 1 = Die when inst executed = AGE_LIMIT (with deviation)
 		  # 2 = Die when inst executed = length * AGE_LIMIT (+ dev.)
Index: avida/current/source/tools/tList.hh
diff -u avida/current/source/tools/tList.hh:1.11 avida/current/source/tools/tList.hh:1.12
--- avida/current/source/tools/tList.hh:1.11	Tue Nov 25 09:38:01 2003
+++ avida/current/source/tools/tList.hh	Wed Dec 10 13:56:57 2003
@@ -238,10 +238,21 @@
     while (other_it.Next() != NULL) PushRear(other_it.Get());
   }
 
+  // Find by value
   T * Find(T * _in) const {
     tListNode<T> * test = root.next;
     while (test != &root) {
       if ( *(test->data) == *(_in) ) return test->data;
+      test = test->next;
+    }
+    return NULL;
+  }
+
+  // Find by Pointer
+  T * FindPtr(T * _in) const {
+    tListNode<T> * test = root.next;
+    while (test != &root) {
+      if ( test->data == _in ) return test->data;
       test = test->next;
     }
     return NULL;


More information about the Avida-cvs mailing list