[avida-cvs] avida(kaben) CVS commits: /current NEWS configure.in /current/doc analyze_mode.html /current/source defs.hh /current/source/cpu hardware_cpu.cc hardware_cpu.hh /current/source/event cPopulation.events cPopulation_construct_event_auto.ci cPopulation_descr.ci cPopulation_descr.hi cPopulation_enums_auto.ci cPopulation_event_list cPopulation_name2enum_auto.ci cPopulation_process_auto.ci /current/source/main Makefile.am analyze.cc analyze.hh avida.cc birth_chamber.cc birth_chamber.hh callback_util.cc callback_util.hh config.cc config.hh environment.cc environment.hh inst_set.cc organism.hh pop_interface.cc pop_interface.hh population.cc population.hh reaction.cc reaction.hh /current/source/main/functional_testsuites/tedious.tail genesis /current/source/qt-viewer avd_instruction_viewer_controller.cc /current/source/support genesis /current/source/tools functions.hh stat.hh

kaben avida-cvs at alife.org
Thu Oct 16 15:18:23 PDT 2003


kaben		Thu Oct 16 07:18:23 2003 EDT

  Removed files:               (Branch: kaben)
    /avida/current/source/event	cPopulation_construct_event_auto.ci 
                               	cPopulation_descr.ci 
                               	cPopulation_descr.hi 
                               	cPopulation_enums_auto.ci 
                               	cPopulation_name2enum_auto.ci 
                               	cPopulation_process_auto.ci 

  Modified files:              
    /avida/current	NEWS configure.in 
    /avida/current/doc	analyze_mode.html 
    /avida/current/source	defs.hh 
    /avida/current/source/cpu	hardware_cpu.cc hardware_cpu.hh 
    /avida/current/source/event	cPopulation.events 
                               	cPopulation_event_list 
    /avida/current/source/main	Makefile.am analyze.cc analyze.hh 
                              	avida.cc birth_chamber.cc 
                              	birth_chamber.hh callback_util.cc 
                              	callback_util.hh config.cc config.hh 
                              	environment.cc environment.hh 
                              	inst_set.cc organism.hh pop_interface.cc 
                              	pop_interface.hh population.cc 
                              	population.hh reaction.cc reaction.hh 
    /avida/current/source/main/functional_testsuites/tedious.tail	
                                                                 	genesis 
    /avida/current/source/qt-viewer	
                                   	avd_instruction_viewer_controller.cc 
    /avida/current/source/support	genesis 
    /avida/current/source/tools	functions.hh stat.hh 
  Log:
  
  Merge of branch HEAD into branch kaben.
  
  
  
-------------- next part --------------
Index: avida/current/NEWS
diff -u avida/current/NEWS:1.22.2.3 avida/current/NEWS:1.22.2.4
--- avida/current/NEWS:1.22.2.3	Tue Sep 23 19:58:53 2003
+++ avida/current/NEWS	Thu Oct 16 07:18:19 2003
@@ -4,6 +4,53 @@
 [B] = Bug fix; something that used to work wrong will now be correct.
 [M] = Major change; avida will function differently in certain circumstances.
 
+For version 2.0 beta 7:
+
+October, 03
+[F] Implemented proportional merit with sex...
+
+[F] Setup environment file with an extra command:
+
+      SET_ACTIVE <type> <name> <active=true>
+
+    Type can currently only be "reaction" (but soon I'll also get resources
+    working, and eventually mutations).  Name is the name of the resource,
+    and fitnally a true or false if you want that reaction turned on.
+  
+    THEN I also added a command to the analyze mode called "ENVIRONMENT"
+    which will allow you to add extra commands to define the environment
+    file on the fly.  For example, the analyze command:
+  
+      ENVIRONMENT SET_ACTIVE reaction NOT false
+  
+    Will turn off rewards for not.  They can be turned back on again
+    trivially with:
+  
+      ENVIRONMENT SET_ACTIVE reaction NOT true
+
+[B] Made changes to arrays in analyze mode so that they use tArray and
+    tMatrix to make them easier to use with variable sizes.
+
+[F] Added new functions "AnalyzeComplexity" and "AnalyzePopComplexity"
+    to analyze source code.
+
+[F] 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.
+
+[F] Added some info about the new AVERAGE_MODULARITY analyze command to
+    the documentation files.
+
+[F] After much tweaking, implemented a new analyze function,
+    AVERAGE_MODULARITY.
+    Usage:
+    AVERAGE_MODULARITY output_file task.0 task.1 task.2 task.3 task.4 task.5 task.6 task.7 task.8
+
+[B] Fixed the formula used to calculate Standard Error in various
+    statistics parameters.
+
+
 For version 2.0 beta 6:
 
 September, 03
Index: avida/current/configure.in
diff -u avida/current/configure.in:1.22.2.11 avida/current/configure.in:1.22.2.12
--- avida/current/configure.in:1.22.2.11	Fri Oct  3 13:46:44 2003
+++ avida/current/configure.in	Thu Oct 16 07:18:20 2003
@@ -8,7 +8,7 @@
 dnl ****************************************
 dnl        Package name and version
 dnl ****************************************
-AM_INIT_AUTOMAKE(avida, 2.0b6)
+AM_INIT_AUTOMAKE(avida, 2.0b7)
 
 
 dnl ****************************************
@@ -199,7 +199,6 @@
   source/event/Makefile source/viewers/Makefile
   source/main/Makefile
   source/main/functional_testsuites/Makefile
-  source/main/unit_testsuites/Makefile
   source/support/Makefile
   source/support/preset_organisms/Makefile
   source/qt-viewer/Makefile
Index: avida/current/doc/analyze_mode.html
diff -u avida/current/doc/analyze_mode.html:1.2.2.1 avida/current/doc/analyze_mode.html:1.2.2.2
--- avida/current/doc/analyze_mode.html:1.2.2.1	Thu May 29 11:47:48 2003
+++ avida/current/doc/analyze_mode.html	Thu Oct 16 07:18:20 2003
@@ -234,6 +234,15 @@
         The cells in the chart indicate the fitness were a mutation to
         occur at the position in the matrix, to the listed instruction.
         If the "html" flag is used, the charts will be output in HTML format.
+<tr><td><b>AVERAGE_MODULATITY [<font color="#008800">file="modularity.dat"</font>]
+	[<font color="#008800">task.0 task.1 task.2 task.3 task.4 task.5      
+	task.6 task.7 task.8</font>] </b><br>
+    	Calculate several modularity measuers, such as how many tasks is an 
+	instruction involved in, number of sites required for each task, etc.
+	The measures are averaged over all the organisms in the current batch 
+	that perform any tasks. For the full output list, do 
+	"AVERAGE_MODULATITY legend.dat" At the moment doesn't support html
+	output format and works with only 1 and 2 input tasks. 
 <tr><td><b>HAMMING [<font color="#008800">file="hamming.dat"</font>]
 	[<font color="#008800">b1=current</font>]
 	[<font color="#008800">b2=b1</font>] </b><br>
@@ -375,4 +384,4 @@
 <br><hr>
 Project hosted by:<br>
 <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=46761&type=2" width="125" height="37" border="0" alt="SourceForge.net"/></a>
-    
\ No newline at end of file
+    
Index: avida/current/source/defs.hh
diff -u avida/current/source/defs.hh:1.25.2.8 avida/current/source/defs.hh:1.25.2.9
--- avida/current/source/defs.hh:1.25.2.8	Thu Oct  2 17:04:37 2003
+++ avida/current/source/defs.hh	Thu Oct 16 07:18:20 2003
@@ -75,7 +75,7 @@
 // the macro VERSION is defined by automake (in the file 'configure.in' in
 // the top-level directory).
 #ifndef VERSION
- #define VERSION "2.0b6"
+ #define VERSION "2.0b7"
 #endif
 #define AVIDA_VERSION VERSION
 
Index: avida/current/source/cpu/hardware_cpu.cc
diff -u avida/current/source/cpu/hardware_cpu.cc:1.34.2.11 avida/current/source/cpu/hardware_cpu.cc:1.34.2.12
--- avida/current/source/cpu/hardware_cpu.cc:1.34.2.11	Fri Oct 10 19:45:53 2003
+++ avida/current/source/cpu/hardware_cpu.cc	Thu Oct 16 07:18:20 2003
@@ -18,9 +18,11 @@
 #include "../main/genome_util.hh"
 #include "../main/organism.hh"
 #include "../main/phenotype.hh"
