[avida-cvs] avida(kaben) CVS commits: /current/source/event cPopulation.events /current/source/main analyze.cc analyze.hh config.cc config.hh population.cc /current/source/support genesis /current/source/tools tList.hh
kaben
avida-cvs at alife.org
Mon Dec 22 18:43:19 PST 2003
kaben Mon Dec 22 10:43:19 2003 EDT
Modified files: (Branch: kaben)
/avida/current/source/event cPopulation.events
/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:
Sync with cvs commit on branch HEAD by mercere99 Wed Dec 10 13:56:57 2003 EDT
-------------- next part --------------
Index: avida/current/source/event/cPopulation.events
diff -u avida/current/source/event/cPopulation.events:1.49.2.1 avida/current/source/event/cPopulation.events:1.49.2.2
--- avida/current/source/event/cPopulation.events:1.49.2.1 Mon Dec 15 10:05:43 2003
+++ avida/current/source/event/cPopulation.events Mon Dec 22 10:43:17 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/main/analyze.cc
diff -u avida/current/source/main/analyze.cc:1.89.2.1 avida/current/source/main/analyze.cc:1.89.2.2
--- avida/current/source/main/analyze.cc:1.89.2.1 Mon Dec 15 10:05:43 2003
+++ avida/current/source/main/analyze.cc Mon Dec 22 10:43:18 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.52.2.1 avida/current/source/main/analyze.hh:1.52.2.2
--- avida/current/source/main/analyze.hh:1.52.2.1 Mon Dec 15 10:05:44 2003
+++ avida/current/source/main/analyze.hh Mon Dec 22 10:43:18 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.68.2.1 avida/current/source/main/config.cc:1.68.2.2
--- avida/current/source/main/config.cc:1.68.2.1 Mon Dec 15 10:05:44 2003
+++ avida/current/source/main/config.cc Mon Dec 22 10:43:18 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.61.2.2 avida/current/source/main/config.hh:1.61.2.3
--- avida/current/source/main/config.hh:1.61.2.2 Tue Dec 16 14:37:14 2003
+++ avida/current/source/main/config.hh Mon Dec 22 10:43:18 2003
@@ -222,6 +222,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;
@@ -343,6 +344,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; }
@@ -437,6 +439,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.124.2.1 avida/current/source/main/population.cc:1.124.2.2
--- avida/current/source/main/population.cc:1.124.2.1 Mon Dec 15 10:05:44 2003
+++ avida/current/source/main/population.cc Mon Dec 22 10:43:18 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.45.2.1 avida/current/source/support/genesis:1.45.2.2
--- avida/current/source/support/genesis:1.45.2.1 Mon Dec 15 10:05:48 2003
+++ avida/current/source/support/genesis Mon Dec 22 10:43:18 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.12.2.1 avida/current/source/tools/tList.hh:1.12.2.2
--- avida/current/source/tools/tList.hh:1.12.2.1 Mon Dec 15 10:05:49 2003
+++ avida/current/source/tools/tList.hh Mon Dec 22 10:43:18 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