+#include "../main/genotype.hh"
 
 #include "test_cpu.hh"
 #include <limits.h>
+#include <fstream>
 
 
 using namespace std;
@@ -491,6 +493,9 @@
     cInstEntryCPU("repro-Y",    &cHardwareCPU::Inst_Repro),
     cInstEntryCPU("repro-Z",    &cHardwareCPU::Inst_Repro),
 
+	// Jeff and Sherri
+	cInstEntryCPU("kazi",		&cHardwareCPU::Inst_Kazi),
+
     // Placebo instructions
     // nop-x (included with nops)
     cInstEntryCPU("skip",      &cHardwareCPU::Inst_Skip)
@@ -2722,6 +2727,23 @@
   return true;
 }
 
+
+bool cHardwareCPU::Inst_Kazi()
+{
+	const int reg_used = FindModifiedRegister(REG_AX);
+	int percentProb = Register(reg_used) % 100;
+	int random = abs(rand()) % 100;
+	if (random >= percentProb)
+	{
+		return true;
+	}
+	else
+	{
+		organism->Kaboom();
+		return true;
+	}
+}
+
 // The inject instruction can be used instead of a divide command, paired
 // with an allocate.  Note that for an inject to work, one needs to have a
 // broad range for sizes allowed to be allocated.
@@ -3125,7 +3147,7 @@
 
 bool cHardwareCPU::Inst_HeadDivideAsexWait()  
 { 
-  organism->GetPhenotype().SetDivideSex(true);
+  organism->GetPhenotype().SetDivideSex(false);
   organism->GetPhenotype().SetCrossNum(0);
   return Inst_HeadDivide(); 
 }
Index: avida/current/source/cpu/hardware_cpu.hh
diff -u avida/current/source/cpu/hardware_cpu.hh:1.19.2.6 avida/current/source/cpu/hardware_cpu.hh:1.19.2.7
--- avida/current/source/cpu/hardware_cpu.hh:1.19.2.6	Thu Oct  2 17:04:37 2003
+++ avida/current/source/cpu/hardware_cpu.hh	Thu Oct 16 07:18:20 2003
@@ -8,6 +8,7 @@
 #ifndef HARDWARE_CPU_HH
 #define HARDWARE_CPU_HH
 
+#include <vector>
 #include "hardware_base.hh"
 
 #include "../defs.hh"
@@ -20,6 +21,7 @@
 #include "cpu_defs.hh"
 #include "label.hh"
 #include "head.hh"
+using namespace std;
 
 class cInstSet;
 class cInstLibBase;
@@ -367,6 +369,7 @@
   bool Inst_InjectRand();
   bool Inst_InjectThread();
   bool Inst_Repro();
+  bool Inst_Kazi();
 
   // I/O and Sensory
   bool Inst_TaskGet();
Index: avida/current/source/event/cPopulation.events
diff -u avida/current/source/event/cPopulation.events:1.36.2.7 avida/current/source/event/cPopulation.events:1.36.2.8
--- avida/current/source/event/cPopulation.events:1.36.2.7	Thu Oct  2 17:04:38 2003
+++ avida/current/source/event/cPopulation.events	Thu Oct 16 07:18:20 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_event_list
diff -u avida/current/source/event/cPopulation_event_list:1.4.2.3 avida/current/source/event/cPopulation_event_list:1.4.2.4
--- avida/current/source/event/cPopulation_event_list:1.4.2.3	Thu Oct  2 17:04:38 2003
+++ avida/current/source/event/cPopulation_event_list	Thu Oct 16 07:18:21 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/main/Makefile.am
diff -u avida/current/source/main/Makefile.am:1.24.2.14 avida/current/source/main/Makefile.am:1.24.2.15
--- avida/current/source/main/Makefile.am:1.24.2.14	Mon Oct 13 10:24:07 2003
+++ avida/current/source/main/Makefile.am	Thu Oct 16 07:18:21 2003
@@ -16,9 +16,9 @@
 #
 # don't know why it was needed.
 #
-AVIDA_EVENT_DIR = $(srcdir)/../event
-AVIDA_CPU_DIR = $(srcdir)/../cpu
-INCLUDES = -I$(AVIDA_EVENT_DIR) -I$(AVIDA_CPU_DIR)
+AVIDA_EVENT_DIR = -I$(srcdir)/../event -I../event
+AVIDA_CPU_DIR = -I$(srcdir)/../cpu
+INCLUDES = $(AVIDA_EVENT_DIR) $(AVIDA_CPU_DIR)
 #
 
 libmain_a_SOURCES = analyze.hh		analyze.cc		\
@@ -77,6 +77,7 @@
 EXTRA_DIST = main.pro main_sub.pri
 
 if DEJAGNU_REGRESSION_TESTS
+# Disabled unit_testsuite until I can try it out on our beowulf.
 #SUBDIRS = . unit_testsuites functional_testsuites
 SUBDIRS = . functional_testsuites
 endif
Index: avida/current/source/main/analyze.cc
diff -u avida/current/source/main/analyze.cc:1.63.2.7 avida/current/source/main/analyze.cc:1.63.2.8
--- avida/current/source/main/analyze.cc:1.63.2.7	Mon Aug 25 23:30:22 2003
+++ avida/current/source/main/analyze.cc	Thu Oct 16 07:18:21 2003
@@ -1898,6 +1898,306 @@
   }
 }
 
+void cAnalyze::CommandAverageModularity(cString cur_string)
+{
+  cout << "Average Modularity calculations" << endl;
+
+  // Load in the variables...
+  cString filename = cur_string.PopWord();
+//    cString filename = "average.dat";
+
+  int print_mode = 0;   // 0=Normal, 1=Boolean results
+
+  // Collect any other format information needed...
+  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
+  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
+
+  cStringList arg_list(cur_string);
+
+  cout << "Found " << arg_list.GetSize() << " args." << endl;
+
+  // Check for some command specific variables.
+  if (arg_list.PopString("0") != "") print_mode = 0;
+  if (arg_list.PopString("1") != "") print_mode = 1;
+
+  cout << "There are " << arg_list.GetSize() << " column args." << endl;
+
+  LoadGenotypeDataList(arg_list, output_list);
+
+  cout << "Args are loaded." << endl;
+
+  const int num_cols = output_list.GetSize();
+
+  // Give some information in verbose mode.
+  if (verbose == true) {
+    cout << "  outputing as ";
+    if (print_mode == 1) cout << "boolean ";
+      cout << "text files." << endl;
+    cout << "  Format: ";
+
+    output_it.Reset();
+    while (output_it.Next() != NULL) {
+      cout << output_it.Get()->GetName() << " ";
+    }
+    cout << endl;
+  }
+
+    ofstream & fp = data_file_manager.GetOFStream(filename);
+
+  // printing the headers
+  // not done by default since many dumps may be analyzed at the same time
+  // and results would be put in the same file
+  if (arg_list.GetSize()==0) {
+    // Headers
+    fp << "# Avida analyze modularity data" << endl;
+    fp << "# 1: organism length" << endl;
+    fp << "# 2: number of tasks done" << endl;
+    fp << "# 3: number of sites used in tasks" << endl;
+    fp << "# 4: proportion of sites used in tasks" << endl;
+    fp << "# 5: average number of tasks done per site" << endl;
+    fp << "# 6: average number sites per task done" << endl;
+    fp << "# 7: average number tasks per site per task" << endl;
+    fp << "# 8-16: average StDev in positions used for task 1-9" << endl;
+    fp << "# 17-25: average number of sites necessary for each of the tasks" << endl;
+    fp << "# 26-35: number of sites involved in 0-9 tasks" << endl;
+    fp << endl;
+    return;
+}        
+
+  // initialize various variables used in calculations
+
+    int num_orgs = 0;		// number of organisms in the dump
+
+    double  av_length = 0; 	// average organism length
+    double  av_task = 0; 	// average # of tasks done
+    double  av_inst = 0; 	// average # instructions used in tasks
+    double  av_inst_len = 0; 	// proportion of sites used for tasks
+    double  av_site_task = 0; 	// average number of sites per task
+    double  av_task_site = 0;   // average number of tasks per site
+    double  av_t_s_norm = 0;	// average number of tasks per site per task
+
+    // average StDev in positions used for a task
+    tArray<double> std_task_position(num_cols);
+    
+    // # of organisms actually doing a task
+    tArray<double> org_task(num_cols);
+
+    // av. # of sites necessary for each of the tasks
+    tArray<double> av_num_inst(num_cols);
+    
+    // number of sites involved in 0-9 tasks 
+    tArray<double> av_inst_task(num_cols+1);
+
+    for (int i = 0; i < num_cols; i++) {
+      av_num_inst[i] = 0;
+      org_task[i] = 0; 
+      std_task_position[i] = 0;
+    }
+
+    for (int i = 0; i < num_cols+1; i++) {
+      av_inst_task[i] = 0;
+    }
+
+    
+  ///////////////////////////////////////////////////////
+  // Loop through all of the genotypes in this batch...
+  ///////////////////////////////////////////////////////
+
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+
+  // would like to test oly the viable ones, but they can be non-viable
+  // and still reproduce and do tasks
+  // while ((genotype = batch_it.Next()) != NULL && genotype->GetViable()) {
+  while ((genotype = batch_it.Next()) != NULL) {
+
+    int num_cpus = genotype->GetNumCPUs();
+
+    if (verbose == true) cout << "  Mapping " << genotype->GetName() << endl;
+ 
+    // Calculate the stats for the genotype we're working with...
+    genotype->Recalculate();
+
+    // Check if the organism does any tasks. 
+    int does_tasks = 0;
+    for (int i = 0; i < num_cols; i++) {
+      if (genotype->GetTaskCount(i) > 0)  does_tasks = 1;
+    }
+
+   // Don't calculate the modularity if the organism doesn't reproduce
+   // i.e. if the fitness is 0 
+   if (genotype->GetFitness() != 0 && does_tasks != 0) {
+    num_orgs = num_orgs + num_cpus;
+
+    const int max_line = genotype->GetLength();
+    const cGenome & base_genome = genotype->GetGenome();
+    cGenome mod_genome(base_genome);
+
+    // Create and initialize the modularity matrix
+    tMatrix<int> mod_matrix(num_cols, max_line);
+    for (int i = 0; i < num_cols; i++) {
+        for (int j = 0; j < max_line; j++) {
+      	    mod_matrix(i,j) = 0;
+	}
+    } 
+
+    // Create an initialize the counters for modularity
+    tArray<int> num_task(max_line); // number of tasks instruction is used in
+    tArray<int> num_inst(num_cols); // number of instructions involved in a task
+    tArray<int> sum(num_cols); 	    // helps with StDev calculations
+    tArray<int> sumsq(num_cols);    // helps with StDev calculations
+    tArray<int> inst_task(num_cols+1); // # of inst's involved in 0,1,2,3... tasks
+
+    for (int i = 0; i < num_cols; i++) {
+      num_inst[i] = 0;
+      sum[i] = 0;
+      sumsq[i] = 0; 		
+    }
+    for (int i = 0; i < num_cols+1; i++) {
+      inst_task[i] = 0;		
+    }
+    for (int i = 0; i < max_line; i++) {
+      num_task[i] = 0;		
+    }
+
+    int total_task = 0; // total number of tasks done
+    int total_inst = 0; // total number of instructions involved in tasks
+    int total_all = 0;  // sum of mod_matrix
+
+    cInstSet map_inst_set(inst_set);
+
+    // Locate instruction corresponding to "NULL" in the instruction library.
+    {
+      const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("NULL");
+      if(inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
+        cout << "<cAnalyze::CommandMapTasks> got error:" << endl;
+        cout << " --- instruction \"NULL\" isn't in the instruction library;" << endl;
+        cout << " --- get somebody to map a function to \"NULL\" in the library." << endl;
+        cout << " --- (probably to class method \"cHardware-of-some-type::initInstLib\"" << endl;
+        cout << " --- in file named \"cpu/hardware-of-some-type.cc\".)" << endl;
+        cout << " --- bailing-out." << endl;
+        exit(1);
+      }
+      // Add mapping to located instruction. 
+      map_inst_set.Add2(inst_lib_null_inst.GetOp());
+    }
+    const cInstruction null_inst = map_inst_set.GetInst("NULL");
+
+    // Loop through all the lines of code, testing the removal of each.
+    for (int line_num = 0; line_num < max_line; line_num++) {
+      int cur_inst = base_genome[line_num].GetOp();
+      char cur_symbol = base_genome[line_num].GetSymbol();
+
+      mod_genome[line_num] = null_inst;
+      cAnalyzeGenotype test_genotype(mod_genome, map_inst_set);
+      test_genotype.Recalculate();
+
+      // Print the individual columns...
+      output_it.Reset();
+      tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+      int cur_col = 0;
+      while ((data_command = output_it.Next()) != NULL) {
+	data_command->SetTarget(&test_genotype);
+	test_genotype.SetSpecialArgs(data_command->GetArgs());
+	int compare = data_command->Compare(genotype);
+
+	// If knocking out an instruction stops the expression of a
+	// particular task, mark that in the modularity matrix
+	// and add it to two counts
+	// Only do the checking if the test_genotype replicate, i.e.
+	// if it's fitness is not zeros
+
+	if (compare == -2 && test_genotype.GetFitness() != 0) { 
+		mod_matrix(cur_col,line_num) = 1;
+		num_inst[cur_col]++;
+		num_task[line_num]++;
+	}
+	cur_col++;
+      }
+
+      // Reset the mod_genome back to the original sequence.
+      mod_genome[line_num].SetOp(cur_inst);
+    }
+    
+    for (int i = 0; i < num_cols; i++) {if (num_inst[i] != 0) total_task++;}
+    for (int i = 0; i < max_line; i++) {if (num_task[i] != 0) total_inst++;}
+    for (int i = 0; i < num_cols; i++) {total_all = total_all + num_inst[i];}
+
+    // Add the values to the av_ variables, used for calculating the average
+    // in order to weigh them by abundance, multiply everything by num_cpus
+
+    av_length = av_length + max_line*num_cpus;
+    av_task = av_task + total_task*num_cpus;
+    av_inst = av_inst + total_inst*num_cpus;
+    av_inst_len = av_inst_len + (double) total_inst*num_cpus/max_line;
+
+    if (total_task !=0)  av_site_task = av_site_task + num_cpus * (double) total_all/total_task; 
+    if (total_inst !=0)  av_task_site = av_task_site + num_cpus * (double) total_all/total_inst; 
+    if (total_inst !=0 && total_task !=0) {
+	av_t_s_norm = av_t_s_norm + num_cpus * (double) total_all/(total_inst*total_task); 
+    }
+
+    for (int i = 0; i < num_cols; i++) { 
+	if (num_inst[i] > 0) {
+		av_num_inst[i] = av_num_inst[i] + num_inst[i] * num_cpus;
+		org_task[i]++; 	// count how many are actually doing the task
+	}
+    }	
+
+    // calculate the Standard Deviation in the mean position of the task
+
+    for (int i = 0; i < num_cols; i++) { 
+	for (int j = 0; j < max_line; j++) { 
+		if (mod_matrix(i,j)>0) sum[i] = sum[i] + j;
+	}		
+    }
+
+    double temp = 0;
+    for (int i = 0; i < num_cols; i++) {
+	if (num_inst[i]>1) { 
+		double av_sum = sum[i]/num_inst[i];
+		for (int j = 0; j < max_line; j++) {
+			if (mod_matrix(i,j)>0) temp = (av_sum - j)*(av_sum - j);
+		}
+		std_task_position[i] = std_task_position[i] + sqrt(temp/(num_inst[i]-1))*num_cpus;
+	} 
+    } 
+
+    for (int i = 0; i < max_line; i++) { inst_task[num_task[i]]++ ;}
+    for (int i = 0; i < num_cols+1; i++) { av_inst_task[i] = av_inst_task[i] + inst_task[i] * num_cpus;}
+
+   }
+  }
+
+ // make sure there are some organisms doing task in this batch
+ // if not, return all zeros
+
+ if (num_orgs != 0) { 
+    fp << (double) av_length/num_orgs  << " ";  	// 1: average length
+    fp << (double) av_task/num_orgs << " ";		// 2: av. number of tasks done
+    fp << (double) av_inst/num_orgs << " ";		// 3: av. number of sites used for tasks
+    fp << (double) av_inst_len/num_orgs << " ";		// 4: proportion of sites used for tasks
+    fp << (double) av_task_site/num_orgs << " ";	// 5: av. number of tasks per site
+    fp << (double) av_site_task/num_orgs << " ";	// 6: av. number of sites per task
+    fp << (double) av_t_s_norm/num_orgs << " ";		// 7: av. number of tasks per site per task
+    for (int i = 0; i < num_cols; i++) {
+	if (org_task[i] > 0) fp << std_task_position[i]/org_task[i]  << " ";
+        else fp << 0 << " ";
+    }
+    for (int i = 0; i < num_cols; i++) { 
+	if (org_task[i] > 0) fp << (double) av_num_inst[i]/org_task[i]  << " ";
+        else fp << 0 << " ";
+    }
+    for (int i = 0; i < num_cols+1; i++) { fp << (double) av_inst_task[i]/num_orgs  << " ";}
+    fp << endl;
+    }
+
+ else {
+    for (int i = 0; i < 7+3*num_cols+1; i++) {fp << "0 ";}
+    fp << endl; 
+ }
+}
+
 
 void cAnalyze::CommandMapMutations(cString cur_string)
 {
@@ -2921,6 +3221,7 @@
   // Loop through all of the genotypes again, testing mutation reversions.
   cAnalyzeGenotype * prev_genotype = batch_it.Next();
   while ((genotype = batch_it.Next()) != NULL) {
+    continue;
     // Check to see if any sites have changed...
     for (int i = 0; i < size; i++) {
       if (genotype->GetGenome()[i] != prev_genotype->GetGenome()[i]) {
@@ -2963,6 +3264,187 @@
   }
 }
 
+void cAnalyze::AnalyzeComplexity(cString cur_string)
+{
+  cout << "Analyzing genome complexity..." << endl;
+  
+  // Load in the variables...
+  double mut_rate = cur_string.PopWord().AsDouble();
+  cString directory = PopDirectory(cur_string, "complexity/");
+  
+    
+  ///////////////////////////////////////////////////////
+  // Loop through all of the genotypes in this batch...
+
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+
+  bool islineage = false;
+  cString lineage_filename;
+  ofstream lineage_fp;
+  if (batch[cur_batch].IsLineage() == true) {
+    lineage_filename.Set("%scomplexity.%s.dat", directory(), "lineage");
+    lineage_fp.open(lineage_filename);
+    islineage = true;
+  }
+  while ((genotype = batch_it.Next()) != NULL) {
+    if (verbose == true) {
+      cout << "  Analyzing complexity for " << genotype->GetName() << endl;
+    }
+    
+    // Construct this filename...
+    cString filename;
+    filename.Set("%s%s.complexity.dat", directory(), genotype->GetName()());
+    ofstream fp(filename());
+    
+    // Calculate the stats for the genotype we're working with ...
+    genotype->Recalculate();
+    const int num_insts = inst_set.GetSize();
+    
+    const int max_line = genotype->GetLength();
+    const cGenome & base_genome = genotype->GetGenome();
+    cGenome mod_genome(base_genome);
+
+    // Loop through all the lines of code, testing all mutations...
+    tArray<double> test_fitness(num_insts);
+    tArray<double> prob(num_insts);
+    for (int line_num = 0; line_num < max_line; line_num++) {
+      int cur_inst = base_genome[line_num].GetOp();
+      //char cur_symbol = base_genome[line_num].GetSymbol();
+      
+      // Column 1 ... the original instruction in the genome.
+      fp << cur_inst << " ";
+      
+      // Test fitness of each mutant.
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
+        mod_genome[line_num].SetOp(mod_inst);
+        cAnalyzeGenotype test_genotype(mod_genome, inst_set);
+        test_genotype.Recalculate();
+        test_fitness[mod_inst] = test_genotype.GetFitness();
+      }
+
+      // Ajust fitness
+      double cur_inst_fitness = test_fitness[cur_inst];
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
+	if (test_fitness[mod_inst] > cur_inst_fitness)
+	  test_fitness[mod_inst] = cur_inst_fitness;
+        test_fitness[mod_inst] = test_fitness[mod_inst] / cur_inst_fitness;
+      }
+      
+      // Calculate probabilities at mut-sel balance
+      double w_bar = 1;
+
+      while(1) {
+        double sum = 0.0;
+        for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
+          prob[mod_inst] = (mut_rate * w_bar) / (num_insts * (w_bar + test_fitness[mod_inst] * mut_rate - test_fitness[mod_inst]));
+          sum = sum + prob[mod_inst];
+        }
+        if ((sum-1.0)*(sum-1.0) <= 0.0001) 
+	  break;
+        else
+          w_bar = w_bar - 0.000001;
+      }
+
+      // Write probability
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
+        fp << prob[mod_inst] << " ";
+      }
+
+      // Calculate complexity
+      double entropy = 0;
+      for (int i = 0; i < num_insts; i ++) {
+	entropy += prob[i] * log((double) 1.0/prob[i]) / log ((double) num_insts);
+      }
+      double complexity = 1 - entropy;
+      fp << complexity << endl;
+
+      if (islineage) {
+	lineage_fp << complexity << " ";
+      }
+
+      // Reset the mod_genome back to the original sequence.
+      mod_genome[line_num].SetOp(cur_inst);
+    }
+    fp.close();
+    lineage_fp << endl;
+  }
+  lineage_fp.close();
+        
+
+}
+
+void cAnalyze::AnalyzePopComplexity(cString cur_string)
+{
+  cout << "Analyzing population complexity ..." << endl;
+  
+  // Load in the variables...
+  cString directory = PopDirectory(cur_string, "complexity/");
+  cString file = cur_string;
+
+  // Construct filename ...
+  cString filename;
+  filename.Set("%spop%s.complexity.dat", directory(), file());
+  ofstream fp(filename());
+
+  //////////////////////////////////////////////////////////
+  // Loop through all of the genotypes in this batch ...
+
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+
+  genotype = batch_it.Next();
+  if (genotype == NULL) return;
+  int seq_length = genotype->GetLength();
+  const int num_insts = inst_set.GetSize();
+  tMatrix<int> inst_stat(seq_length, num_insts);
+  int pop_size = 0;
+
+  // Initializing inst_stat ...
+  for (int line_num = 0; line_num < seq_length; line_num ++) 
+    for (int inst_num = 0; inst_num < num_insts; inst_num ++) 
+      inst_stat(line_num, inst_num) = 0;
+
+  while (genotype != NULL) {
+    pop_size ++;
+    const cGenome & base_genome = genotype->GetGenome();
+    if (genotype->GetLength() != seq_length) { 
+      cout << genotype->GetName() << " " << genotype->GetLength() << endl;
+      genotype = batch_it.Next();
+      continue;
+    }
+    for (int line_num = 0; line_num < seq_length; line_num ++) {
+      int cur_inst = base_genome[line_num].GetOp();
+      inst_stat(line_num, cur_inst) ++;
+    }
+    genotype = batch_it.Next();
+  }
+
+  // Calculate complexity
+  for (int line_num = 0; line_num < seq_length; line_num ++) {
+    double entropy = 0.0;
+    for (int inst_num = 0; inst_num < num_insts; inst_num ++) {
+      if (inst_stat(line_num, inst_num) == 0) continue;
+      float prob = (float) (inst_stat(line_num, inst_num)) / (float) (pop_size);
+      entropy += prob * log((double) 1.0/prob) / log((double) num_insts);
+    }
+    double complexity = 1 - entropy;
+    fp << complexity << " ";
+  };
+  fp << endl;
+  fp.close();
+  return;
+}
+
+
+void cAnalyze::EnvironmentSetup(cString cur_string)
+{
+  cout << "Running environment command: " << endl
+       << "  " << cur_string << endl;
+
+  cTestCPU::GetEnvironment()->LoadLine(cur_string);
+}
+
 
 void cAnalyze::CommandHelpfile(cString cur_string)
 {
@@ -3908,7 +4390,10 @@
   AddLibraryDef("FITNESS_MATRIX", &cAnalyze::CommandFitnessMatrix);
   AddLibraryDef("MAP", &cAnalyze::CommandMapTasks);  // Deprecated...
   AddLibraryDef("MAP_TASKS", &cAnalyze::CommandMapTasks);
+  AddLibraryDef("AVERAGE_MODULARITY", &cAnalyze::CommandAverageModularity);
   AddLibraryDef("MAP_MUTATIONS", &cAnalyze::CommandMapMutations);
+  AddLibraryDef("ANALYZE_COMPLEXITY", &cAnalyze::AnalyzeComplexity);
+  AddLibraryDef("ANALYZE_POP_COMPLEXITY", &cAnalyze::AnalyzePopComplexity);
 
   // Population comparison commands...
   AddLibraryDef("HAMMING", &cAnalyze::CommandHamming);
@@ -3929,6 +4414,9 @@
   AddLibraryDef("ANALYZE_MUTATION_TRACEBACK",
 		&cAnalyze::AnalyzeMutationTraceback);
 
+  // Environment manipulation
+  AddLibraryDef("ENVIRONMENT", &cAnalyze::EnvironmentSetup);
+
   // Documantation...
   AddLibraryDef("HELPFILE", &cAnalyze::CommandHelpfile);
 
@@ -3967,4 +4455,3 @@
 
   return lib_it.Get();
 }
-
Index: avida/current/source/main/analyze.hh
diff -u avida/current/source/main/analyze.hh:1.39.2.3 avida/current/source/main/analyze.hh:1.39.2.4
--- avida/current/source/main/analyze.hh:1.39.2.3	Tue May 20 05:12:21 2003
+++ avida/current/source/main/analyze.hh	Thu Oct 16 07:18:21 2003
@@ -448,6 +448,7 @@
   void CommandLandscape(cString cur_string);
   void CommandFitnessMatrix(cString cur_string);
   void CommandMapTasks(cString cur_string);
+  void CommandAverageModularity(cString cur_string);
   void CommandMapMutations(cString cur_string);
 
   // Population Comparison Commands...
@@ -467,6 +468,11 @@
   void AnalyzeInstructions(cString cur_string);
   void AnalyzeBranching(cString cur_string);
   void AnalyzeMutationTraceback(cString cur_string);
+  void AnalyzeComplexity(cString cur_string);
+  void AnalyzePopComplexity(cString cur_string);
+
+  // Environment Manipulation
+  void EnvironmentSetup(cString cur_string);
 
   // Documentation...
   void CommandHelpfile(cString cur_string);
Index: avida/current/source/main/avida.cc
diff -u avida/current/source/main/avida.cc:1.34.2.6 avida/current/source/main/avida.cc:1.34.2.7
--- avida/current/source/main/avida.cc:1.34.2.6	Mon Aug 25 23:30:22 2003
+++ avida/current/source/main/avida.cc	Thu Oct 16 07:18:21 2003
@@ -192,13 +192,14 @@
   default_interface.SetFun_GetResources(&cCallbackUtil::CB_GetResources);
   default_interface.SetFun_UpdateResources(&cCallbackUtil::CB_UpdateResources);
   default_interface.SetFun_KillCell(&cCallbackUtil::CB_KillCell);
+  default_interface.SetFun_KillSurroundCell(&cCallbackUtil::CB_KillSurroundCell);
   default_interface.SetFun_SendMessage(&cCallbackUtil::CB_SendMessage);
   default_interface.SetFun_InjectParasite(&cCallbackUtil::CB_InjectParasite);
 
   population = new cPopulation(default_interface, environment);
   cout << " ...done" << endl;
 
-  // Setup Event List
+  //Setup Event List
   cout<<"Initializing Event Factory Manager..."<<flush;
   event_manager = new cEventFactoryManager;
   cStats & stats = population->GetStats();
Index: avida/current/source/main/birth_chamber.cc
diff -u avida/current/source/main/birth_chamber.cc:1.2.2.4 avida/current/source/main/birth_chamber.cc:1.2.2.5
--- avida/current/source/main/birth_chamber.cc:1.2.2.4	Thu Oct  2 17:04:39 2003
+++ avida/current/source/main/birth_chamber.cc	Thu Oct 16 07:18:21 2003
@@ -27,7 +27,8 @@
 
 bool cBirthChamber::SubmitOffspring(const cGenome & child_genome,
 				    const cOrganism & parent,
-				    tArray<cOrganism *> & child_array)
+				    tArray<cOrganism *> & child_array,
+				    tArray<cMerit> & merit_array)
 {
   // Collect some info for building the child.
   const cPopulationInterface & pop_interface = parent.PopInterface();
@@ -39,6 +40,8 @@
     // just build the child and return.
     child_array.Resize(1);
     child_array[0] = new cOrganism(child_genome, pop_interface, environment);
+    merit_array.Resize(1);
+    merit_array[0] = parent.GetPhenotype().GetMerit();
     return true;
   }
 
@@ -47,7 +50,8 @@
   // See if there is anything for it to mate with.
   if (genome_waiting == false) {
     // There is nothing waiting!
-    wait_genome = child_genome;
+    wait_entry.genome = child_genome;
+    wait_entry.merit = parent.GetPhenotype().GetMerit();
     genome_waiting = true;
     return false;
   }
@@ -55,35 +59,41 @@
   // There is already someone in the birth chamber
   // We must now do a crossover between the two 
 
-  cCPUMemory genome0 = wait_genome;
-  cCPUMemory genome1 = child_genome;
   genome_waiting = false;
 
-  // Crossover...
-  // get (for now) one region to cross
-
-  int start0 = g_random.GetInt(genome0.GetSize()); 
-  int end0   = g_random.GetInt(genome0.GetSize());
-  int start1 = genome1.GetSize() * start0 / genome0.GetSize();
-  int end1   = genome1.GetSize() * end0 / genome0.GetSize();
-
   // How many crossovers should be do? For now, 0 or 1
   if (parent.GetPhenotype().CrossNum() ==0) {
     child_array.Resize(2);
-    child_array[0] = new cOrganism(genome0, pop_interface, environment);
-    child_array[1] = new cOrganism(genome1, pop_interface, environment);    
+    child_array[0] = new cOrganism(wait_entry.genome, pop_interface,
+				   environment);
+    child_array[1] = new cOrganism(child_genome, pop_interface, environment);
+    merit_array.Resize(2);
+    merit_array[0] = wait_entry.merit;
+    merit_array[1] = parent.GetPhenotype().GetMerit();
     return true;
   }
   else {
+    cCPUMemory genome0 = wait_entry.genome;
+    cCPUMemory genome1 = child_genome;
+
+    // Crossover...
+    // get (for now) one region to cross
+    
+    double start_frac = g_random.GetDouble();
+    double end_frac = g_random.GetDouble();
+
+    if (start_frac > end_frac) Swap(start_frac, end_frac);
+
+    int start0 = (int) (start_frac * genome0.GetSize());
+    int end0   = (int) (end_frac * genome0.GetSize());
+    int start1 = (int) (start_frac * genome1.GetSize());
+    int end1   = (int) (end_frac * genome1.GetSize());
+
     assert( start0 >= 0  &&  start0 < genome0.GetSize() );
     assert( end0   >= 0  &&  end0   < genome0.GetSize() ); 
     assert( start1 >= 0  &&  start1 < genome1.GetSize() );
     assert( end1   >= 0  &&  end1   < genome1.GetSize() );
   
-    // @CAO for the moment, force start to be less than end.
-    if (start0 > end0) Swap(start0, end0);
-    if (start1 > end1) Swap(start1, end1);
-  
     // Calculate size of sections crossing over...
     int size0 = end0 - start0;
     int size1 = end1 - start1;
@@ -116,6 +126,16 @@
     child_array.Resize(2);
     child_array[0] = new cOrganism(genome0, pop_interface, environment);
     child_array[1] = new cOrganism(genome1, pop_interface, environment);
+
+    double cut_frac = end_frac - start_frac;
+    double stay_frac = 1.0 - cut_frac;
+
+    double merit0 = wait_entry.merit.GetDouble();
+    double merit1 = parent.GetPhenotype().GetMerit().GetDouble();
+    merit_array.Resize(2);
+
+    merit_array[0] = stay_frac * merit0 + cut_frac * merit1;
+    merit_array[1] = stay_frac * merit1 + cut_frac * merit0;
 
     return true;
   }
Index: avida/current/source/main/birth_chamber.hh
diff -u avida/current/source/main/birth_chamber.hh:1.1.2.1 avida/current/source/main/birth_chamber.hh:1.1.2.2
--- avida/current/source/main/birth_chamber.hh:1.1.2.1	Thu May 15 05:35:13 2003
+++ avida/current/source/main/birth_chamber.hh	Thu Oct 16 07:18:21 2003
@@ -9,6 +9,7 @@
 #define BIRTH_CHAMBER_HH
 
 #include "../tools/tList.hh"
+#include "../tools/merit.hh"
 
 #include "../cpu/cpu_memory.hh"
 #include "../cpu/label.hh"
@@ -25,8 +26,15 @@
 
 class cBirthChamber {
 private:
+  class cBirthEntry {
+  public:
+    cCPUMemory genome;
+    cMerit merit;
+  };
+
+  cBirthEntry wait_entry;
+
   // For the moment, the following variable is the only one being used.
-  cCPUMemory wait_genome;
   bool genome_waiting;  // Is there are genome waiting to be born?
   
 public:
@@ -36,7 +44,8 @@
   // Handle manipulations & tests of genome.  Return false if divide process
   // should halt.  Place offspring in child_array.
   bool SubmitOffspring(const cGenome & child_genome, const cOrganism & parent,
-		       tArray<cOrganism *> & child_array);
+		       tArray<cOrganism *> & child_array,
+		       tArray<cMerit> & merit_array);
 };
 
 #endif
Index: avida/current/source/main/callback_util.cc
diff -u avida/current/source/main/callback_util.cc:1.14.2.5 avida/current/source/main/callback_util.cc:1.14.2.6
--- avida/current/source/main/callback_util.cc:1.14.2.5	Mon Aug 25 23:30:22 2003
+++ avida/current/source/main/callback_util.cc	Thu Oct 16 07:18:21 2003
@@ -186,6 +186,13 @@
   pop->KillOrganism(death_cell);
 }
 
+void cCallbackUtil::CB_KillSurroundCell(cPopulation * pop, int commie_id)
+{
+	assert (pop != NULL);
+	cPopulationCell & death_cell = pop->GetCell(commie_id);
+	pop->Kaboom(death_cell);
+}
+
 bool cCallbackUtil::CB_SendMessage(cPopulation * pop, int cell_id, cOrgMessage & mess)
 {
   mess.SetSenderID(cell_id);
Index: avida/current/source/main/callback_util.hh
diff -u avida/current/source/main/callback_util.hh:1.8.2.2 avida/current/source/main/callback_util.hh:1.8.2.3
--- avida/current/source/main/callback_util.hh:1.8.2.2	Mon Aug 25 23:30:22 2003
+++ avida/current/source/main/callback_util.hh	Thu Oct 16 07:18:21 2003
@@ -40,6 +40,7 @@
   static void CB_UpdateResources(cPopulation  * pop, int cell_id,
 				 const tArray<double> & res_change);
   static void CB_KillCell(cPopulation * pop, int death_id);
+  static void CB_KillSurroundCell(cPopulation * pop, int commie_id);
   static bool CB_SendMessage(cPopulation * pop, int cell_id, cOrgMessage & mess);
   static bool CB_InjectParasite(cPopulation * pop, int cell_id, cOrganism * parent,
 				const cGenome & injected_code);
Index: avida/current/source/main/config.cc
diff -u avida/current/source/main/config.cc:1.50.2.6 avida/current/source/main/config.cc:1.50.2.7
--- avida/current/source/main/config.cc:1.50.2.6	Mon Aug 25 23:30:22 2003
+++ avida/current/source/main/config.cc	Thu Oct 16 07:18:21 2003
@@ -10,8 +10,8 @@
 #include "config.hh"
 
 #include "../tools/tools.hh"
-#include "cPopulation_descr.hi" // declarations and definitions
-#include "cPopulation_descr.ci" // for event documentation
+#include "../event/cPopulation_descr.hi" // declarations and definitions
+#include "../event/cPopulation_descr.ci" // for event documentation
 
 
 using namespace std;
@@ -44,6 +44,7 @@
 double cConfig::divide_ins_prob;
 double cConfig::divide_del_prob;
 double cConfig::parent_mut_prob;
+int cConfig::special_mut_line;
 int cConfig::num_instructions;
 int cConfig::hardware_type;
 int cConfig::max_cpu_threads;
@@ -200,6 +201,8 @@
 		  "Deletion rate (per divide)");
   muts_group->Add(parent_mut_prob, "0.0", "PARENT_MUT_PROB",
 		  "Per-site, in parent, on divide");
+  muts_group->Add(special_mut_line, "-1", "SPECIAL_MUT_LINE",
+		  "If this is >= 0, ONLY this line is mutated");
 
   
   // Mutation reversions group
Index: avida/current/source/main/config.hh
diff -u avida/current/source/main/config.hh:1.43.2.5 avida/current/source/main/config.hh:1.43.2.6
--- avida/current/source/main/config.hh:1.43.2.5	Mon Aug 25 23:30:22 2003
+++ avida/current/source/main/config.hh	Thu Oct 16 07:18:21 2003
@@ -188,6 +188,7 @@
   static double divide_ins_prob;
   static double divide_del_prob;
   static double parent_mut_prob;
+  static int special_mut_line;
 
   // CPU Configutation
   static int num_instructions;
@@ -313,6 +314,7 @@
   static double GetDivideInsProb() { return divide_ins_prob; }
   static double GetDivideDelProb() { return divide_del_prob; }
   static double GetParentMutProb() { return parent_mut_prob; }
+  static int GetSpecialMutLine() { return special_mut_line; }  
 
   static int GetNumInstructions() { return num_instructions; }
   static int GetHardwareType() { return hardware_type; }
Index: avida/current/source/main/environment.cc
diff -u avida/current/source/main/environment.cc:1.8.2.4 avida/current/source/main/environment.cc:1.8.2.5
--- avida/current/source/main/environment.cc:1.8.2.4	Mon Aug 25 23:30:22 2003
+++ avida/current/source/main/environment.cc	Thu Oct 16 07:18:21 2003
@@ -551,6 +551,60 @@
   return true;
 }
 
+bool cEnvironment::LoadSetActive(cString desc)
+{
+  cString item_type = desc.PopWord(); 
+  item_type.ToUpper();
+
+  cString item_name = desc.PopWord();
+
+  cString item_active = desc.PopWord();
+  item_active.ToUpper();
+
+  bool new_active = true;
+  if (item_active == "0" || item_active == "FALSE") new_active = false;
+
+  if (item_type == "REACTION") {
+    cReaction * cur_reaction = reaction_lib.GetReaction(item_name);
+    if (cur_reaction == NULL) {
+      cerr << "Unknown REACTION: '" << item_name << "'" << endl;
+      return false;
+    }
+    cur_reaction->SetActive(new_active);
+  } else if (item_type == "") {
+    cerr << "Format: SET_ACTIVE <type> <name> <new_status=true>" << endl;
+  } else {
+    cerr << "Error: Cannot deactivate items of type "
+	 << item_type << endl;
+    return false;
+  }
+
+  return true;
+}
+
+bool cEnvironment::LoadLine(cString line) 
+{
+  cString type = line.PopWord();      // Determine type of this entry.
+  type.ToUpper();                     // Make type case insensitive.
+
+  bool load_ok = true;
+  if (type == "RESOURCE") load_ok = LoadResource(line);
+  else if (type == "REACTION") load_ok = LoadReaction(line);
+  else if (type == "MUTATION") load_ok = LoadMutation(line);
+  else if (type == "SET_ACTIVE") load_ok = LoadSetActive(line);
+  else {
+    cerr << "Error: Unknown environment keyword '" << type << "." << endl;
+    return false;
+  }
+  
+  if (load_ok == false) {
+    cerr << "...failed in loading '" << type << "'..." << endl;
+    return false;
+  }
+
+  return true;
+}
+
 bool cEnvironment::Load(const cString & filename)
 {
   cerr << "ENV: Loading file '" << filename << "'." << endl;
@@ -568,23 +622,9 @@
   // cerr << "ENV: found " << infile.GetNumLines() << " commands." << endl;
 
   for (int line_id = 0; line_id < infile.GetNumLines(); line_id++) {
-    cString line = infile.GetLine(line_id); // Load next line from file.
-    cString type = line.PopWord();      // Determine type of this entry.
-    type.ToUpper();                     // Make type case insensitive.
-
-    bool load_ok = true;
-    if (type == "RESOURCE") load_ok = LoadResource(line);
-    else if (type == "REACTION") load_ok = LoadReaction(line);
-    else if (type == "MUTATION") load_ok = LoadMutation(line);
-    else {
-      cerr << "Error: Unknown environment keyword '" << type << "." << endl;
-      return false;
-    }
-
-    if (load_ok == false) {
-      cerr << "...failed in loading '" << type << "'..." << endl;
-      return false;
-    }
+    // Load the next line from the file.
+    bool load_ok = LoadLine(infile.GetLine(line_id));
+    if (load_ok == false) return false;
   }
 
   // Make sure that all pre-declared reactions have been loaded correctly.
@@ -642,6 +682,9 @@
   for (int i = 0; i < num_reactions; i++) {
     cReaction * cur_reaction = reaction_lib.GetReaction(i);
     assert(cur_reaction != NULL);
+
+    // Only use active reactions...
+    if (cur_reaction->GetActive() == false) continue;
 
     // Examine the task trigger associated with this reaction
     cTaskEntry * cur_task = cur_reaction->GetTask();
Index: avida/current/source/main/environment.hh
diff -u avida/current/source/main/environment.hh:1.7.2.2 avida/current/source/main/environment.hh:1.7.2.3
--- avida/current/source/main/environment.hh:1.7.2.2	Mon Aug 25 23:30:22 2003
+++ avida/current/source/main/environment.hh	Thu Oct 16 07:18:21 2003
@@ -46,6 +46,8 @@
   bool LoadReaction(cString desc);
   bool LoadMutation(cString desc);
 
+  bool LoadSetActive(cString desc);
+
   bool TestRequisites(const tList<cReactionRequisite> & req_list,
 		      int task_count,
 		      const tArray<int> & reaction_count) const;
@@ -62,6 +64,11 @@
    * Reads the environment from disk.
    **/
   bool Load(const cString & filename);
+
+  /**
+   * Reads in a single environment configuration line
+   **/
+  bool LoadLine(cString line);
 
   // Interaction with the organisms
   void SetupInputs( tArray<int> & input_array ) const;
Index: avida/current/source/main/inst_set.cc
diff -u avida/current/source/main/inst_set.cc:1.1.2.5 avida/current/source/main/inst_set.cc:1.1.2.6
--- avida/current/source/main/inst_set.cc:1.1.2.5	Mon Aug 25 23:30:22 2003
+++ avida/current/source/main/inst_set.cc	Thu Oct 16 07:18:21 2003
@@ -18,6 +18,7 @@
 //////////////////////
 
 // Initialize static variables
+const cInstruction cInstSet::inst_default(   0 );
 cInstruction cInstSet::inst_default2(   0 );
 cInstruction cInstSet::inst_error2  ( 255 );
 
Index: avida/current/source/main/organism.hh
diff -u avida/current/source/main/organism.hh:1.18.2.3 avida/current/source/main/organism.hh:1.18.2.4
--- avida/current/source/main/organism.hh:1.18.2.3	Mon Aug 25 23:30:23 2003
+++ avida/current/source/main/organism.hh	Thu Oct 16 07:18:21 2003
@@ -10,6 +10,7 @@
 
 #include <fstream>
 #include <deque>
+#include <vector>
 
 #include "../tools/merit.hh"
 #include "../tools/tBuffer.hh"
@@ -26,6 +27,7 @@
 
 #include "../cpu/cpu_memory.hh"
 #include "../cpu/cpu_stats.hh"
+using namespace std;
 
 class cEnvironment;
 class cGenotype;
@@ -92,9 +94,10 @@
   int GetInput() { return pop_interface.GetInput(); }
   int GetInputAt(int & input_pointer) { return pop_interface.GetInputAt(input_pointer); }
   void Die() { pop_interface.Die(); }
+  void Kaboom() {pop_interface.Kaboom();}
   int GetCellID() { return pop_interface.GetCellID(); }
   int GetDebugInfo() { return pop_interface.Debug(); }
-
+  
   // Input & Output Testing
   void DoInput(const int value, tBuffer<int> & in_buf, tBuffer<int> & out_buf);
   void DoOutput(const int value, tBuffer<int> & in_buf, tBuffer<int> &out_buf);
Index: avida/current/source/main/pop_interface.cc
diff -u avida/current/source/main/pop_interface.cc:1.10.2.3 avida/current/source/main/pop_interface.cc:1.10.2.4
--- avida/current/source/main/pop_interface.cc:1.10.2.3	Mon Aug 25 23:30:23 2003
+++ avida/current/source/main/pop_interface.cc	Thu Oct 16 07:18:21 2003
@@ -32,6 +32,7 @@
   , fun_get_resources(NULL)
   , fun_update_resources(NULL)
   , fun_kill_cell(NULL)
+  , fun_kill_surround_cell(NULL)
     , fun_send_message(NULL)
     , fun_inject_parasite(NULL)
 {
@@ -59,6 +60,7 @@
   fun_get_resources    = in_interface.fun_get_resources;
   fun_update_resources = in_interface.fun_update_resources;
   fun_kill_cell        = in_interface.fun_kill_cell;
+  fun_kill_surround_cell = in_interface.fun_kill_surround_cell;
   fun_send_message     = in_interface.fun_send_message;
   fun_inject_parasite  = in_interface.fun_inject_parasite;
 }
@@ -169,6 +171,12 @@
   (*fun_kill_cell)(population, cell_id);
 }
 
+void cPopulationInterface::Kaboom()
+{
+	if (fun_kill_surround_cell == NULL) return;
+	(*fun_kill_surround_cell)(population, cell_id);
+}
+
 bool cPopulationInterface::SendMessage(cOrgMessage & mess)
 {
   if (fun_send_message == NULL) return false;
@@ -181,3 +189,4 @@
   if (fun_inject_parasite == NULL) return false;
   return (*fun_inject_parasite)(population, cell_id, parent, injected_code);
 }
+
Index: avida/current/source/main/pop_interface.hh
diff -u avida/current/source/main/pop_interface.hh:1.8.2.2 avida/current/source/main/pop_interface.hh:1.8.2.3
--- avida/current/source/main/pop_interface.hh:1.8.2.2	Mon Aug 25 23:30:23 2003
+++ avida/current/source/main/pop_interface.hh	Thu Oct 16 07:18:21 2003
@@ -39,10 +39,12 @@
 typedef void (*tFunUpdateResources)
   (cPopulation * pop, int cell_id, const tArray<double> & res_change);
 typedef void (*tFunKillCell)(cPopulation * pop, int death_id);
+typedef void (*tFunKillSurroundCell)(cPopulation * pop, int commie_id);
 typedef bool (*tFunSendMessage)(cPopulation * pop, int cell_id, cOrgMessage & mess);
 typedef bool (*tFunInjectParasite)
   (cPopulation * pop, int cell_id, cOrganism * parent, const cGenome & injected_code);
 
+
 class cPopulationInterface {
 private:
   cPopulation * population;
@@ -63,7 +65,8 @@
   tFunDebug            fun_debug;
   tFunGetResources     fun_get_resources;
   tFunUpdateResources  fun_update_resources;
-  tFunKillCell         fun_kill_cell;
+  tFunKillCell		   fun_kill_cell;
+  tFunKillSurroundCell fun_kill_surround_cell;
   tFunSendMessage      fun_send_message;
   tFunInjectParasite   fun_inject_parasite;
 public:
@@ -93,6 +96,7 @@
   void SetFun_UpdateResources(tFunUpdateResources fun)
     { fun_update_resources = fun; }
   void SetFun_KillCell(tFunKillCell fun) { fun_kill_cell = fun; }
+  void SetFun_KillSurroundCell(tFunKillSurroundCell fun) {fun_kill_surround_cell = fun; }
   void SetFun_SendMessage(tFunSendMessage fun) { fun_send_message = fun; }
   void SetFun_InjectParasite(tFunInjectParasite fun) { fun_inject_parasite = fun; }
   void CopyCallbacks(cPopulationInterface & in_interface);
@@ -114,6 +118,7 @@
   const tArray<double> & GetResources();
   void UpdateResources(const tArray<double> & res_change);
   void Die();
+  void Kaboom();
   bool SendMessage(cOrgMessage & mess);
   bool InjectParasite(cOrganism * parent, const cGenome & injected_code);
 };
Index: avida/current/source/main/population.cc
diff -u avida/current/source/main/population.cc:1.94.2.7 avida/current/source/main/population.cc:1.94.2.8
--- avida/current/source/main/population.cc:1.94.2.7	Thu Oct  2 17:04:39 2003
+++ avida/current/source/main/population.cc	Thu Oct 16 07:18:21 2003
@@ -250,7 +250,9 @@
   assert(&parent_organism != NULL);
 
   tArray<cOrganism *> child_array;
-  birth_chamber.SubmitOffspring(child_genome, parent_organism, child_array);
+  tArray<cMerit> merit_array;
+  birth_chamber.SubmitOffspring(child_genome, parent_organism,
+				child_array, merit_array);
 
   cPhenotype & parent_phenotype = parent_organism.GetPhenotype();
 
@@ -314,7 +316,9 @@
   // Go back into a for-loop and continue to deal with the children.
   for (int i = 0; i < child_array.GetSize(); i++) {
     const int child_length = child_array[i]->GetGenome().GetSize();
-    child_array[i]->GetPhenotype().SetupOffspring(parent_phenotype,child_length);
+    child_array[i]->GetPhenotype().
+      SetupOffspring(parent_phenotype,child_length);
+    child_array[i]->GetPhenotype().SetMerit(merit_array[i]);
   }
 
   // If we're not about to kill the parent, do some extra work on it.
@@ -539,6 +543,52 @@
 
   // Update the genebank (note: genotype adjustment may be defered)
   genebank->AdjustGenotype(*genotype);
+}
+
+void cPopulation::Kaboom(cPopulationCell & in_cell)
+{
+  cOrganism * organism = in_cell.GetOrganism();
+  cGenotype * genotype = organism->GetGenotype();
+  cGenome genome = genotype->GetGenome();
+  int id = genotype->GetID();
+  
+  int radius = 2;
+  int distance = 0;
+  int count = 0;
+  
+  for (int i=-1*radius; i<=radius; i++) {
+    for (int j=-1*radius; j<=radius; j++) {
+      cPopulationCell & death_cell =
+	cell_array[Neighbor(in_cell.GetID(), world_x, world_y, i, j)];
+      //do we actually have something to kill?
+      if (death_cell.IsOccupied() == false) continue;
+      
+      cOrganism * org_temp = death_cell.GetOrganism();
+      cGenotype * gene_temp = org_temp->GetGenotype();
+      
+      if (distance == 0) {
+	int temp_id = gene_temp->GetID();
+	if (temp_id != id) {
+	  KillOrganism(death_cell);
+	  count++;
+	}
+      }
+      else {	
+	cGenome genome_temp = gene_temp->GetGenome();
+	int diff=0;
+	for (int i=0; i<genome_temp.GetSize(); i++)
+	  if (genome_temp.AsString()[i] != genome.AsString()[i])
+	    diff++;
+	if (diff > distance)
+	  {
+	    KillOrganism(death_cell);
+	    count++;
+	  }
+      }
+    }
+  }
+  KillOrganism(in_cell);
+  // @SLG my prediction = 92% and, 28 get equals
 }
 
 /**
Index: avida/current/source/main/population.hh
diff -u avida/current/source/main/population.hh:1.48.2.6 avida/current/source/main/population.hh:1.48.2.7
--- avida/current/source/main/population.hh:1.48.2.6	Thu Oct  2 17:04:39 2003
+++ avida/current/source/main/population.hh	Thu Oct 16 07:18:21 2003
@@ -111,6 +111,7 @@
 
   // Deactivate an organism in the population (required for deactivations)
   void KillOrganism(cPopulationCell & in_cell);
+  void Kaboom(cPopulationCell & in_cell);
 
   // Process a single organism one instruction...
   int ScheduleOrganism();          // Determine next organism to be processed.
Index: avida/current/source/main/reaction.cc
diff -u avida/current/source/main/reaction.cc:1.4.2.2 avida/current/source/main/reaction.cc:1.4.2.3
--- avida/current/source/main/reaction.cc:1.4.2.2	Mon Aug 25 23:30:24 2003
+++ avida/current/source/main/reaction.cc	Thu Oct 16 07:18:21 2003
@@ -62,6 +62,7 @@
   : name(_name)
   , id(_id)
   , task(NULL)
+  , active(true)
 {
 }
 
Index: avida/current/source/main/reaction.hh
diff -u avida/current/source/main/reaction.hh:1.3.2.1 avida/current/source/main/reaction.hh:1.3.2.2
--- avida/current/source/main/reaction.hh:1.3.2.1	Mon Aug 25 23:30:24 2003
+++ avida/current/source/main/reaction.hh	Thu Oct 16 07:18:21 2003
@@ -100,6 +100,7 @@
   cTaskEntry * task;
   tList<cReactionProcess> process_list;
   tList<cReactionRequisite> requisite_list;
+  bool active;
 public:
   cReaction(const cString & _name, int _id);
   ~cReaction();
@@ -110,10 +111,12 @@
   const tList<cReactionProcess> & GetProcesses() { return process_list; }
   const tList<cReactionRequisite> & GetRequisites()
     { return requisite_list; }
+  bool GetActive() const { return active; }
 
   void SetTask(cTaskEntry * _task) { task = _task; }
   cReactionProcess * AddProcess();
   cReactionRequisite * AddRequisite();
+  void SetActive(bool in_active=true) { active = in_active; }
 };
 
 class cReactionLib {
Index: avida/current/source/main/functional_testsuites/tedious.tail/genesis
diff -u avida/current/source/main/functional_testsuites/tedious.tail/genesis:1.1.2.1 avida/current/source/main/functional_testsuites/tedious.tail/genesis:1.1.2.2
--- avida/current/source/main/functional_testsuites/tedious.tail/genesis:1.1.2.1	Fri Oct  3 14:12:21 2003
+++ avida/current/source/main/functional_testsuites/tedious.tail/genesis	Thu Oct 16 07:18:21 2003
@@ -3,7 +3,7 @@
 # For more information, see doc/genesis.html
 #############################################################################
 
-VERSION_ID 2.0b6		# Do not change this value!
+VERSION_ID 2.0b7		# Do not change this value!
 
 ### Architecture Variables ###
 MAX_UPDATES  -1         # Maximum updates to run simulation (-1 = no limit)
Index: avida/current/source/qt-viewer/avd_instruction_viewer_controller.cc
diff -u avida/current/source/qt-viewer/avd_instruction_viewer_controller.cc:1.1.2.5 avida/current/source/qt-viewer/avd_instruction_viewer_controller.cc:1.1.2.6
--- avida/current/source/qt-viewer/avd_instruction_viewer_controller.cc:1.1.2.5	Mon Oct 13 10:00:51 2003
+++ avida/current/source/qt-viewer/avd_instruction_viewer_controller.cc	Thu Oct 16 07:18:21 2003
@@ -1,3 +1,5 @@
+
+
 #ifndef AVD_INSTRUCTIONS_VIEW_CONTROLLER_HH
 #include "avd_instruction_viewer_controller.hh"
 #endif
Index: avida/current/source/support/genesis
diff -u avida/current/source/support/genesis:1.34.2.5 avida/current/source/support/genesis:1.34.2.6
--- avida/current/source/support/genesis:1.34.2.5	Thu Oct  2 17:04:50 2003
+++ avida/current/source/support/genesis	Thu Oct 16 07:18:22 2003
@@ -3,7 +3,7 @@
 # For more information, see doc/genesis.html
 #############################################################################
 
-VERSION_ID 2.0b6		# Do not change this value!
+VERSION_ID 2.0b7		# Do not change this value!
 
 ### Architecture Variables ###
 MAX_UPDATES  -1         # Maximum updates to run simulation (-1 = no limit)
Index: avida/current/source/tools/functions.hh
diff -u avida/current/source/tools/functions.hh:1.8.2.3 avida/current/source/tools/functions.hh:1.8.2.4
--- avida/current/source/tools/functions.hh:1.8.2.3	Tue May 20 05:14:37 2003
+++ avida/current/source/tools/functions.hh	Thu Oct 16 07:18:22 2003
@@ -40,6 +40,13 @@
   in2 = tmp;
 }
 
+inline void Swap(double & in1, double & in2)
+{
+  const double tmp = in1;
+  in1 = in2;
+  in2 = tmp;
+}
+
 inline bool ToggleBool(bool & in_bool)
 {
   if (in_bool == true) in_bool = false;
Index: avida/current/source/tools/stat.hh
diff -u avida/current/source/tools/stat.hh:1.7.2.1 avida/current/source/tools/stat.hh:1.7.2.2
--- avida/current/source/tools/stat.hh:1.7.2.1	Mon May 12 10:22:49 2003
+++ avida/current/source/tools/stat.hh	Thu Oct 16 07:18:22 2003
@@ -111,7 +111,11 @@
     //n*(s2/n - s1/n*s1/n) / (n-1) : INF_ERR; }
   double StdDeviation() const { return sqrt(Variance()); }
   double StdError()  const { return (n > 1) ?
-       sqrt(s2 / (n * (n-1))) : INF_ERR; }
+         sqrt(Variance()/n) : INF_ERR; }
+
+//      old formula, implemented by TCC, not sure how it relates to 
+//      the real Standard Error
+//       sqrt(s2 / (n * (n-1))) : INF_ERR; }
 
   double Skewness() const { return ( n > 2 ) ?
        (n*s3 - 3*s2*s1 + 2*s1*s1*s1/n) / ((n-1)*(n-2)) : INF_ERR; }


More information about the Avida-cvs mailing list