[Avida-cvs] [avida-svn] r523 - in development/source: analyze classification cpu main

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Sun Mar 19 17:18:38 PST 2006


Author: brysonda
Date: 2006-03-19 20:16:06 -0500 (Sun, 19 Mar 2006)
New Revision: 523

Modified:
   development/source/analyze/cAnalyze.cc
   development/source/analyze/cAnalyze.h
   development/source/analyze/cAnalyzeJobQueue.cc
   development/source/classification/cGenotype.cc
   development/source/classification/cGenotype.h
   development/source/classification/cInjectGenotype.cc
   development/source/classification/cInjectGenotype.h
   development/source/cpu/cHardware4Stack.cc
   development/source/cpu/cHardware4Stack.h
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/cpu/cHardwareSMT.cc
   development/source/cpu/cHardwareSMT.h
   development/source/cpu/cTestCPU.cc
   development/source/cpu/cTestCPUInterface.cc
   development/source/cpu/cTestCPUInterface.h
   development/source/main/cBirthChamber.cc
   development/source/main/cBirthChamber.h
   development/source/main/cEnvironment.cc
   development/source/main/cEnvironment.h
   development/source/main/cInstSet.cc
   development/source/main/cLandscape.cc
   development/source/main/cMutationRates.cc
   development/source/main/cMutationRates.h
   development/source/main/cOrgInterface.h
   development/source/main/cOrganism.cc
   development/source/main/cOrganism.h
   development/source/main/cPhenotype.cc
   development/source/main/cPhenotype.h
   development/source/main/cPopulation.cc
   development/source/main/cPopulation.h
   development/source/main/cPopulationCell.cc
   development/source/main/cPopulationCell.h
   development/source/main/cPopulationInterface.cc
   development/source/main/cPopulationInterface.h
   development/source/main/cTaskLib.cc
   development/source/main/cTaskLib.h
   development/source/main/cWorld.h
Log:
Convert many cWorld::GetRandom() usages over to cAvidaContext::GetRandom().  Pass around cAvidaContext to several more functions, as necessary.

Changed cTaskContext creation semantics to avoid the resulting heavy use of malloc within tight execution looping.   Was causing performance problems in multithreaded situations.    Also changed cTaskContext members to const references to avoid unnecessary copy overhead.

Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/analyze/cAnalyze.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -66,7 +66,7 @@
 : cur_batch(0)
 , m_world(world)
 , inst_set(world->GetHardwareManager().GetInstSet())
-, m_ctx(0)
+, m_ctx(world->GetRandom())
 , verbose(nAnalyze::VERBOSE_QUIET)
 , interactive_depth(0)
 {
@@ -1657,12 +1657,12 @@
   }
 }
 
-void cAnalyze::CommandLandscapePreGen(cString cur_string)
+void cAnalyze::CommandCalcLandscape(cString cur_string)
 {
   cAnalyzeJobQueue queue(m_world);
   tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
 
-  cout << "Precalculating Fitness Landscape..." << endl;
+  cout << "Calculating Landscape..." << endl;
 
   for (cAnalyzeGenotype* cur_genotype = batch_it.Next(); cur_genotype; cur_genotype = batch_it.Next()) {
     queue.AddJob(new tAnalyzeJob<cAnalyzeGenotype>(cur_genotype, &cAnalyzeGenotype::CalcLandscape));
@@ -7801,7 +7801,7 @@
   AddLibraryDef("SYSTEM", &cAnalyze::CommandSystem);
   AddLibraryDef("INTERACTIVE", &cAnalyze::CommandInteractive);
 //  AddLibraryDef("PRINT_TEST_CPU_RESOURCES", &cAnalyze::PrintTestCPUResources);
-  AddLibraryDef("LANDSCAPE_PREGEN", &cAnalyze::CommandLandscapePreGen);
+  AddLibraryDef("CALC_LANDSCAPE", &cAnalyze::CommandCalcLandscape);
   
   // Functions...
   AddLibraryDef("FUNCTION", &cAnalyze::FunctionCreate);

Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/analyze/cAnalyze.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -235,7 +235,7 @@
   void CommandSystem(cString cur_string);
   void CommandInteractive(cString cur_string);
 //  void PrintTestCPUResources(cString cur_string);
-  void CommandLandscapePreGen(cString cur_string);
+  void CommandCalcLandscape(cString cur_string);
 
   // Functions...
   void FunctionCreate(cString cur_string, tList<cAnalyzeCommand> & clist);

Modified: development/source/analyze/cAnalyzeJobQueue.cc
===================================================================
--- development/source/analyze/cAnalyzeJobQueue.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/analyze/cAnalyzeJobQueue.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -12,6 +12,9 @@
 #include "cAnalyzeJobWorker.h"
 #include "cWorld.h"
 
+#include <iostream>
+using namespace std;
+
 cAnalyzeJobQueue::cAnalyzeJobQueue(cWorld* world) : m_world(world), m_last_jobid(0)
 {
   for (int i = 0; i < MT_RANDOM_POOL_SIZE; i++) {
@@ -34,6 +37,8 @@
   
   cAnalyzeJobWorker* workers[num_workers];
   
+  cout << "Going Multithreaded..." << endl;
+  
   for (int i = 0; i < num_workers; i++) {
     workers[i] = new cAnalyzeJobWorker(this);
     workers[i]->Start();

Modified: development/source/classification/cGenotype.cc
===================================================================
--- development/source/classification/cGenotype.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/classification/cGenotype.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -156,16 +156,6 @@
   tmp_sum_fitness.Add(        parent->GetFitness());
 }
 
-void cGenotype::Mutate()  // Check each location to be mutated.
-{
-  int i;
-
-  for (i = 0; i < genome.GetSize(); i++) {
-    genome[i].SetOp(m_world->GetRandom().GetUInt(m_world->GetNumInstructions()));
-    // Flag command as having been mutated? @CAO
-  }
-}
-
 void cGenotype::UpdateReset()
 {
   last_num_organisms = num_organisms;

Modified: development/source/classification/cGenotype.h
===================================================================
--- development/source/classification/cGenotype.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/classification/cGenotype.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -102,7 +102,6 @@
   bool SaveClone(std::ofstream& fp);
   static cGenotype* LoadClone(cWorld* world, std::ifstream& fp);
   bool OK();
-  void Mutate();
   void UpdateReset();
 
   void SetGenome(const cGenome & in_genome);

Modified: development/source/classification/cInjectGenotype.cc
===================================================================
--- development/source/classification/cInjectGenotype.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/classification/cInjectGenotype.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -104,16 +104,6 @@
   parent->AddOffspringGenotype();
 }
 
-void cInjectGenotype::Mutate()  // Check each location to be mutated.
-{
-  int i;
-
-  for (i = 0; i < genome.GetSize(); i++) {
-      genome[i].SetOp(m_world->GetRandom().GetUInt(m_world->GetNumInstructions()));
-    }
-  
-}
-
 void cInjectGenotype::UpdateReset()
 {
   last_num_injected = num_injected;

Modified: development/source/classification/cInjectGenotype.h
===================================================================
--- development/source/classification/cInjectGenotype.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/classification/cInjectGenotype.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -66,7 +66,6 @@
   bool SaveClone(std::ofstream& fp);
   bool LoadClone(std::ifstream & fp);
   bool OK();
-  void Mutate();
   void UpdateReset();
 
   void SetGenome(const cGenome & in_genome);

Modified: development/source/cpu/cHardware4Stack.cc
===================================================================
--- development/source/cpu/cHardware4Stack.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/cpu/cHardware4Stack.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -347,7 +347,7 @@
     const cInstruction& cur_inst = IP().GetInst();
     
     // Test if costs have been paid and it is okay to execute this now...
-    const bool exec = SingleProcess_PayCosts(cur_inst);
+    const bool exec = SingleProcess_PayCosts(ctx, cur_inst);
     
     // Now execute the instruction...
     if (exec == true) {
@@ -373,7 +373,7 @@
 // This method will test to see if all costs have been paid associated
 // with executing an instruction and only return true when that instruction
 // should proceed.
-bool cHardware4Stack::SingleProcess_PayCosts(const cInstruction & cur_inst)
+bool cHardware4Stack::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
 {
 #ifdef INSTRUCTION_COSTS
   assert(cur_inst.GetOp() < inst_cost.GetSize());
@@ -396,7 +396,7 @@
   
   // Prob of exec
   if ( m_inst_set->GetProbFail(cur_inst) > 0.0 ){
-    return !( m_world->GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
+    return !( ctx.GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
   }
 #endif
   return true;
@@ -404,7 +404,7 @@
 
 // This method will handle the actuall execution of an instruction
 // within single process, once that function has been finalized.
-bool cHardware4Stack::SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction & cur_inst) 
+bool cHardware4Stack::SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst) 
 {
   // Copy Instruction locally to handle stochastic effects
   cInstruction actual_inst = cur_inst;
@@ -868,7 +868,7 @@
   //************* CALL GOES HERE ******************//
   // spin around randomly (caution: possible organism dizziness)
   //const int num_neighbors = organism->GetNeighborhoodSize();
-  //for(unsigned int i=0; i<m_world->GetRandom().GetUInt(num_neighbors); i++)
+  //for(unsigned int i=0; i<ctx.GetRandom().GetUInt(num_neighbors); i++)
   //  organism->Rotate(1);
   
   // If we don't have a host, stop here.
@@ -978,10 +978,10 @@
 int cHardware4Stack::PointMutate(cAvidaContext& ctx, const double mut_rate)
 {
   const int num_muts =
-  m_world->GetRandom().GetRandBinomial(GetMemory(0).GetSize(), mut_rate);
+  ctx.GetRandom().GetRandBinomial(GetMemory(0).GetSize(), mut_rate);
   
   for (int i = 0; i < num_muts; i++) {
-    const int pos = m_world->GetRandom().GetUInt(GetMemory(0).GetSize());
+    const int pos = ctx.GetRandom().GetUInt(GetMemory(0).GetSize());
     Mutate(ctx, pos);
   }
   
@@ -1061,11 +1061,11 @@
   // The rate we have stored indicates the probability that a single
   // mutation will occur anywhere in the genome.
   
-  if (m_world->GetRandom().P(rate) == true) {
+  if (ctx.GetRandom().P(rate) == true) {
     // We must create a temporary head and use it to randomly determine the
     // position in the genome to be mutated.
     cHeadCPU tmp_head(cur_head);
-    tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
+    tmp_head.AbsSet(ctx.GetRandom().GetUInt(target_memory.GetSize()));
     TriggerMutations_Body(ctx, cur_mut->GetType(), target_memory, tmp_head);
     return true;
   }
@@ -1078,7 +1078,7 @@
   // The rate we have stored is the probability for a mutation at this single
   // position in the genome.
   
-  if (m_world->GetRandom().P(rate) == true) {
+  if (ctx.GetRandom().P(rate) == true) {
     TriggerMutations_Body(ctx, cur_mut->GetType(), target_memory, cur_head);
     return true;
   }
@@ -1093,12 +1093,12 @@
   // that should occur.
   
   const int num_mut =
-  m_world->GetRandom().GetRandBinomial(target_memory.GetSize(), rate);
+  ctx.GetRandom().GetRandBinomial(target_memory.GetSize(), rate);
   
   if (num_mut > 0) {
     for (int i = 0; i < num_mut; i++) {
       cHeadCPU tmp_head(cur_head);
-      tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
+      tmp_head.AbsSet(ctx.GetRandom().GetUInt(target_memory.GetSize()));
       TriggerMutations_Body(ctx, cur_mut->GetType(), target_memory, tmp_head);
     }
   }
@@ -1326,34 +1326,34 @@
   organism->GetPhenotype().SetDivType(mut_multiplier);
   
   // Divide Mutations
-  if (organism->TestDivideMut()) {
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
+  if (organism->TestDivideMut(ctx)) {
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize());
     child_genome[mut_line] = m_inst_set->GetRandomInst(ctx);
     cpu_stats.mut_stats.divide_mut_count++;
   }
   
   // Divide Insertions
-  if (organism->TestDivideIns() && child_genome.GetSize() < MAX_CREATURE_SIZE){
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
+  if (organism->TestDivideIns(ctx) && child_genome.GetSize() < MAX_CREATURE_SIZE){
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize() + 1);
     child_genome.Insert(mut_line, m_inst_set->GetRandomInst(ctx));
     cpu_stats.mut_stats.divide_insert_mut_count++;
   }
   
   // Divide Deletions
-  if (organism->TestDivideDel() && child_genome.GetSize() > MIN_CREATURE_SIZE){
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
+  if (organism->TestDivideDel(ctx) && child_genome.GetSize() > MIN_CREATURE_SIZE){
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize());
     child_genome.Remove(mut_line);
     cpu_stats.mut_stats.divide_delete_mut_count++;
   }
   
   // Divide Mutations (per site)
   if(organism->GetDivMutProb() > 0){
-    int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(), 
+    int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(), 
                                                        organism->GetDivMutProb() / mut_multiplier);
     // If we have lines to mutate...
     if( num_mut > 0 ){
       for (int i = 0; i < num_mut; i++) {
-        int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
+        int site = ctx.GetRandom().GetUInt(child_genome.GetSize());
         child_genome[site] = m_inst_set->GetRandomInst(ctx);
         cpu_stats.mut_stats.div_mut_count++;
       }
@@ -1363,7 +1363,7 @@
   
   // Insert Mutations (per site)
   if(organism->GetInsMutProb() > 0){
-    int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
+    int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(),
                                                        organism->GetInsMutProb());
     // If would make creature to big, insert up to MAX_CREATURE_SIZE
     if( num_mut + child_genome.GetSize() > MAX_CREATURE_SIZE ){
@@ -1374,7 +1374,7 @@
       // Build a list of the sites where mutations occured
       static int mut_sites[MAX_CREATURE_SIZE];
       for (int i = 0; i < num_mut; i++) {
-        mut_sites[i] = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
+        mut_sites[i] = ctx.GetRandom().GetUInt(child_genome.GetSize() + 1);
       }
       // Sort the list
       qsort( (void*)mut_sites, num_mut, sizeof(int), &IntCompareFunction );
@@ -1389,7 +1389,7 @@
   
   // Delete Mutations (per site)
   if( organism->GetDelMutProb() > 0 ){
-    int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
+    int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(),
                                                        organism->GetDelMutProb());
     // If would make creature too small, delete down to MIN_CREATURE_SIZE
     if (child_genome.GetSize() - num_mut < MIN_CREATURE_SIZE) {
@@ -1398,7 +1398,7 @@
     
     // If we have lines to delete...
     for (int i = 0; i < num_mut; i++) {
-      int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
+      int site = ctx.GetRandom().GetUInt(child_genome.GetSize());
       child_genome.Remove(site);
       cpu_stats.mut_stats.delete_mut_count++;
     }
@@ -1407,7 +1407,7 @@
   // Mutations in the parent's genome
   if (organism->GetParentMutProb() > 0) {
     for (int i = 0; i < GetMemory(0).GetSize(); i++) {
-      if (organism->TestParentMut()) {
+      if (organism->TestParentMut(ctx)) {
         GetMemory(0)[i] = m_inst_set->GetRandomInst(ctx);
         cpu_stats.mut_stats.parent_mut_line_count++;
       }
@@ -1436,34 +1436,34 @@
   organism->GetPhenotype().SetDivType(mut_multiplier);
   
   // Divide Mutations
-  if (organism->TestDivideMut()) {
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize());
+  if (organism->TestDivideMut(ctx)) {
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(injected_code.GetSize());
     injected_code[mut_line] = m_inst_set->GetRandomInst(ctx);
     //cpu_stats.mut_stats.divide_mut_count++;
   }
   
   // Divide Insertions
-  if (organism->TestDivideIns() && injected_code.GetSize() < MAX_CREATURE_SIZE){
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize() + 1);
+  if (organism->TestDivideIns(ctx) && injected_code.GetSize() < MAX_CREATURE_SIZE){
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(injected_code.GetSize() + 1);
     injected_code.Insert(mut_line, m_inst_set->GetRandomInst(ctx));
     //cpu_stats.mut_stats.divide_insert_mut_count++;
   }
   
   // Divide Deletions
-  if (organism->TestDivideDel() && injected_code.GetSize() > MIN_CREATURE_SIZE){
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize());
+  if (organism->TestDivideDel(ctx) && injected_code.GetSize() > MIN_CREATURE_SIZE){
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(injected_code.GetSize());
     injected_code.Remove(mut_line);
     //cpu_stats.mut_stats.divide_delete_mut_count++;
   }
   
   // Divide Mutations (per site)
   if(organism->GetDivMutProb() > 0){
-    int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(), 
+    int num_mut = ctx.GetRandom().GetRandBinomial(injected_code.GetSize(), 
                                                        organism->GetDivMutProb() / mut_multiplier);
     // If we have lines to mutate...
     if( num_mut > 0 ){
       for (int i = 0; i < num_mut; i++) {
-        int site = m_world->GetRandom().GetUInt(injected_code.GetSize());
+        int site = ctx.GetRandom().GetUInt(injected_code.GetSize());
         injected_code[site] = m_inst_set->GetRandomInst(ctx);
         //cpu_stats.mut_stats.div_mut_count++;
       }
@@ -1473,7 +1473,7 @@
   
   // Insert Mutations (per site)
   if(organism->GetInsMutProb() > 0){
-    int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(),
+    int num_mut = ctx.GetRandom().GetRandBinomial(injected_code.GetSize(),
                                                        organism->GetInsMutProb());
     // If would make creature to big, insert up to MAX_CREATURE_SIZE
     if( num_mut + injected_code.GetSize() > MAX_CREATURE_SIZE ){
@@ -1484,7 +1484,7 @@
       // Build a list of the sites where mutations occured
       static int mut_sites[MAX_CREATURE_SIZE];
       for (int i = 0; i < num_mut; i++) {
-        mut_sites[i] = m_world->GetRandom().GetUInt(injected_code.GetSize() + 1);
+        mut_sites[i] = ctx.GetRandom().GetUInt(injected_code.GetSize() + 1);
       }
       // Sort the list
       qsort( (void*)mut_sites, num_mut, sizeof(int), &IntCompareFunction );
@@ -1499,7 +1499,7 @@
   
   // Delete Mutations (per site)
   if( organism->GetDelMutProb() > 0 ){
-    int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(),
+    int num_mut = ctx.GetRandom().GetRandBinomial(injected_code.GetSize(),
                                                        organism->GetDelMutProb());
     // If would make creature too small, delete down to MIN_CREATURE_SIZE
     if (injected_code.GetSize() - num_mut < MIN_CREATURE_SIZE) {
@@ -1508,7 +1508,7 @@
     
     // If we have lines to delete...
     for (int i = 0; i < num_mut; i++) {
-      int site = m_world->GetRandom().GetUInt(injected_code.GetSize());
+      int site = ctx.GetRandom().GetUInt(injected_code.GetSize());
       injected_code.Remove(site);
       //cpu_stats.mut_stats.delete_mut_count++;
     }
@@ -1517,7 +1517,7 @@
   // Mutations in the parent's genome
   if (organism->GetParentMutProb() > 0) {
     for (int i = 0; i < GetMemory(0).GetSize(); i++) {
-      if (organism->TestParentMut()) {
+      if (organism->TestParentMut(ctx)) {
         GetMemory(0)[i] = m_inst_set->GetRandomInst(ctx);
         //cpu_stats.mut_stats.parent_mut_line_count++;
       }
@@ -1564,17 +1564,17 @@
   
   if (child_fitness == 0.0) {
     // Fatal mutation... test for reversion.
-    if (m_world->GetRandom().P(organism->GetRevertFatal())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizeFatal())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertFatal())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizeFatal())) sterilize = true;
   } else if (child_fitness < neut_min) {
-    if (m_world->GetRandom().P(organism->GetRevertNeg())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertNeg())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
   } else if (child_fitness <= neut_max) {
-    if (m_world->GetRandom().P(organism->GetRevertNeut())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertNeut())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
   } else {
-    if (m_world->GetRandom().P(organism->GetRevertPos())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizePos())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertPos())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizePos())) sterilize = true;
   }
   
   // Ideally, we won't have reversions and sterilizations turned on at the
@@ -1624,7 +1624,7 @@
   }
 #endif
   
-  bool parent_alive = organism->ActivateDivide();
+  bool parent_alive = organism->ActivateDivide(ctx);
   
   //reset the memory of the memory space that has been divided off
   GetMemory(mem_space_used)=cGenome(ConvertToInstruction(mem_space_used)); 
@@ -1784,7 +1784,7 @@
   
   // Mutations only occur on the read, for the moment.
   int read_inst = 0;
-  if (organism->TestCopyMut()) {
+  if (organism->TestCopyMut(ctx)) {
     read_inst = m_inst_set->GetRandomInst(ctx).GetOp();
     cpu_stats.mut_stats.copy_mut_count++;  // @CAO, hope this is good!
   } else {
@@ -1840,7 +1840,7 @@
   
   // Do mutations.
   cInstruction read_inst = read_head.GetInst();
-  if (organism->TestCopyMut()) {
+  if (organism->TestCopyMut(ctx)) {
     read_inst = m_inst_set->GetRandomInst(ctx);
     cpu_stats.mut_stats.copy_mut_count++; 
     write_head.SetFlagMutated();
@@ -2141,7 +2141,7 @@
  {
    // Rotate to a random facing and then run the normal inject instruction
    const int num_neighbors = organism->GetNeighborhoodSize();
-   organism->Rotate(m_world->GetRandom().GetUInt(num_neighbors));
+   organism->Rotate(ctx.GetRandom().GetUInt(num_neighbors));
    Inst_Inject();
    return true;
  }

Modified: development/source/cpu/cHardware4Stack.h
===================================================================
--- development/source/cpu/cHardware4Stack.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/cpu/cHardware4Stack.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -97,7 +97,7 @@
   float inst_remainder; 
 
   
-  bool SingleProcess_PayCosts(const cInstruction & cur_inst);
+  bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction & cur_inst);
   bool SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction & cur_inst);
   
   

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/cpu/cHardwareCPU.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -11,6 +11,7 @@
 
 #include "cHardwareCPU.h"
 
+#include "cAvidaContext.h"
 #include "cCPUTestInfo.h"
 #include "functions.h"
 #include "cGenomeUtil.h"
@@ -470,10 +471,10 @@
     }
     
     // Find the instruction to be executed
-    const cInstruction & cur_inst = IP().GetInst();
+    const cInstruction& cur_inst = IP().GetInst();
     
     // Test if costs have been paid and it is okay to execute this now...
-    const bool exec = SingleProcess_PayCosts(cur_inst);
+    const bool exec = SingleProcess_PayCosts(ctx, cur_inst);
     
     // Now execute the instruction...
     if (exec == true) {
@@ -500,7 +501,7 @@
 // This method will test to see if all costs have been paid associated
 // with executing an instruction and only return true when that instruction
 // should proceed.
-bool cHardwareCPU::SingleProcess_PayCosts(const cInstruction & cur_inst)
+bool cHardwareCPU::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
 {
 #ifdef INSTRUCTION_COSTS
   assert(cur_inst.GetOp() < inst_cost.GetSize());
@@ -523,7 +524,7 @@
   
   // Prob of exec
   if ( m_inst_set->GetProbFail(cur_inst) > 0.0 ){
-    return !( m_world->GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
+    return !( ctx.GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
   }
 #endif
   return true;
@@ -531,7 +532,7 @@
 
 // This method will handle the actuall execution of an instruction
 // within single process, once that function has been finalized.
-bool cHardwareCPU::SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction & cur_inst) 
+bool cHardwareCPU::SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst) 
 {
   // Copy Instruction locally to handle stochastic effects
   cInstruction actual_inst = cur_inst;
@@ -1062,10 +1063,10 @@
 int cHardwareCPU::PointMutate(cAvidaContext& ctx, const double mut_rate)
 {
   const int num_muts =
-  m_world->GetRandom().GetRandBinomial(GetMemory().GetSize(), mut_rate);
+  ctx.GetRandom().GetRandBinomial(GetMemory().GetSize(), mut_rate);
   
   for (int i = 0; i < num_muts; i++) {
-    const int pos = m_world->GetRandom().GetUInt(GetMemory().GetSize());
+    const int pos = ctx.GetRandom().GetUInt(GetMemory().GetSize());
     Mutate(ctx, pos);
   }
   
@@ -1145,11 +1146,11 @@
   // The rate we have stored indicates the probability that a single
   // mutation will occur anywhere in the genome.
   
-  if (m_world->GetRandom().P(rate) == true) {
+  if (ctx.GetRandom().P(rate) == true) {
     // We must create a temporary head and use it to randomly determine the
     // position in the genome to be mutated.
     cHeadCPU tmp_head(cur_head);
-    tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
+    tmp_head.AbsSet(ctx.GetRandom().GetUInt(target_memory.GetSize()));
     TriggerMutations_Body(ctx, cur_mut->GetType(), target_memory, tmp_head);
     return true;
   }
@@ -1162,7 +1163,7 @@
   // The rate we have stored is the probability for a mutation at this single
   // position in the genome.
   
-  if (m_world->GetRandom().P(rate) == true) {
+  if (ctx.GetRandom().P(rate) == true) {
     TriggerMutations_Body(ctx, cur_mut->GetType(), target_memory, cur_head);
     return true;
   }
@@ -1177,12 +1178,12 @@
   // that should occur.
   
   const int num_mut =
-  m_world->GetRandom().GetRandBinomial(target_memory.GetSize(), rate);
+  ctx.GetRandom().GetRandBinomial(target_memory.GetSize(), rate);
   
   if (num_mut > 0) {
     for (int i = 0; i < num_mut; i++) {
       cHeadCPU tmp_head(cur_head);
-      tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
+      tmp_head.AbsSet(ctx.GetRandom().GetUInt(target_memory.GetSize()));
       TriggerMutations_Body(ctx, cur_mut->GetType(), target_memory, tmp_head);
     }
   }
@@ -1521,11 +1522,11 @@
     bool sterilize = false;
     
     if (fitness_ratio < nHardware::FITNESS_NEUTRAL_MIN) {
-      if (m_world->GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
+      if (ctx.GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
     } else if (fitness_ratio <= nHardware::FITNESS_NEUTRAL_MAX) {
-      if (m_world->GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
+      if (ctx.GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
     } else {
-      if (m_world->GetRandom().P(organism->GetSterilizePos())) sterilize = true;
+      if (ctx.GetRandom().P(organism->GetSterilizePos())) sterilize = true;
     }
     
     if (sterilize == true) {
@@ -1547,34 +1548,34 @@
   organism->GetPhenotype().SetDivType(mut_multiplier);
   
   // Divide Mutations
-  if (organism->TestDivideMut()) {
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
+  if (organism->TestDivideMut(ctx)) {
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize());
     child_genome[mut_line] = m_inst_set->GetRandomInst(ctx);
     cpu_stats.mut_stats.divide_mut_count++;
   }
   
   // Divide Insertions
-  if (organism->TestDivideIns() && child_genome.GetSize() < MAX_CREATURE_SIZE){
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
+  if (organism->TestDivideIns(ctx) && child_genome.GetSize() < MAX_CREATURE_SIZE){
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize() + 1);
     child_genome.Insert(mut_line, m_inst_set->GetRandomInst(ctx));
     cpu_stats.mut_stats.divide_insert_mut_count++;
   }
   
   // Divide Deletions
-  if (organism->TestDivideDel() && child_genome.GetSize() > MIN_CREATURE_SIZE){
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
+  if (organism->TestDivideDel(ctx) && child_genome.GetSize() > MIN_CREATURE_SIZE){
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize());
     child_genome.Remove(mut_line);
     cpu_stats.mut_stats.divide_delete_mut_count++;
   }
   
   // Divide Mutations (per site)
   if(organism->GetDivMutProb() > 0){
-    int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(), 
+    int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(), 
                                                        organism->GetDivMutProb() / mut_multiplier);
     // If we have lines to mutate...
     if( num_mut > 0 ){
       for (int i = 0; i < num_mut; i++) {
-        int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
+        int site = ctx.GetRandom().GetUInt(child_genome.GetSize());
         child_genome[site] = m_inst_set->GetRandomInst(ctx);
         cpu_stats.mut_stats.div_mut_count++;
       }
@@ -1584,7 +1585,7 @@
   
   // Insert Mutations (per site)
   if(organism->GetInsMutProb() > 0){
-    int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
+    int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(),
                                                        organism->GetInsMutProb());
     // If would make creature to big, insert up to MAX_CREATURE_SIZE
     if( num_mut + child_genome.GetSize() > MAX_CREATURE_SIZE ){
@@ -1595,7 +1596,7 @@
       // Build a list of the sites where mutations occured
       static int mut_sites[MAX_CREATURE_SIZE];
       for (int i = 0; i < num_mut; i++) {
-        mut_sites[i] = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
+        mut_sites[i] = ctx.GetRandom().GetUInt(child_genome.GetSize() + 1);
       }
       // Sort the list
       qsort( (void*)mut_sites, num_mut, sizeof(int), &IntCompareFunction );
@@ -1610,7 +1611,7 @@
   
   // Delete Mutations (per site)
   if( organism->GetDelMutProb() > 0 ){
-    int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
+    int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(),
                                                        organism->GetDelMutProb());
     // If would make creature too small, delete down to MIN_CREATURE_SIZE
     if (child_genome.GetSize() - num_mut < MIN_CREATURE_SIZE) {
@@ -1619,7 +1620,7 @@
     
     // If we have lines to delete...
     for (int i = 0; i < num_mut; i++) {
-      int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
+      int site = ctx.GetRandom().GetUInt(child_genome.GetSize());
       child_genome.Remove(site);
       cpu_stats.mut_stats.delete_mut_count++;
     }
@@ -1628,7 +1629,7 @@
   // Mutations in the parent's genome
   if (organism->GetParentMutProb() > 0) {
     for (int i = 0; i < GetMemory().GetSize(); i++) {
-      if (organism->TestParentMut()) {
+      if (organism->TestParentMut(ctx)) {
         GetMemory()[i] = m_inst_set->GetRandomInst(ctx);
         cpu_stats.mut_stats.parent_mut_line_count++;
       }
@@ -1687,17 +1688,17 @@
   
   if (child_fitness == 0.0) {
     // Fatal mutation... test for reversion.
-    if (m_world->GetRandom().P(organism->GetRevertFatal())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizeFatal())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertFatal())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizeFatal())) sterilize = true;
   } else if (child_fitness < neut_min) {
-    if (m_world->GetRandom().P(organism->GetRevertNeg())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertNeg())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
   } else if (child_fitness <= neut_max) {
-    if (m_world->GetRandom().P(organism->GetRevertNeut())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertNeut())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
   } else {
-    if (m_world->GetRandom().P(organism->GetRevertPos())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizePos())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertPos())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizePos())) sterilize = true;
   }
   
   // Ideally, we won't have reversions and sterilizations turned on at the
@@ -1751,7 +1752,7 @@
   
   // Activate the child, and do more work if the parent lives through the
   // birth.
-  bool parent_alive = organism->ActivateDivide();
+  bool parent_alive = organism->ActivateDivide(ctx);
   if (parent_alive) {
     if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset();
   }
@@ -2371,7 +2372,7 @@
   cHeadCPU to(this, GetRegister(nHardwareCPU::REG_AX) + GetRegister(nHardwareCPU::REG_BX));
   sCPUStats & cpu_stats = organism->CPUStats();
   
-  if (organism->TestCopyMut()) {
+  if (organism->TestCopyMut(ctx)) {
     to.SetInst(m_inst_set->GetRandomInst(ctx));
     to.SetFlagMutated();  // Mark this instruction as mutated...
     to.SetFlagCopyMut();  // Mark this instruction as copy mut...
@@ -2407,7 +2408,7 @@
   sCPUStats & cpu_stats = organism->CPUStats();
 
   // Change value on a mutation...
-  if (organism->TestCopyMut()) {
+  if (organism->TestCopyMut(ctx)) {
     to.SetInst(m_inst_set->GetRandomInst(ctx));
     to.SetFlagMutated();      // Mark this instruction as mutated...
     to.SetFlagCopyMut();      // Mark this instruction as copy mut...
@@ -2440,7 +2441,7 @@
   sCPUStats & cpu_stats = organism->CPUStats();
   
   // Change value on a mutation...
-  if (organism->TestCopyMut()) {
+  if (organism->TestCopyMut(ctx)) {
     to.SetInst(m_inst_set->GetRandomInst(ctx));
     to.SetFlagMutated();      // Mark this instruction as mutated...
     to.SetFlagCopyMut();      // Mark this instruction as copy mut...
@@ -2464,7 +2465,7 @@
   cHeadCPU to(this, GetRegister(nHardwareCPU::REG_AX) + GetRegister(nHardwareCPU::REG_BX));
   
   // Compare is dangerous -- it can cause mutations!
-  if (organism->TestCopyMut()) {
+  if (organism->TestCopyMut(ctx)) {
     to.SetInst(m_inst_set->GetRandomInst(ctx));
     to.SetFlagMutated();      // Mark this instruction as mutated...
     to.SetFlagCopyMut();      // Mark this instruction as copy mut...
@@ -2482,7 +2483,7 @@
   const cHeadCPU to(this, GetRegister(nHardwareCPU::REG_AX) + GetRegister(nHardwareCPU::REG_BX));
   
   // Allow for errors in this test...
-  if (organism->TestCopyMut()) {
+  if (organism->TestCopyMut(ctx)) {
     if (from.GetInst() != to.GetInst()) IP().Advance();
   } else {
     if (from.GetInst() == to.GetInst()) IP().Advance();
@@ -2542,7 +2543,7 @@
   // Perform Copy Mutations...
   if (organism->GetCopyMutProb() > 0) { // Skip this if no mutations....
     for (int i = 0; i < GetMemory().GetSize(); i++) {
-      if (organism->TestCopyMut()) {
+      if (organism->TestCopyMut(ctx)) {
         child_genome[i] = m_inst_set->GetRandomInst(ctx);
         //organism->GetPhenotype().IsMutated() = true;
       }
@@ -2564,7 +2565,7 @@
   
   if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) advance_ip = false;
   
-  organism->ActivateDivide();
+  organism->ActivateDivide(ctx);
   
   return true;
 }
@@ -2589,7 +2590,7 @@
 bool cHardwareCPU::Inst_Die(cAvidaContext& ctx)
 {
   const double die_prob = m_world->GetConfig().DIE_PROB.Get();
-  if(m_world->GetRandom().GetDouble() < die_prob) { organism->Die(); }
+  if(ctx.GetRandom().GetDouble() < die_prob) { organism->Die(); }
   return true; 
 }
 
@@ -2655,7 +2656,7 @@
 {
   // Rotate to a random facing and then run the normal inject instruction
   const int num_neighbors = organism->GetNeighborhoodSize();
-  organism->Rotate(m_world->GetRandom().GetUInt(num_neighbors));
+  organism->Rotate(ctx.GetRandom().GetUInt(num_neighbors));
   Inst_Inject(ctx);
   return true;
 }
@@ -2830,7 +2831,7 @@
   }
   
   // Turn to a random neighbor, get it, and turn back...
-  int neighbor_id = m_world->GetRandom().GetInt(organism->GetNeighborhoodSize());
+  int neighbor_id = ctx.GetRandom().GetInt(organism->GetNeighborhoodSize());
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
   cOrganism * neighbor = organism->GetNeighbor();
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
@@ -2853,7 +2854,7 @@
   const int num_neighbors = organism->GetNeighborhoodSize();
   
   // Turn to face a random neighbor
-  int neighbor_id = m_world->GetRandom().GetInt(num_neighbors);
+  int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
   cOrganism * neighbor = organism->GetNeighbor();
   
@@ -2896,7 +2897,7 @@
   const int num_neighbors = organism->GetNeighborhoodSize();
   
   // Turn to face a random neighbor
-  int neighbor_id = m_world->GetRandom().GetInt(num_neighbors);
+  int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
   cOrganism * neighbor = organism->GetNeighbor();
   
@@ -3238,7 +3239,7 @@
   
   // Mutations only occur on the read, for the moment.
   int read_inst = 0;
-  if (organism->TestCopyMut()) {
+  if (organism->TestCopyMut(ctx)) {
     read_inst = m_inst_set->GetRandomInst(ctx).GetOp();
     cpu_stats.mut_stats.copy_mut_count++;  // @CAO, hope this is good!
   } else {
@@ -3285,7 +3286,7 @@
   // Do mutations.
   cInstruction read_inst = read_head.GetInst();
   ReadInst(read_inst.GetOp());
-  if (organism->TestCopyMut()) {
+  if (organism->TestCopyMut(ctx)) {
     read_inst = m_inst_set->GetRandomInst(ctx);
     cpu_stats.mut_stats.copy_mut_count++; 
     write_head.SetFlagMutated();
@@ -3318,7 +3319,7 @@
   // Do mutations.
   cInstruction read_inst = read_head.GetInst();
   ReadInst(read_inst.GetOp());
-  if ( m_world->GetRandom().P(organism->GetCopyMutProb() / reduction) ) {
+  if ( ctx.GetRandom().P(organism->GetCopyMutProb() / reduction) ) {
     read_inst = m_inst_set->GetRandomInst(ctx);
     cpu_stats.mut_stats.copy_mut_count++; 
     write_head.SetFlagMutated();

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/cpu/cHardwareCPU.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -388,8 +388,8 @@
 
   // Internal Implementation
 
-  bool SingleProcess_PayCosts(const cInstruction & cur_inst);
-  bool SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction & cur_inst);
+  bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);
+  bool SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst);
   
   // --------  Stack Manipulation...  --------
   inline void StackPush(int value);

Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/cpu/cHardwareSMT.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -200,7 +200,7 @@
     const cInstruction & cur_inst = IP().GetInst();
 		
     // Test if costs have been paid and it is okay to execute this now...
-    const bool exec = SingleProcess_PayCosts(cur_inst);
+    const bool exec = SingleProcess_PayCosts(ctx, cur_inst);
 		
     // Now execute the instruction...
     if (exec == true) {
@@ -225,7 +225,7 @@
 // This method will test to see if all costs have been paid associated
 // with executing an instruction and only return true when that instruction
 // should proceed.
-bool cHardwareSMT::SingleProcess_PayCosts(const cInstruction & cur_inst)
+bool cHardwareSMT::SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst)
 {
 #ifdef INSTRUCTION_COSTS
   assert(cur_inst.GetOp() < inst_cost.GetSize());
@@ -248,7 +248,7 @@
 	
   // Prob of exec
   if ( m_inst_set->GetProbFail(cur_inst) > 0.0 ){
-    return !( m_world->GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
+    return !( ctx.GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
   }
 #endif
   return true;
@@ -713,7 +713,7 @@
   //************* CALL GOES HERE ******************//
   // spin around randomly (caution: possible organism dizziness)
   //const int num_neighbors = organism->GetNeighborhoodSize();
-  //for(unsigned int i=0; i<m_world->GetRandom().GetUInt(num_neighbors); i++)
+  //for(unsigned int i=0; i<ctx.GetRandom().GetUInt(num_neighbors); i++)
   //  organism->Rotate(1);
 	
   // If we don't have a host, stop here.
@@ -763,10 +763,10 @@
 
 int cHardwareSMT::PointMutate(cAvidaContext& ctx, const double mut_rate)
 {
-  const int num_muts = m_world->GetRandom().GetRandBinomial(m_mem_array[0].GetSize(), mut_rate);
+  const int num_muts = ctx.GetRandom().GetRandBinomial(m_mem_array[0].GetSize(), mut_rate);
 	
   for (int i = 0; i < num_muts; i++) {
-    const int pos = m_world->GetRandom().GetUInt(m_mem_array[0].GetSize());
+    const int pos = ctx.GetRandom().GetUInt(m_mem_array[0].GetSize());
     Mutate(ctx, pos);
   }
 	
@@ -846,11 +846,11 @@
   // The rate we have stored indicates the probability that a single
   // mutation will occur anywhere in the genome.
   
-  if (m_world->GetRandom().P(rate) == true) {
+  if (ctx.GetRandom().P(rate) == true) {
     // We must create a temporary head and use it to randomly determine the
     // position in the genome to be mutated.
     cHeadCPU tmp_head(cur_head);
-    tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
+    tmp_head.AbsSet(ctx.GetRandom().GetUInt(target_memory.GetSize()));
     TriggerMutations_Body(ctx, cur_mut->GetType(), target_memory, tmp_head);
     return true;
   }
@@ -863,7 +863,7 @@
   // The rate we have stored is the probability for a mutation at this single
   // position in the genome.
 	
-  if (m_world->GetRandom().P(rate) == true) {
+  if (ctx.GetRandom().P(rate) == true) {
     TriggerMutations_Body(ctx, cur_mut->GetType(), target_memory, cur_head);
     return true;
   }
@@ -878,12 +878,12 @@
   // that should occur.
 	
   const int num_mut =
-	m_world->GetRandom().GetRandBinomial(target_memory.GetSize(), rate);
+	ctx.GetRandom().GetRandBinomial(target_memory.GetSize(), rate);
 	
   if (num_mut > 0) {
     for (int i = 0; i < num_mut; i++) {
       cHeadCPU tmp_head(cur_head);
-      tmp_head.AbsSet(m_world->GetRandom().GetUInt(target_memory.GetSize()));
+      tmp_head.AbsSet(ctx.GetRandom().GetUInt(target_memory.GetSize()));
       TriggerMutations_Body(ctx, cur_mut->GetType(), target_memory, tmp_head);
     }
   }
@@ -1160,34 +1160,34 @@
   organism->GetPhenotype().SetDivType(mut_multiplier);
 	
   // Divide Mutations
-  if (organism->TestDivideMut()) {
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
+  if (organism->TestDivideMut(ctx)) {
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize());
     child_genome[mut_line] = m_inst_set->GetRandomInst(ctx);
     cpu_stats.mut_stats.divide_mut_count++;
   }
 	
   // Divide Insertions
-  if (organism->TestDivideIns() && child_genome.GetSize() < MAX_CREATURE_SIZE){
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
+  if (organism->TestDivideIns(ctx) && child_genome.GetSize() < MAX_CREATURE_SIZE){
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize() + 1);
     child_genome.Insert(mut_line, m_inst_set->GetRandomInst(ctx));
     cpu_stats.mut_stats.divide_insert_mut_count++;
   }
 	
   // Divide Deletions
-  if (organism->TestDivideDel() && child_genome.GetSize() > MIN_CREATURE_SIZE){
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(child_genome.GetSize());
+  if (organism->TestDivideDel(ctx) && child_genome.GetSize() > MIN_CREATURE_SIZE){
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize());
     child_genome.Remove(mut_line);
     cpu_stats.mut_stats.divide_delete_mut_count++;
   }
 	
   // Divide Mutations (per site)
   if(organism->GetDivMutProb() > 0){
-    int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(), 
+    int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(), 
 																					 organism->GetDivMutProb() / mut_multiplier);
     // If we have lines to mutate...
     if( num_mut > 0 ){
       for (int i = 0; i < num_mut; i++) {
-				int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
+				int site = ctx.GetRandom().GetUInt(child_genome.GetSize());
 				child_genome[site] = m_inst_set->GetRandomInst(ctx);
 				cpu_stats.mut_stats.div_mut_count++;
       }
@@ -1197,7 +1197,7 @@
 	
   // Insert Mutations (per site)
   if(organism->GetInsMutProb() > 0){
-    int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
+    int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(),
 																					 organism->GetInsMutProb());
     // If would make creature to big, insert up to MAX_CREATURE_SIZE
     if( num_mut + child_genome.GetSize() > MAX_CREATURE_SIZE ){
@@ -1208,7 +1208,7 @@
       // Build a list of the sites where mutations occured
       static int mut_sites[MAX_CREATURE_SIZE];
       for (int i = 0; i < num_mut; i++) {
-				mut_sites[i] = m_world->GetRandom().GetUInt(child_genome.GetSize() + 1);
+				mut_sites[i] = ctx.GetRandom().GetUInt(child_genome.GetSize() + 1);
       }
       // Sort the list
       qsort( (void*)mut_sites, num_mut, sizeof(int), &IntCompareFunction );
@@ -1223,7 +1223,7 @@
 	
   // Delete Mutations (per site)
   if( organism->GetDelMutProb() > 0 ){
-    int num_mut = m_world->GetRandom().GetRandBinomial(child_genome.GetSize(),
+    int num_mut = ctx.GetRandom().GetRandBinomial(child_genome.GetSize(),
 																					 organism->GetDelMutProb());
     // If would make creature too small, delete down to MIN_CREATURE_SIZE
     if (child_genome.GetSize() - num_mut < MIN_CREATURE_SIZE) {
@@ -1232,7 +1232,7 @@
 		
     // If we have lines to delete...
     for (int i = 0; i < num_mut; i++) {
-      int site = m_world->GetRandom().GetUInt(child_genome.GetSize());
+      int site = ctx.GetRandom().GetUInt(child_genome.GetSize());
       child_genome.Remove(site);
       cpu_stats.mut_stats.delete_mut_count++;
     }
@@ -1241,7 +1241,7 @@
   // Mutations in the parent's genome
   if (organism->GetParentMutProb() > 0) {
     for (int i = 0; i < m_mem_array[0].GetSize(); i++) {
-      if (organism->TestParentMut()) {
+      if (organism->TestParentMut(ctx)) {
 				m_mem_array[0][i] = m_inst_set->GetRandomInst(ctx);
 				cpu_stats.mut_stats.parent_mut_line_count++;
       }
@@ -1267,31 +1267,31 @@
   organism->GetPhenotype().SetDivType(mut_multiplier);
 	
   // Divide Mutations
-  if (organism->TestDivideMut()) {
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize());
+  if (organism->TestDivideMut(ctx)) {
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(injected_code.GetSize());
     injected_code[mut_line] = m_inst_set->GetRandomInst(ctx);
   }
 	
   // Divide Insertions
-  if (organism->TestDivideIns() && injected_code.GetSize() < MAX_CREATURE_SIZE){
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize() + 1);
+  if (organism->TestDivideIns(ctx) && injected_code.GetSize() < MAX_CREATURE_SIZE){
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(injected_code.GetSize() + 1);
     injected_code.Insert(mut_line, m_inst_set->GetRandomInst(ctx));
   }
 	
   // Divide Deletions
-  if (organism->TestDivideDel() && injected_code.GetSize() > MIN_CREATURE_SIZE){
-    const unsigned int mut_line = m_world->GetRandom().GetUInt(injected_code.GetSize());
+  if (organism->TestDivideDel(ctx) && injected_code.GetSize() > MIN_CREATURE_SIZE){
+    const unsigned int mut_line = ctx.GetRandom().GetUInt(injected_code.GetSize());
     injected_code.Remove(mut_line);
   }
 	
   // Divide Mutations (per site)
   if(organism->GetDivMutProb() > 0){
-    int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(), 
+    int num_mut = ctx.GetRandom().GetRandBinomial(injected_code.GetSize(), 
 																					 organism->GetDivMutProb() / mut_multiplier);
     // If we have lines to mutate...
     if( num_mut > 0 ){
       for (int i = 0; i < num_mut; i++) {
-				int site = m_world->GetRandom().GetUInt(injected_code.GetSize());
+				int site = ctx.GetRandom().GetUInt(injected_code.GetSize());
 				injected_code[site] = m_inst_set->GetRandomInst(ctx);
       }
     }
@@ -1300,7 +1300,7 @@
 	
   // Insert Mutations (per site)
   if(organism->GetInsMutProb() > 0){
-    int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(),
+    int num_mut = ctx.GetRandom().GetRandBinomial(injected_code.GetSize(),
 																					 organism->GetInsMutProb());
     // If would make creature to big, insert up to MAX_CREATURE_SIZE
     if( num_mut + injected_code.GetSize() > MAX_CREATURE_SIZE ){
@@ -1311,7 +1311,7 @@
       // Build a list of the sites where mutations occured
       static int mut_sites[MAX_CREATURE_SIZE];
       for (int i = 0; i < num_mut; i++) {
-				mut_sites[i] = m_world->GetRandom().GetUInt(injected_code.GetSize() + 1);
+				mut_sites[i] = ctx.GetRandom().GetUInt(injected_code.GetSize() + 1);
       }
       // Sort the list
       qsort( (void*)mut_sites, num_mut, sizeof(int), &IntCompareFunction );
@@ -1325,7 +1325,7 @@
 	
   // Delete Mutations (per site)
   if( organism->GetDelMutProb() > 0 ){
-    int num_mut = m_world->GetRandom().GetRandBinomial(injected_code.GetSize(),
+    int num_mut = ctx.GetRandom().GetRandBinomial(injected_code.GetSize(),
 																					 organism->GetDelMutProb());
     // If would make creature too small, delete down to MIN_CREATURE_SIZE
     if (injected_code.GetSize() - num_mut < MIN_CREATURE_SIZE) {
@@ -1334,7 +1334,7 @@
 		
     // If we have lines to delete...
     for (int i = 0; i < num_mut; i++) {
-      int site = m_world->GetRandom().GetUInt(injected_code.GetSize());
+      int site = ctx.GetRandom().GetUInt(injected_code.GetSize());
       injected_code.Remove(site);
     }
   }
@@ -1342,7 +1342,7 @@
   // Mutations in the parent's genome
   if (organism->GetParentMutProb() > 0) {
     for (int i = 0; i < m_mem_array[0].GetSize(); i++) {
-      if (organism->TestParentMut()) {
+      if (organism->TestParentMut(ctx)) {
 				m_mem_array[0][i] = m_inst_set->GetRandomInst(ctx);
       }
     }
@@ -1388,17 +1388,17 @@
   
   if (child_fitness == 0.0) {
     // Fatal mutation... test for reversion.
-    if (m_world->GetRandom().P(organism->GetRevertFatal())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizeFatal())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertFatal())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizeFatal())) sterilize = true;
   } else if (child_fitness < neut_min) {
-    if (m_world->GetRandom().P(organism->GetRevertNeg())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertNeg())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizeNeg())) sterilize = true;
   } else if (child_fitness <= neut_max) {
-    if (m_world->GetRandom().P(organism->GetRevertNeut())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertNeut())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizeNeut())) sterilize = true;
   } else {
-    if (m_world->GetRandom().P(organism->GetRevertPos())) revert = true;
-    if (m_world->GetRandom().P(organism->GetSterilizePos())) sterilize = true;
+    if (ctx.GetRandom().P(organism->GetRevertPos())) revert = true;
+    if (ctx.GetRandom().P(organism->GetSterilizePos())) sterilize = true;
   }
   
   // Ideally, we won't have reversions and sterilizations turned on at the
@@ -1447,7 +1447,7 @@
   }
 #endif
 	
-  bool parent_alive = organism->ActivateDivide();
+  bool parent_alive = organism->ActivateDivide(ctx);
 	
   //reset the memory of the memory space that has been divided off
   m_mem_array[mem_space_used] = cGenome("a"); 
@@ -1695,7 +1695,7 @@
 	
   // Mutations only occur on the read, for the moment.
   int read_inst = 0;
-  if (organism->TestCopyMut()) {
+  if (organism->TestCopyMut(ctx)) {
     read_inst = m_inst_set->GetRandomInst(ctx).GetOp();
     cpu_stats.mut_stats.copy_mut_count++;  // @CAO, hope this is good!
   } else {
@@ -1754,7 +1754,7 @@
 	
   // Do mutations.
   cInstruction read_inst = read_head.GetInst();
-  if (organism->TestCopyMut()) {
+  if (organism->TestCopyMut(ctx)) {
     read_inst = m_inst_set->GetRandomInst(ctx);
     cpu_stats.mut_stats.copy_mut_count++; 
     write_head.SetFlagMutated();

Modified: development/source/cpu/cHardwareSMT.h
===================================================================
--- development/source/cpu/cHardwareSMT.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/cpu/cHardwareSMT.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -91,7 +91,7 @@
 #endif
 
   
-  bool SingleProcess_PayCosts(const cInstruction& cur_inst);
+  bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);
   bool SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst);
   	
 

Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/cpu/cTestCPU.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -198,8 +198,8 @@
     receive_array[1] = 0x33083ee5;  // 00110011 00001000 00111110 11100101
     receive_array[2] = 0x5562eb41;  // 01010101 01100010 11101011 01000001
   } else {
-    m_world->GetEnvironment().SetupInputs(input_array);
-    m_world->GetEnvironment().SetupInputs(receive_array);
+    m_world->GetEnvironment().SetupInputs(ctx, input_array);
+    m_world->GetEnvironment().SetupInputs(ctx, receive_array);
   }
 
   if (cur_depth > test_info.max_depth) test_info.max_depth = cur_depth;
@@ -208,7 +208,7 @@
   if (test_info.org_array[cur_depth] != NULL) {
     delete test_info.org_array[cur_depth];
   }
-  test_info.org_array[cur_depth] = new cOrganism(m_world, genome);
+  test_info.org_array[cur_depth] = new cOrganism(m_world, ctx, genome);
   cOrganism & organism = *( test_info.org_array[cur_depth] );
   organism.SetOrgInterface(new cTestCPUInterface(this));
   organism.GetPhenotype().SetupInject(genome.GetSize());

Modified: development/source/cpu/cTestCPUInterface.cc
===================================================================
--- development/source/cpu/cTestCPUInterface.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/cpu/cTestCPUInterface.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -15,7 +15,7 @@
 #include "cTestCPU.h"
 
 
-bool cTestCPUInterface::Divide(cOrganism * parent, cGenome& child_genome)
+bool cTestCPUInterface::Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome)
 {
   parent->GetPhenotype().TestDivideReset(parent->GetGenome().GetSize());
   // @CAO in the future, we probably want to pass this child the test_cpu!

Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/cpu/cTestCPUInterface.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -32,7 +32,7 @@
   int GetCellID() { return -1; }
   void SetCellID(int in_id) { ; }
 
-  bool Divide(cOrganism* parent, cGenome& child_genome);
+  bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome);
   cOrganism* GetNeighbor();
   int GetNumNeighbors();
   void Rotate(int direction = 1);

Modified: development/source/main/cBirthChamber.cc
===================================================================
--- development/source/main/cBirthChamber.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cBirthChamber.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -10,6 +10,7 @@
 
 #include "cBirthChamber.h"
 
+#include "cAvidaContext.h"
 #include "tArray.h"
 #include "functions.h"
 #include "cClassificationManager.h"
@@ -35,19 +36,13 @@
   global_wait_entry.is_waiting = false;
 }
 
-cBirthChamber::~cBirthChamber()
+bool cBirthChamber::GetNeighborWaiting(const int & parent_id, int world_x, int world_y)
 {
-}
-
-bool cBirthChamber::GetNeighborWaiting(const int & parent_id,
-				       int world_x,
-				       int world_y)
-{
   for (int i=-1; i<=1; i++) {
     for (int j=-1; j<=1; j++) { 
       const int neighbor_id = GridNeighbor(parent_id, world_x, world_y, i, j);
       if (local_wait_entry[neighbor_id].is_waiting == true) {
-	return true;
+        return true;
       }
     }
   }
@@ -55,13 +50,11 @@
 }
 
 
-int cBirthChamber::PickRandRecGenome(const int & parent_id, 
-				     int world_x,
-				     int world_y)
+int cBirthChamber::PickRandRecGenome(cAvidaContext& ctx, const int& parent_id, int world_x, int world_y)
 {
   bool done = false; 
   while (done ==false) {
-    int test_neighbor = (int) m_world->GetRandom().GetUInt(9); 
+    int test_neighbor = (int) ctx.GetRandom().GetUInt(9); 
     int i = test_neighbor / 3 - 1; 
     int j = test_neighbor % 3 - 1;
     int test_loc = GridNeighbor(parent_id,world_x, world_y, i, j); 		
@@ -73,10 +66,7 @@
   return -1;
 }
 
-bool cBirthChamber::RegionSwap(cCPUMemory & genome0, 
-			       cCPUMemory & genome1,
-			       int start0, int end0, 
-			       int start1, int end1)
+bool cBirthChamber::RegionSwap(cCPUMemory& genome0, cCPUMemory& genome1, int start0, int end0, int start1, int end1)
 {
    assert( start0 >= 0  &&  start0 < genome0.GetSize() );
    assert( end0   >= 0  &&  end0   < genome0.GetSize() );
@@ -91,8 +81,8 @@
    int new_size1 = genome1.GetSize() - size1 + size0;
       
    // Don't Crossover if offspring will be illegal!!!
-   if( new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE ||
-       new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE ){
+   if (new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE ||
+       new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE) {
      return false;
    } 
 
@@ -101,12 +91,10 @@
      cGenome cross1 = cGenomeUtil::Crop(genome1, start1, end1);
      genome0.Replace(start0, size0, cross1);
      genome1.Replace(start1, size1, cross0);
-   }
-   else if (size0 > 0) {
+   } else if (size0 > 0) {
      cGenome cross0 = cGenomeUtil::Crop(genome0, start0, end0);
      genome1.Replace(start1, size1, cross0);
-   }
-   else if (size1 > 0) {
+   } else if (size1 > 0) {
      cGenome cross1 = cGenomeUtil::Crop(genome1, start1, end1);
      genome0.Replace(start0, size0, cross1);
    }
@@ -114,33 +102,25 @@
    return true;
 }
 
-bool cBirthChamber::GenomeSwap(cCPUMemory & genome0,
-	                       cCPUMemory & genome1,
-                  	       double & merit0,
-                  	       double & merit1)
+void cBirthChamber::GenomeSwap(cCPUMemory& genome0, cCPUMemory& genome1, double& merit0, double& merit1)
 {
-  cCPUMemory & genome0_tmp = genome0;
+  cCPUMemory& genome0_tmp = genome0;
   genome0 = genome1; 
   genome1 = genome0_tmp; 
 
-  double & merit0_tmp = merit0; 
+  double& merit0_tmp = merit0; 
   merit0 = merit1; 
   merit1 = merit0_tmp;
-
-	// This had no return value, added 9/23/2004 DMB
-  return true;
 }
 
 
-bool cBirthChamber::DoAsexBirth(const cGenome & child_genome,
-				cOrganism & parent,
-				tArray<cOrganism *> & child_array,
-				tArray<cMerit> & merit_array)
+bool cBirthChamber::DoAsexBirth(cAvidaContext& ctx, const cGenome& child_genome, cOrganism& parent,
+                                tArray<cOrganism*>& child_array, tArray<cMerit>& merit_array)
 {
   // This is asexual who doesn't need to wait in the birth chamber
   // just build the child and return.
   child_array.Resize(1);
-  child_array[0] = new cOrganism(m_world, child_genome);
+  child_array[0] = new cOrganism(m_world, ctx, child_genome);
   merit_array.Resize(1);
   merit_array[0] = parent.GetPhenotype().GetMerit();
 
@@ -160,16 +140,13 @@
   return true;
 }
 
-bool cBirthChamber::DoPairAsexBirth(const cBirthEntry & old_entry,
-				    const cGenome & new_genome,
-				    cOrganism & parent,
-				    tArray<cOrganism *> & child_array,
-				    tArray<cMerit> & merit_array)
+bool cBirthChamber::DoPairAsexBirth(cAvidaContext& ctx, const cBirthEntry& old_entry, const cGenome& new_genome,
+                                    cOrganism& parent, tArray<cOrganism*>& child_array, tArray<cMerit>& merit_array)
 {
   // Build both child organisms...
   child_array.Resize(2);
-  child_array[0] = new cOrganism(m_world, old_entry.genome);
-  child_array[1] = new cOrganism(m_world, new_genome);
+  child_array[0] = new cOrganism(m_world, ctx, old_entry.genome);
+  child_array[1] = new cOrganism(m_world, ctx, new_genome);
 
   // Setup the merits for both children...
   merit_array.Resize(2);
@@ -189,9 +166,7 @@
   return true;
 }
 
-cBirthChamber::cBirthEntry *
-  cBirthChamber::FindSexSizeWaiting(const cGenome & child_genome,
-				    cOrganism & parent)
+cBirthChamber::cBirthEntry* cBirthChamber::FindSexSizeWaiting(const cGenome& child_genome, cOrganism& parent)
 {
   const int child_length = child_genome.GetSize();
 
@@ -219,9 +194,7 @@
   return &( size_wait_entry[child_length] ); 
 }
 
-cBirthChamber::cBirthEntry *
-  cBirthChamber::FindSexMateSelectWaiting(const cGenome & child_genome,
-					  cOrganism & parent)
+cBirthChamber::cBirthEntry* cBirthChamber::FindSexMateSelectWaiting(const cGenome& child_genome, cOrganism& parent)
 {
   const int mate_id = parent.GetPhenotype().MateSelectID();
 
@@ -249,9 +222,8 @@
   return &( mate_select_wait_entry[mate_id] ); 
 }
 
-cBirthChamber::cBirthEntry *
-  cBirthChamber::FindSexLocalWaiting(const cGenome & child_genome,
-				   cOrganism & parent)
+cBirthChamber::cBirthEntry* cBirthChamber::FindSexLocalWaiting(cAvidaContext& ctx, const cGenome& child_genome,
+                                                               cOrganism& parent)
 {
   // Collect some info for building the child.
   const int world_x = m_world->GetConfig().WORLD_X.Get();
@@ -270,13 +242,11 @@
   }
 
   // There is already a child waiting -- do crossover between the two.
-  int found_location = PickRandRecGenome(parent_id, world_x, world_y);
+  int found_location = PickRandRecGenome(ctx, parent_id, world_x, world_y);
   return &( local_wait_entry[found_location] ); 
 }
 
-cBirthChamber::cBirthEntry *
-  cBirthChamber::FindSexDemeWaiting(const cGenome & child_genome,
-				   cOrganism & parent)
+cBirthChamber::cBirthEntry* cBirthChamber::FindSexDemeWaiting(const cGenome& child_genome, cOrganism& parent)
 {
   // Collect some info for building the child.
   const int world_x = m_world->GetConfig().WORLD_X.Get();
@@ -302,8 +272,7 @@
 
 }
 
-cBirthChamber::cBirthEntry * cBirthChamber::FindSexGlobalWaiting(const cGenome & child_genome,
-						  cOrganism & parent)
+cBirthChamber::cBirthEntry* cBirthChamber::FindSexGlobalWaiting(const cGenome& child_genome, cOrganism& parent)
 {
   // If no other child is waiting, store this one.
   if (global_wait_entry.is_waiting == false){
@@ -321,12 +290,11 @@
   return &global_wait_entry;
 }
 
-void cBirthChamber::DoBasicRecombination(cCPUMemory & genome0,
-					 cCPUMemory & genome1, 
-					 double & merit0, double & merit1)
+void cBirthChamber::DoBasicRecombination(cAvidaContext& ctx, cCPUMemory& genome0, cCPUMemory& genome1,
+                                         double& merit0, double& merit1)
 {
-  double start_frac = m_world->GetRandom().GetDouble();
-  double end_frac = m_world->GetRandom().GetDouble();
+  double start_frac = ctx.GetRandom().GetDouble();
+  double end_frac = ctx.GetRandom().GetDouble();
   if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
     
   // calculate the proportion of the genome  that will be swapped
@@ -351,15 +319,13 @@
   } 
 }
 
-void cBirthChamber::DoModularContRecombination(cCPUMemory & genome0,
-					       cCPUMemory & genome1, 
-					       double & merit0,
-					       double & merit1)
+void cBirthChamber::DoModularContRecombination(cAvidaContext& ctx, cCPUMemory& genome0, cCPUMemory& genome1,
+                                               double& merit0, double& merit1)
 {
   const int num_modules = m_world->GetConfig().MODULE_NUM.Get();
 
-  int start_module = (int) (m_world->GetRandom().GetDouble() * num_modules);
-  int end_module = (int) (m_world->GetRandom().GetDouble() * num_modules);
+  int start_module = (int) (ctx.GetRandom().GetDouble() * num_modules);
+  int end_module = (int) (ctx.GetRandom().GetDouble() * num_modules);
 
   double start_frac = ((double) start_module) / (double) num_modules;
   double end_frac = ((double) end_module) / (double) num_modules;
@@ -388,16 +354,14 @@
   } 
 }
 
-void cBirthChamber::DoModularNonContRecombination(cCPUMemory & genome0,
-						  cCPUMemory & genome1, 
-						  double & merit0,
-						  double & merit1)
+void cBirthChamber::DoModularNonContRecombination(cAvidaContext& ctx, cCPUMemory& genome0, cCPUMemory& genome1,
+                                                  double& merit0, double& merit1)
 {
   const int num_modules = m_world->GetConfig().MODULE_NUM.Get();
 
   int swap_count = 0;
   for (int i = 0; i < num_modules; i++) {
-    if (m_world->GetRandom().GetDouble() < 0.5) {
+    if (ctx.GetRandom().GetDouble() < 0.5) {
       swap_count++;
       double start_frac = ((double) i) / (double) num_modules;
       double end_frac = ((double) i+1) / (double) num_modules;
@@ -424,10 +388,8 @@
   } 
 }
 
-void cBirthChamber::DoModularShuffleRecombination(cCPUMemory & genome0,
-						  cCPUMemory & genome1, 
-						  double & merit0,
-						  double & merit1)
+void cBirthChamber::DoModularShuffleRecombination(cAvidaContext& ctx, cCPUMemory& genome0, cCPUMemory& genome1,
+                                                   double& merit0, double& merit1)
 {
   const int num_modules = m_world->GetConfig().MODULE_NUM.Get();
   tArray<bool> swapped_region(num_modules);
@@ -435,7 +397,7 @@
 
   int swap_count = 0;
   for (int mod0 = 0; mod0 < num_modules; mod0++) {
-    if (m_world->GetRandom().GetDouble() < 0.5) {
+    if (ctx.GetRandom().GetDouble() < 0.5) {
       swap_count++;
 
       // Collect start and end info for current module
@@ -445,9 +407,9 @@
       int end0   = (int) (end0_frac * (double) genome0.GetSize());
 
       // Pick module from other genome...
-      int mod1 = m_world->GetRandom().GetUInt(num_modules);
+      int mod1 = ctx.GetRandom().GetUInt(num_modules);
       while (swapped_region[mod1] == true) {
-	mod1 = m_world->GetRandom().GetUInt(num_modules);
+        mod1 = ctx.GetRandom().GetUInt(num_modules);
       }
       swapped_region[mod1] = true;
 
@@ -491,15 +453,13 @@
   child_genotype->IncDeferAdjust();
 }
 
-bool cBirthChamber::SubmitOffspring(const cGenome & child_genome,
-				    cOrganism & parent,
-				    tArray<cOrganism *> & child_array,
-				    tArray<cMerit> & merit_array)
+bool cBirthChamber::SubmitOffspring(cAvidaContext& ctx, const cGenome& child_genome, cOrganism& parent,
+                                    tArray<cOrganism*>& child_array, tArray<cMerit>& merit_array)
 {
-  cPhenotype & parent_phenotype = parent.GetPhenotype();
+  cPhenotype& parent_phenotype = parent.GetPhenotype();
 
   if (parent_phenotype.DivideSex() == false) {
-    return DoAsexBirth(child_genome, parent, child_array, merit_array);
+    return DoAsexBirth(ctx, child_genome, parent, child_array, merit_array);
   }
 
   // If we make it this far, this must be a sexual or a "waiting" asexual
@@ -511,7 +471,7 @@
   cBirthEntry * old_entry = NULL;
   // First check if the birth method is one of the local ones... 
   if (birth_method < NUM_LOCAL_POSITION_CHILD) { 
-    old_entry = FindSexLocalWaiting(child_genome, parent);
+    old_entry = FindSexLocalWaiting(ctx, child_genome, parent);
   }
   // ... then check if population is split into demes
   else if (birth_method == POSITION_CHILD_DEME_RANDOM) {
@@ -544,9 +504,8 @@
 
   // If we are NOT recombining, handle that here.
   if (parent_phenotype.CrossNum() == 0 || 
-      m_world->GetRandom().GetDouble() > m_world->GetConfig().RECOMBINATION_PROB.Get()) {
-    return DoPairAsexBirth(*old_entry, child_genome, parent, 
-			   child_array, merit_array);
+      ctx.GetRandom().GetDouble() > m_world->GetConfig().RECOMBINATION_PROB.Get()) {
+    return DoPairAsexBirth(ctx, *old_entry, child_genome, parent, child_array, merit_array);
   }
 
   // If we made it this far, RECOMBINATION will happen!
@@ -567,22 +526,22 @@
 
   // If we are NOT modular...
   if (num_modules == 0) {
-    DoBasicRecombination(genome0, genome1, merit0, merit1);
+    DoBasicRecombination(ctx, genome0, genome1, merit0, merit1);
   }
 
   // If we ARE modular, and continuous...
   else if (continuous_regions == 1) {
-    DoModularContRecombination(genome0, genome1, merit0, merit1);
+    DoModularContRecombination(ctx, genome0, genome1, merit0, merit1);
   }
 
   // If we are NOT continuous, but NO shuffling...
   else if (shuffle_regions == 0) {
-    DoModularNonContRecombination(genome0, genome1, merit0, merit1);
+    DoModularNonContRecombination(ctx, genome0, genome1, merit0, merit1);
   }
 
   // If there IS shuffling (NON-continuous required)
   else {
-    DoModularShuffleRecombination(genome0, genome1, merit0, merit1);
+    DoModularShuffleRecombination(ctx, genome0, genome1, merit0, merit1);
   }
 
   // Should there be a 2-fold cost to sex?
@@ -594,8 +553,8 @@
 
   if (two_fold_cost == 0) {	// Build the two organisms.
     child_array.Resize(2);
-    child_array[0] = new cOrganism(m_world, genome0);
-    child_array[1] = new cOrganism(m_world, genome1);
+    child_array[0] = new cOrganism(m_world, ctx, genome0);
+    child_array[1] = new cOrganism(m_world, ctx, genome1);
     
     merit_array.Resize(2);
     merit_array[0] = merit0;
@@ -610,15 +569,15 @@
     child_array.Resize(1);
     merit_array.Resize(1);
 
-    if (m_world->GetRandom().GetDouble() < 0.5) {
-      child_array[0] = new cOrganism(m_world, genome0);
+    if (ctx.GetRandom().GetDouble() < 0.5) {
+      child_array[0] = new cOrganism(m_world, ctx, genome0);
       merit_array[0] = merit0;
 
       // Setup the genotype for the child...
       SetupGenotypeInfo(child_array[0], parent0_genotype, parent1_genotype);
     } 
     else {
-      child_array[0] = new cOrganism(m_world, genome1);
+      child_array[0] = new cOrganism(m_world, ctx, genome1);
       merit_array[0] = merit1;
 
       // Setup the genotype for the child...

Modified: development/source/main/cBirthChamber.h
===================================================================
--- development/source/main/cBirthChamber.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cBirthChamber.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -26,6 +26,7 @@
  * over before they are born.
  **/
 
+class cAvidaContext;
 class cGenome;
 class cGenotype;
 class cOrganism;
@@ -59,45 +60,48 @@
 
   // Private methods...
   bool RegionSwap(cCPUMemory& genome0, cCPUMemory& genome1, int start0, int end0, int start1, int end1);
-  bool GenomeSwap(cCPUMemory& genome0, cCPUMemory& genome1, double& merit0, double& merit1);
+  void GenomeSwap(cCPUMemory& genome0, cCPUMemory& genome1, double& merit0, double& merit1);
 
-  bool DoAsexBirth(const cGenome& child_genome, cOrganism& parent,
+  bool DoAsexBirth(cAvidaContext& ctx, const cGenome& child_genome, cOrganism& parent,
                    tArray<cOrganism*>& child_array, tArray<cMerit>& merit_array);
-  bool DoPairAsexBirth(const cBirthEntry& old_entry, const cGenome& new_genome, cOrganism& parent,
+  bool DoPairAsexBirth(cAvidaContext& ctx, const cBirthEntry& old_entry, const cGenome& new_genome, cOrganism& parent,
                        tArray<cOrganism*>& child_array, tArray<cMerit>& merit_array);
-  cBirthEntry* FindSexLocalWaiting(const cGenome& child_genome, cOrganism& parent);
+  cBirthEntry* FindSexLocalWaiting(cAvidaContext& ctx, const cGenome& child_genome, cOrganism& parent);
   cBirthEntry* FindSexDemeWaiting(const cGenome& child_genome, cOrganism& parent);
   cBirthEntry* FindSexSizeWaiting(const cGenome & child_genome, cOrganism& parent);
   cBirthEntry* FindSexMateSelectWaiting(const cGenome & child_genome, cOrganism& parent);
   cBirthEntry* FindSexGlobalWaiting(const cGenome & child_genome, cOrganism& parent);
 
-  void DoBasicRecombination(cCPUMemory& genome0, cCPUMemory& genome1, double& merit0, double& merit1);
-  void DoModularContRecombination(cCPUMemory& genome0, cCPUMemory& genome1, double& merit0, double& merit1);
-  void DoModularNonContRecombination(cCPUMemory& genome0, cCPUMemory& genome1, double& merit0, double& merit1);
-  void DoModularShuffleRecombination(cCPUMemory& genome0, cCPUMemory& genome1, double& merit0, double& merit1);
+  void DoBasicRecombination(cAvidaContext& ctx, cCPUMemory& genome0, cCPUMemory& genome1,
+                            double& merit0, double& merit1);
+  void DoModularContRecombination(cAvidaContext& ctx, cCPUMemory& genome0, cCPUMemory& genome1,
+                                  double& merit0, double& merit1);
+  void DoModularNonContRecombination(cAvidaContext& ctx, cCPUMemory& genome0, cCPUMemory& genome1,
+                                     double& merit0, double& merit1);
+  void DoModularShuffleRecombination(cAvidaContext& ctx, cCPUMemory& genome0, cCPUMemory& genome1,
+                                     double& merit0, double& merit1);
 
   void SetupGenotypeInfo(cOrganism* organism, cGenotype* parent0_genotype, cGenotype* parent1_genotype);
 
+  // Pick a random waiting genome from the nehighborhood for recombination
+  int PickRandRecGenome(cAvidaContext& ctx, const int & parent_id, int world_x, int world_y);
+  
+
   cBirthChamber(); // @not_implemented
   cBirthChamber(const cBirthChamber&); // @not_implemented
   cBirthChamber& operator=(const cBirthChamber&); // @not_implemented
   
 public:
   cBirthChamber(cWorld* world);
-  ~cBirthChamber();
+  ~cBirthChamber() { ; }
 
   // Handle manipulations & tests of genome.  Return false if divide process
   // should halt.  Place offspring in child_array.
-  bool SubmitOffspring(const cGenome & child_genome, cOrganism & parent,
-		       tArray<cOrganism *> & child_array,
-		       tArray<cMerit> & merit_array);
+  bool SubmitOffspring(cAvidaContext& ctx, const cGenome& child_genome, cOrganism& parent,
+                       tArray<cOrganism*>& child_array, tArray<cMerit>& merit_array);
 
   // Check the neighborhood for waiting genomes
   bool GetNeighborWaiting(const int & parent_id, int world_x, int world_y);
-
-  // Pick a random waiting genome from the nehighborhood for recombination
-  int PickRandRecGenome(const int & parent_id, int world_x, int world_y);
-
 };
 
 #endif

Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cEnvironment.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -10,6 +10,7 @@
 
 #include "cEnvironment.h"
 
+#include "cAvidaContext.h"
 #include "cHardwareManager.h"
 #include "cInitFile.h"
 #include "nMutation.h"
@@ -28,8 +29,7 @@
 using namespace std;
 
 
-bool cEnvironment::ParseSetting(cString entry, cString & var_name,
-                                cString & var_value, const cString & var_type)
+bool cEnvironment::ParseSetting(cString entry, cString& var_name, cString& var_value, const cString& var_type)
 {
   // Make sure we have an actual entry to parse.
   if (entry.GetSize() == 0) {
@@ -626,7 +626,7 @@
 }
 
 
-void cEnvironment::SetupInputs( tArray<int> & input_array ) const
+void cEnvironment::SetupInputs(cAvidaContext& ctx, tArray<int>& input_array) const
 {
   input_array.Resize(3);
   
@@ -637,34 +637,32 @@
   
   // And randomize the rest...
   for (int i = 0; i < 3; i++) {
-    input_array[i] += m_world->GetRandom().GetUInt(1 << 24);
+    input_array[i] += ctx.GetRandom().GetUInt(1 << 24);
   }
 }
 
 
-bool cEnvironment::TestInput( cReactionResult & result,
-                              const tBuffer<int> & inputs,
-                              const tBuffer<int> & outputs,
-                              const tArray<double> & resource_count ) const
+bool cEnvironment::TestInput(cReactionResult& result, const tBuffer<int>& inputs,
+                             const tBuffer<int>& outputs, const tArray<double>& resource_count ) const
 {
   // @CAO nothing for the moment...
   return false;
 }
 
 
-bool cEnvironment::TestOutput( cReactionResult & result,
-                               const tBuffer<int> & input_buf,
-                               const tBuffer<int> & output_buf,
-                               const tBuffer<int> & send_buf,
-                               const tBuffer<int> & receive_buf,
-                               const tArray<int> & task_count,
-                               const tArray<int> & reaction_count,
-                               const tArray<double> & resource_count,
-                               const tList< tBuffer<int> > & input_buffers,
-                               const tList< tBuffer<int> > & output_buffers) const
+bool cEnvironment::TestOutput(cAvidaContext& ctx, cReactionResult& result,
+                              const tBuffer<int>& input_buf,
+                              const tBuffer<int>& output_buf,
+                              const tBuffer<int>& send_buf,
+                              const tBuffer<int>& receive_buf,
+                              const tArray<int>& task_count,
+                              const tArray<int>& reaction_count,
+                              const tArray<double>& resource_count,
+                              const tList< tBuffer<int> >& input_buffers,
+                              const tList< tBuffer<int> >& output_buffers) const
 {
   // Do setup for reaction tests...
-  cTaskContext* taskctx = task_lib.SetupTests(input_buf, output_buf, input_buffers, output_buffers);
+  cTaskContext taskctx = task_lib.SetupTests(input_buf, output_buf, input_buffers, output_buffers);
   
   // Loop through all reactions to see if any have been triggered...
   const int num_reactions = reaction_lib.GetSize();
@@ -678,7 +676,7 @@
     // Examine the task trigger associated with this reaction
     cTaskEntry * cur_task = cur_reaction->GetTask();
     assert(cur_task != NULL);
-    const double task_quality = task_lib.TestOutput(*cur_task, taskctx);
+    const double task_quality = task_lib.TestOutput(*cur_task, &taskctx);
     const int task_id = cur_task->GetID();
     
     // If this task wasn't performed, move on to the next one.
@@ -693,19 +691,17 @@
     }
     
     // And lets process it!
-    DoProcesses(cur_reaction->GetProcesses(), resource_count, task_quality, result);
+    DoProcesses(ctx, cur_reaction->GetProcesses(), resource_count, task_quality, result);
     
     // Mark this reaction as occuring...
     result.MarkReaction(cur_reaction->GetID());
   }
   
-  delete taskctx;
-
   // Loop again to check receive tasks...
   // if (receive_buf.GetSize() != 0)
   {
     // Do setup for reaction tests...
-    taskctx = task_lib.SetupTests(receive_buf, output_buf, input_buffers, output_buffers);
+    cTaskContext taskctx = task_lib.SetupTests(receive_buf, output_buf, input_buffers, output_buffers);
     
     for (int i = 0; i < num_reactions; i++) {
       cReaction * cur_reaction = reaction_lib.GetReaction(i);
@@ -717,7 +713,7 @@
       // Examine the task trigger associated with this reaction
       cTaskEntry * cur_task = cur_reaction->GetTask();
       assert(cur_task != NULL);
-      const double task_quality = task_lib.TestOutput(*cur_task, taskctx);
+      const double task_quality = task_lib.TestOutput(*cur_task, &taskctx);
       const int task_id = cur_task->GetID();
       
       // If this task wasn't performed, move on to the next one.
@@ -726,7 +722,6 @@
       // Mark this task as performed...
       result.MarkReceiveTask(task_id);
     }
-    delete taskctx;
   }
   
   
@@ -783,10 +778,9 @@
 }
 
 
-void cEnvironment::DoProcesses(const tList<cReactionProcess> & process_list,
-                               const tArray<double> & resource_count,
-                               const double task_quality,
-                               cReactionResult & result) const
+void cEnvironment::DoProcesses(cAvidaContext& ctx, const tList<cReactionProcess>& process_list,
+                               const tArray<double>& resource_count, const double task_quality,
+                               cReactionResult& result) const
 {
   const int num_process = process_list.GetSize();
   
@@ -845,12 +839,11 @@
     };
     
     // Determine detection events
-    cResource * detected = cur_process->GetDetect();
+    cResource* detected = cur_process->GetDetect();
     if (detected != NULL) {
       const int detected_id = detected->GetID();
       const double real_amount = resource_count[detected_id];
-      double estimated_amount =
-        m_world->GetRandom().GetRandNormal(real_amount, cur_process->GetDetectionError()*real_amount);
+      double estimated_amount = ctx.GetRandom().GetRandNormal(real_amount, cur_process->GetDetectionError() * real_amount);
       if (estimated_amount < cur_process->GetDetectionThreshold()) {
         result.Detect(detected_id, 0.0);		
       } else {
@@ -859,7 +852,7 @@
     }
     
     // Determine byproducts
-    cResource * product = cur_process->GetProduct();
+    cResource* product = cur_process->GetProduct();
     if (product != NULL) {
       int product_id = product->GetID();
       double product_size = consumed * cur_process->GetConversion();
@@ -876,24 +869,24 @@
   }
 }
 
-double cEnvironment::GetReactionValue(int & reaction_id)
+double cEnvironment::GetReactionValue(int& reaction_id)
 {
-  cReaction * found_reaction = reaction_lib.GetReaction(reaction_id);
+  cReaction* found_reaction = reaction_lib.GetReaction(reaction_id);
   if (found_reaction == NULL) return false;
   return found_reaction->GetValue();
 }
 
-bool cEnvironment::SetReactionValue(const cString & name, double value)
+bool cEnvironment::SetReactionValue(const cString& name, double value)
 {
-  cReaction * found_reaction = reaction_lib.GetReaction(name);
+  cReaction* found_reaction = reaction_lib.GetReaction(name);
   if (found_reaction == NULL) return false;
   found_reaction->ModifyValue(value);
   return true;
 }
 
-bool cEnvironment::SetReactionValueMult(const cString & name, double value_mult)
+bool cEnvironment::SetReactionValueMult(const cString& name, double value_mult)
 {
-  cReaction * found_reaction = reaction_lib.GetReaction(name);
+  cReaction* found_reaction = reaction_lib.GetReaction(name);
   if (found_reaction == NULL) return false;
   found_reaction->MultiplyValue(value_mult);
   return true;

Modified: development/source/main/cEnvironment.h
===================================================================
--- development/source/main/cEnvironment.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cEnvironment.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -36,6 +36,7 @@
 #include "tList.h"
 #endif
 
+class cAvidaContext;
 class cReaction;
 class cReactionRequisite;
 template <class T> class tArray;
@@ -71,7 +72,7 @@
   bool LoadSetActive(cString desc);
 
   bool TestRequisites(const tList<cReactionRequisite>& req_list, int task_count, const tArray<int>& reaction_count) const;
-  void DoProcesses(const tList<cReactionProcess>& process_list, const tArray<double>& resource_count,
+  void DoProcesses(cAvidaContext& ctx, const tList<cReactionProcess>& process_list, const tArray<double>& resource_count,
                    const double task_quality, cReactionResult& result) const;
 
   cEnvironment(); // @not_implemented
@@ -79,7 +80,7 @@
   cEnvironment& operator=(const cEnvironment&); // @not_implemented
 
 public:
-  cEnvironment(cWorld* world) : m_world(world), inst_set(world), mut_rates(world) { ; }
+  cEnvironment(cWorld* world) : m_world(world), inst_set(world) { ; }
   ~cEnvironment() { ; }
 
   /**
@@ -93,23 +94,21 @@
   bool LoadLine(cString line);
 
   // Interaction with the organisms
-  void SetupInputs( tArray<int> & input_array ) const;
+  void SetupInputs(cAvidaContext& ctx, tArray<int>& input_array) const;
 
-  bool TestInput(  cReactionResult & result,
-		   const tBuffer<int> & inputs,
-		   const tBuffer<int> & outputs,
-		   const tArray<double> & resource_count ) const;
+  bool TestInput(cReactionResult& result, const tBuffer<int>& inputs,
+                 const tBuffer<int>& outputs, const tArray<double>& resource_count ) const;
 
-  bool TestOutput(  cReactionResult & result,
-		    const tBuffer<int> & input_buf,
-		    const tBuffer<int> & output_buf,
-		    const tBuffer<int> & send_buf,
-		    const tBuffer<int> & receive_buf,
-		    const tArray<int> & task_count,
-		    const tArray<int> & reaction_count,
-		    const tArray<double> & resource_count,
-		    const tList<tBuffer<int> > & other_inputs,
-		    const tList<tBuffer<int> > & other_outputs) const;
+  bool TestOutput(cAvidaContext& ctx, cReactionResult& result,
+		    const tBuffer<int>& input_buf,
+		    const tBuffer<int>& output_buf,
+		    const tBuffer<int>& send_buf,
+		    const tBuffer<int>& receive_buf,
+		    const tArray<int>& task_count,
+		    const tArray<int>& reaction_count,
+		    const tArray<double>& resource_count,
+		    const tList<tBuffer<int> >& other_inputs,
+		    const tList<tBuffer<int> >& other_outputs) const;
 
   // Accessors
   const cResourceLib & GetResourceLib() const { return resource_lib; }

Modified: development/source/main/cInstSet.cc
===================================================================
--- development/source/main/cInstSet.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cInstSet.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -70,7 +70,7 @@
 
 cInstruction cInstSet::GetRandomInst(cAvidaContext& ctx) const
 {
-  int inst_op = m_mutation_chart[m_world->GetRandom().GetUInt(m_mutation_chart.GetSize())];
+  int inst_op = m_mutation_chart[ctx.GetRandom().GetUInt(m_mutation_chart.GetSize())];
   return cInstruction(inst_op);
 }
 

Modified: development/source/main/cLandscape.cc
===================================================================
--- development/source/main/cLandscape.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cLandscape.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -309,11 +309,11 @@
     int test_id = 0;
     while ((test_id < min_tests) ||
            (test_id < max_tests && (total_neut_found + total_pos_found) < min_found)) {
-      m_world->GetRandom().Choose(genome_size, mut_lines);
+      ctx.GetRandom().Choose(genome_size, mut_lines);
       test_fitness = 1.0;
       for (int j = 0; j < num_muts && test_fitness != 0.0; j++) {	
         test_fitness *=
-        fitness_chart(mut_lines[j], m_world->GetRandom().GetUInt(inst_size));
+        fitness_chart(mut_lines[j], ctx.GetRandom().GetUInt(inst_size));
       }
       total_fitness += test_fitness;
       total_sqr_fitness += test_fitness * test_fitness;
@@ -438,12 +438,12 @@
     int test_id = 0;
     while ((test_id < min_tests) ||
            (test_id < max_tests && (total_neg_found + total_neut_found + total_pos_found) < min_found)) {
-      m_world->GetRandom().Choose(genome_size, mut_lines);
+      ctx.GetRandom().Choose(genome_size, mut_lines);
       test_fitness = 1.0;
       for (int j = 0; j < num_muts && test_fitness != 0.0; j++) {	
         int base_inst = base_genome[ mut_lines[j] ].GetOp();
-        int mut_inst = m_world->GetRandom().GetUInt(inst_size);
-        while (mut_inst == base_inst) mut_inst = m_world->GetRandom().GetUInt(inst_size);
+        int mut_inst = ctx.GetRandom().GetUInt(inst_size);
+        while (mut_inst == base_inst) mut_inst = ctx.GetRandom().GetUInt(inst_size);
         test_fitness *= fitness_chart(mut_lines[j], mut_inst);
         if (test_fitness == 0.0) break;
       }
@@ -553,7 +553,7 @@
   for (cur_trial = 0; cur_trial < in_trials; cur_trial++) { 
     
     // Choose the lines to mutate...
-    m_world->GetRandom().Choose(genome_size, mut_lines);
+    ctx.GetRandom().Choose(genome_size, mut_lines);
     
     // Choose the new instructions for those lines...
     for (mut_num = 0; mut_num < distance; mut_num++) {
@@ -634,7 +634,7 @@
   // Loop through all the lines of genome, testing many combinations.
   for (int i = 0; i < trials; i++) {
     // Choose the lines to mutate...
-    m_world->GetRandom().Choose(genome_size, mut_lines);
+    ctx.GetRandom().Choose(genome_size, mut_lines);
     
     // Choose the new instructions for those lines...
     for (int mut_num = 0; mut_num < 2; mut_num++) {

Modified: development/source/main/cMutationRates.cc
===================================================================
--- development/source/main/cMutationRates.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cMutationRates.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -10,9 +10,7 @@
 
 #include "cMutationRates.h"
 
-#include "cWorld.h"
 
-
 void cMutationRates::Clear()
 {
   exec.point_mut_prob = 0.0;
@@ -42,43 +40,3 @@
   divide.crossover_prob = in_muts.divide.crossover_prob;
   divide.aligned_cross_prob = in_muts.divide.aligned_cross_prob;
 }
-
-bool cMutationRates::TestPointMut() const
-{
-  return m_world->GetRandom().P(exec.point_mut_prob);
-}
-
-bool cMutationRates::TestCopyMut() const
-{
-  return m_world->GetRandom().P(copy.copy_mut_prob);
-}
-
-bool cMutationRates::TestDivideMut() const
-{
-  return m_world->GetRandom().P(divide.divide_mut_prob);
-}
-
-bool cMutationRates::TestDivideIns() const
-{
-  return m_world->GetRandom().P(divide.divide_ins_prob);
-}
-
-bool cMutationRates::TestDivideDel() const
-{
-  return m_world->GetRandom().P(divide.divide_del_prob);
-}
-
-bool cMutationRates::TestParentMut() const
-{
-  return m_world->GetRandom().P(divide.parent_mut_prob);
-}
-
-bool cMutationRates::TestCrossover() const
-{
-  return m_world->GetRandom().P(divide.crossover_prob);
-}
-
-bool cMutationRates::TestAlignedCrossover() const
-{
-  return m_world->GetRandom().P(divide.aligned_cross_prob);
-}

Modified: development/source/main/cMutationRates.h
===================================================================
--- development/source/main/cMutationRates.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cMutationRates.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -11,13 +11,17 @@
 #ifndef cMutationRates_h
 #define cMutationRates_h
 
-class cWorld;
+#ifndef cAvidaContext_h
+#include "cAvidaContext.h"
+#endif
+#ifndef cRandom_h
+#include "cRandom.h"
+#endif
 
+
 class cMutationRates
 {
 private:
-  cWorld* m_world;
-  
   // Mutations are divided up by when they occur...
 
   // ...anytime during execution...
@@ -47,25 +51,24 @@
   sDivideMuts divide;
   
   
-  cMutationRates(); // @not_implemented
   cMutationRates& operator=(const cMutationRates&); // @not_implemented
 
 public:
-  cMutationRates(cWorld* world) : m_world(world) { Clear(); }
-  cMutationRates(const cMutationRates& in_muts) : m_world(in_muts.m_world) { Copy(in_muts); }
+  cMutationRates() { Clear(); }
+  cMutationRates(const cMutationRates& in_muts) { Copy(in_muts); }
   ~cMutationRates() { ; }
 
   void Clear();
   void Copy(const cMutationRates & in_muts);
 
-  bool TestPointMut() const;
-  bool TestCopyMut() const;
-  bool TestDivideMut() const;
-  bool TestDivideIns() const;
-  bool TestDivideDel() const;
-  bool TestParentMut() const;
-  bool TestCrossover() const;
-  bool TestAlignedCrossover() const;
+  bool TestPointMut(cAvidaContext& ctx) const { return ctx.GetRandom().P(exec.point_mut_prob); }
+  bool TestCopyMut(cAvidaContext& ctx) const { return ctx.GetRandom().P(copy.copy_mut_prob); }
+  bool TestDivideMut(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.divide_mut_prob); }
+  bool TestDivideIns(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.divide_ins_prob); }
+  bool TestDivideDel(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.divide_del_prob); }
+  bool TestParentMut(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.parent_mut_prob); }
+  bool TestCrossover(cAvidaContext& ctx) const  { return ctx.GetRandom().P(divide.crossover_prob); }
+  bool TestAlignedCrossover(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.aligned_cross_prob); }
 
   double GetPointMutProb() const     { return exec.point_mut_prob; }
   double GetCopyMutProb() const      { return copy.copy_mut_prob; }

Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cOrgInterface.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -10,6 +10,7 @@
 #ifndef cOrgInterface_h
 #define cOrgInterface_h
 
+class cAvidaContext;
 class cOrganism;
 class cGenome;
 template <class T> class tArray;
@@ -28,7 +29,7 @@
   virtual int GetCellID() = 0;
   virtual void SetCellID(int in_id) = 0;
 
-  virtual bool Divide(cOrganism* parent, cGenome& child_genome) = 0;
+  virtual bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome) = 0;
   virtual cOrganism* GetNeighbor() = 0;
   virtual int GetNumNeighbors() = 0;
   virtual void Rotate(int direction = 1) = 0;

Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cOrganism.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -10,6 +10,7 @@
 
 #include "cOrganism.h"
 
+#include "cAvidaContext.h"
 #include "nHardware.h"
 #include "cEnvironment.h"
 #include "functions.h"
@@ -32,12 +33,11 @@
 using namespace std;
 
 
-cOrganism::cOrganism(cWorld* world, const cGenome& in_genome)
+cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome)
   : m_world(world)
   , genotype(NULL)
   , phenotype(world)
   , initial_genome(in_genome)
-  , mut_rates(world)
   , mut_info(world->GetEnvironment().GetMutationLib(), in_genome.GetSize())
   , m_interface(NULL)
   , input_pointer(0)
@@ -62,7 +62,7 @@
   if (m_world->GetConfig().DEATH_METHOD.Get() > 0) {
     max_executed = m_world->GetConfig().AGE_LIMIT.Get();
     if (m_world->GetConfig().AGE_DEVIATION.Get() > 0.0) {
-      max_executed += (int) (m_world->GetRandom().GetRandNormal() * m_world->GetConfig().AGE_DEVIATION.Get());
+      max_executed += (int) (ctx.GetRandom().GetRandNormal() * m_world->GetConfig().AGE_DEVIATION.Get());
     }
     if (m_world->GetConfig().DEATH_METHOD.Get() == DEATH_METHOD_MULTIPLE) {
       max_executed *= initial_genome.GetSize();
@@ -145,7 +145,7 @@
   output_buf.Add(value);
   tArray<double> res_change(resource_count.GetSize());
   tArray<int> insts_triggered;
-  phenotype.TestOutput(input_buf, output_buf, send_buf, receive_buf,
+  phenotype.TestOutput(ctx, input_buf, output_buf, send_buf, receive_buf,
 		       resource_count, res_change, insts_triggered,
 		       other_input_list, other_output_list);
   m_interface->UpdateResources(res_change);
@@ -279,11 +279,11 @@
 // This gets called after a successful divide to deal with the child. 
 // Returns true if parent lives through this process.
 
-bool cOrganism::ActivateDivide()
+bool cOrganism::ActivateDivide(cAvidaContext& ctx)
 {
   assert(m_interface);
   // Activate the child!  (Keep Last: may kill this organism!)
-  return m_interface->Divide(this, child_genome);
+  return m_interface->Divide(ctx, this, child_genome);
 }
 
 

Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cOrganism.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -102,7 +102,7 @@
   cOrganism& operator=(const cOrganism&); // @not_implemented
   
 public:
-  cOrganism(cWorld* world, const cGenome& in_genome);
+  cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome);
   ~cOrganism();
 
   cHardwareBase& GetHardware() { return *hardware; }
@@ -146,14 +146,13 @@
   cCPUMemory & ChildGenome() { return child_genome; }
   sCPUStats & CPUStats() { return cpu_stats; }
 
-  bool TestCopyMut() const { return MutationRates().TestCopyMut(); }
-  bool TestDivideMut() const { return MutationRates().TestDivideMut(); }
-  bool TestDivideIns() const { return MutationRates().TestDivideIns(); }
-  bool TestDivideDel() const { return MutationRates().TestDivideDel(); }
-  bool TestParentMut() const { return MutationRates().TestParentMut(); }
-  bool TestCrossover() const { return MutationRates().TestCrossover(); }
-  bool TestAlignedCrossover() const
-    { return MutationRates().TestAlignedCrossover(); }
+  bool TestCopyMut(cAvidaContext& ctx) const { return MutationRates().TestCopyMut(ctx); }
+  bool TestDivideMut(cAvidaContext& ctx) const { return MutationRates().TestDivideMut(ctx); }
+  bool TestDivideIns(cAvidaContext& ctx) const { return MutationRates().TestDivideIns(ctx); }
+  bool TestDivideDel(cAvidaContext& ctx) const { return MutationRates().TestDivideDel(ctx); }
+  bool TestParentMut(cAvidaContext& ctx) const { return MutationRates().TestParentMut(ctx); }
+  bool TestCrossover(cAvidaContext& ctx) const { return MutationRates().TestCrossover(ctx); }
+  bool TestAlignedCrossover(cAvidaContext& ctx) const { return MutationRates().TestAlignedCrossover(ctx); }
   
   double GetCopyMutProb() const { return MutationRates().GetCopyMutProb(); }
   void SetCopyMutProb(double _p) { return MutationRates().SetCopyMutProb(_p); }
@@ -217,7 +216,7 @@
   
   // Divide functions
   bool Divide_CheckViable();
-  bool ActivateDivide();
+  bool ActivateDivide(cAvidaContext& ctx);
   
   // Other Special Functions
   void Fault(int fault_loc, int fault_type, cString fault_desc="");

Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cPhenotype.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -488,7 +488,7 @@
   return false; // Nothing happened...
 }
 
-bool cPhenotype::TestOutput(tBuffer<int> & input_buf, tBuffer<int> &output_buf,
+bool cPhenotype::TestOutput(cAvidaContext& ctx, tBuffer<int> & input_buf, tBuffer<int> &output_buf,
 			    tBuffer<int> & send_buf, tBuffer<int> &receive_buf,
 			    const tArray<double> & res_in,
 			    tArray<double> & res_change,
@@ -506,7 +506,7 @@
   cReactionResult result(num_resources, num_tasks, num_reactions);
 			
   // Run everything through the environment.
-  bool found = env.TestOutput(result, input_buf, output_buf, send_buf,
+  bool found = env.TestOutput(ctx, result, input_buf, output_buf, send_buf,
 			      receive_buf, cur_task_count, cur_reaction_count,
 			      res_in, other_inputs, other_outputs);
 

Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cPhenotype.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -50,6 +50,7 @@
  *
  *************************************************************************/
 
+class cAvidaContext;
 class cEnvironment;
 template <class T> class tBuffer;
 template <class T> class tList;
@@ -155,7 +156,7 @@
 
   // Input and Output Reaction Tests
   bool TestInput(tBuffer<int>& inputs, tBuffer<int>& outputs);
-  bool TestOutput(tBuffer<int>& input_buf, tBuffer<int>& output_buf, 
+  bool TestOutput(cAvidaContext& ctx, tBuffer<int>& input_buf, tBuffer<int>& output_buf, 
                   tBuffer<int>& send_buf, tBuffer<int>& receive_buf,
                   const tArray<double>& res_in, tArray<double>& res_change,
                   tArray<int>& insts_triggered, tList<tBuffer<int> >& other_inputs, 

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cPopulation.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -303,8 +303,7 @@
 // Activate the child, given information from the parent.
 // Return true if parent lives through this process.
 
-bool cPopulation::ActivateOffspring(cGenome & child_genome,
-                                    cOrganism & parent_organism)
+bool cPopulation::ActivateOffspring(cAvidaContext& ctx, cGenome& child_genome, cOrganism& parent_organism)
 {
   assert(&parent_organism != NULL);
   
@@ -317,10 +316,8 @@
   cPhenotype & parent_phenotype = parent_organism.GetPhenotype();
   parent_phenotype.DivideReset(parent_organism.GetGenome().GetSize());
   
-  birth_chamber.SubmitOffspring(child_genome, parent_organism,
-                                child_array, merit_array);
+  birth_chamber.SubmitOffspring(ctx, child_genome, parent_organism, child_array, merit_array);
   
-  
   // First, setup the genotype of all of the offspring.
   cGenotype * parent_genotype = parent_organism.GetGenotype();
   const int parent_id = parent_organism.GetOrgInterface().GetCellID();
@@ -377,7 +374,7 @@
   
   // Place all of the offspring...
   for (int i = 0; i < child_array.GetSize(); i++) {
-    ActivateOrganism(child_array[i], GetCell(target_cells[i]));
+    ActivateOrganism(ctx, child_array[i], GetCell(target_cells[i]));
     cGenotype * child_genotype = child_array[i]->GetGenotype();
     child_genotype->DecDeferAdjust();
     m_world->GetClassificationManager().AdjustGenotype(*child_genotype);
@@ -450,8 +447,7 @@
   return true;
 }
 
-void cPopulation::ActivateOrganism(cOrganism * in_organism,
-                                   cPopulationCell & target_cell)
+void cPopulation::ActivateOrganism(cAvidaContext& ctx, cOrganism* in_organism, cPopulationCell& target_cell)
 {
   assert(in_organism != NULL);
   assert(in_organism->GetGenome().GetSize() > 1);
@@ -482,7 +478,7 @@
   target_cell.InsertOrganism(*in_organism);
   
   // Setup the inputs in the target cell.
-  environment.SetupInputs(target_cell.input_array);
+  environment.SetupInputs(ctx, target_cell.input_array);
   
   // Update the archive...
   in_genotype->AddOrganism();
@@ -1838,8 +1834,11 @@
 {
   assert(cell_id >= 0 && cell_id < cell_array.GetSize());
   
-  cOrganism * new_organism = new cOrganism(m_world, new_genotype->GetGenome());
+  // @DMB - Warning: Creating context out of band.
+  cAvidaContext ctx(m_world->GetRandom());
   
+  cOrganism* new_organism = new cOrganism(m_world, ctx, new_genotype->GetGenome());
+  
   // Set the genotype...
   new_organism->SetGenotype(new_genotype);
   
@@ -1866,19 +1865,22 @@
   
   
   // Activate the organism in the population...
-  ActivateOrganism(new_organism, cell_array[cell_id]);
+  ActivateOrganism(ctx, new_organism, cell_array[cell_id]);
 }
 
 
 // This function injects a new organism into the population at cell_id that
 // is an exact clone of the organism passed in.
 
-void cPopulation::InjectClone(int cell_id, cOrganism & orig_org)
+void cPopulation::InjectClone(int cell_id, cOrganism& orig_org)
 {
   assert(cell_id >= 0 && cell_id < cell_array.GetSize());
   
-  cOrganism * new_organism = new cOrganism(m_world, orig_org.GetGenome());
+  // @DMB - Warning: Creating context out of band.
+  cAvidaContext ctx(m_world->GetRandom());
   
+  cOrganism* new_organism = new cOrganism(m_world, ctx, orig_org.GetGenome());
+  
   // Set the genotype...
   new_organism->SetGenotype(orig_org.GetGenotype());
   
@@ -1896,7 +1898,7 @@
   new_organism->MutationRates().Copy(cell_array[cell_id].MutationRates());
   
   // Activate the organism in the population...
-  ActivateOrganism(new_organism, cell_array[cell_id]);
+  ActivateOrganism(ctx, new_organism, cell_array[cell_id]);
 }
 
 

Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cPopulation.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -102,7 +102,7 @@
   void LineageSetupOrganism(cOrganism* organism, cLineage* lineage, int lin_label, cGenotype* parent_genotype = NULL);
 
   // Must be called to activate *any* organism in the population.
-  void ActivateOrganism(cOrganism* in_organism, cPopulationCell& target_cell);
+  void ActivateOrganism(cAvidaContext& ctx, cOrganism* in_organism, cPopulationCell& target_cell);
 
   cPopulation(); // @not_implemented
   cPopulation(const cPopulation&); // @not_implemented
@@ -116,7 +116,7 @@
   bool SetupDemes();
 
   // Activate the offspring of an organism in the population
-  bool ActivateOffspring(cGenome& child_genome, cOrganism& parent_organism);
+  bool ActivateOffspring(cAvidaContext& ctx, cGenome& child_genome, cOrganism& parent_organism);
 
   bool ActivateInject(cOrganism& parent, const cGenome& injected_code);
   bool ActivateInject(const int cell_id, const cGenome& injected_code);

Modified: development/source/main/cPopulationCell.cc
===================================================================
--- development/source/main/cPopulationCell.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cPopulationCell.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -20,7 +20,6 @@
 cPopulationCell::cPopulationCell()
   : m_world(NULL)
   , organism(NULL)
-  , mutation_rates(NULL)
   , cur_input(0)
   , organism_count(0)
 {
@@ -29,13 +28,12 @@
 cPopulationCell::cPopulationCell(const cPopulationCell & in_cell)
   : m_world(in_cell.m_world)
   , organism(in_cell.organism)
-  , mutation_rates(NULL)
   , cur_input(in_cell.cur_input)
   , cell_id(in_cell.cell_id)
   , organism_count(in_cell.organism_count)
 {
   for (int i = 0; i < nHardware::IO_SIZE; i++) input_array[i] = in_cell.input_array[i];
-  mutation_rates = new cMutationRates(m_world);
+  mutation_rates = new cMutationRates();
   mutation_rates->Copy(*in_cell.mutation_rates);
   tConstListIterator<cPopulationCell> conn_it(in_cell.connection_list);
   cPopulationCell * test_cell;
@@ -52,7 +50,7 @@
   cur_input = in_cell.cur_input;
   cell_id = in_cell.cell_id;
   organism_count = in_cell.organism_count;
-  if (mutation_rates == NULL) mutation_rates = new cMutationRates(m_world);
+  if (mutation_rates == NULL) mutation_rates = new cMutationRates();
   mutation_rates->Copy(*in_cell.mutation_rates);
   tConstListIterator<cPopulationCell> conn_it(in_cell.connection_list);
   cPopulationCell * test_cell;
@@ -65,7 +63,7 @@
 {
   m_world = world;
   cell_id = in_id;
-  if (mutation_rates == NULL) mutation_rates = new cMutationRates(world);
+  if (mutation_rates == NULL) mutation_rates = new cMutationRates();
   mutation_rates->Copy(in_rates);
 }
 

Modified: development/source/main/cPopulationCell.h
===================================================================
--- development/source/main/cPopulationCell.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cPopulationCell.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -26,6 +26,7 @@
 class cPopulation;
 class cOrganism;
 class cPopulationCell;
+class cWorld;
 
 class cPopulationCell
 {

Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cPopulationInterface.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -26,11 +26,11 @@
 #endif
 
 
-bool cPopulationInterface::Divide(cOrganism * parent, cGenome & child_genome)
+bool cPopulationInterface::Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome)
 {
   assert(parent != NULL);
   assert(m_world->GetPopulation().GetCell(cell_id).GetOrganism() == parent);
-  return m_world->GetPopulation().ActivateOffspring(child_genome, *parent);
+  return m_world->GetPopulation().ActivateOffspring(ctx, child_genome, *parent);
 }
 
 cOrganism * cPopulationInterface::GetNeighbor()

Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cPopulationInterface.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -43,7 +43,7 @@
   int GetCellID() { return cell_id; }
   void SetCellID(int in_id) { cell_id = in_id; }
 
-  bool Divide(cOrganism* parent, cGenome& child_genome);
+  bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome);
   cOrganism* GetNeighbor();
   int GetNumNeighbors();
   void Rotate(int direction = 1);

Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cTaskLib.cc	2006-03-20 01:16:06 UTC (rev 523)
@@ -342,8 +342,7 @@
   return *(task_array[id]);
 }
 
-int cTaskLib::SetupLogicTests(const tBuffer<int> & inputs,
-                              const tBuffer<int> & outputs) const
+int cTaskLib::SetupLogicTests(const tBuffer<int>& inputs, const tBuffer<int>& outputs) const
 {
   // Collect the inputs in a useful form.
   const int num_inputs = inputs.GetNumStored();
@@ -362,8 +361,8 @@
   //       Input B: 1 1 0 0 1 1 0 0
   //       Input A: 1 0 1 0 1 0 1 0
   
-  tArray<int> logic_out(8);
-  logic_out.SetAll(-1);
+  int logic_out[8];
+  for (int i = 0; i < 8; i++) logic_out[i] = -1;
   
   // Test all input combos!
   bool func_OK = true;  // Have all outputs been consistant?
@@ -1728,10 +1727,10 @@
 {
   const int test_output = ctx->output_buffer[0];
   
-  tListIterator<tBuffer<int> > buff_it(ctx->other_input_buffers);  
+  tConstListIterator<tBuffer<int> > buff_it(ctx->other_input_buffers);  
   
   while (buff_it.Next() != NULL) {
-    tBuffer<int> & cur_buff = *(buff_it.Get());
+    const tBuffer<int>& cur_buff = *(buff_it.Get());
     const int buff_size = cur_buff.GetNumStored();
     for (int i = 0; i < buff_size; i++) {
       if (test_output == cur_buff[i]) return 1.0;
@@ -1745,10 +1744,10 @@
 {
   const int test_output = ctx->output_buffer[0];
   
-  tListIterator<tBuffer<int> > buff_it(ctx->other_input_buffers);  
+  tConstListIterator<tBuffer<int> > buff_it(ctx->other_input_buffers);  
   
   while (buff_it.Next() != NULL) {
-    tBuffer<int> & cur_buff = *(buff_it.Get());
+    const tBuffer<int>& cur_buff = *(buff_it.Get());
     const int buff_size = cur_buff.GetNumStored();
     for (int i = 0; i < buff_size; i++) {
       if (test_output == (0-(cur_buff[i]+1))) return 1.0;

Modified: development/source/main/cTaskLib.h
===================================================================
--- development/source/main/cTaskLib.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cTaskLib.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -27,24 +27,42 @@
 
 class cString;
 
+//class cTaskContext
+//{
+//public:
+//  tBuffer<int> input_buffer;
+//  tBuffer<int> output_buffer;
+//  tList<tBuffer<int> > other_input_buffers;
+//  tList<tBuffer<int> > other_output_buffers;
+//  int logic_id;
+//  
+//  cTaskContext(const tBuffer<int>& inputs, const tBuffer<int>& outputs,
+//               const tList<tBuffer<int> >& other_inputs,
+//               const tList<tBuffer<int> >& other_outputs, int in_logic_id)
+//  : input_buffer(3), output_buffer(3), logic_id(in_logic_id)
+//  {
+//    input_buffer = inputs;
+//    output_buffer = outputs;
+//    other_input_buffers.Copy(other_inputs);
+//    other_output_buffers.Copy(other_outputs);
+//  }
+//};
+
 class cTaskContext
 {
 public:
-  tBuffer<int> input_buffer;
-  tBuffer<int> output_buffer;
-  tList<tBuffer<int> > other_input_buffers;
-  tList<tBuffer<int> > other_output_buffers;
+  const tBuffer<int>& input_buffer;
+  const tBuffer<int>& output_buffer;
+  const tList<tBuffer<int> >& other_input_buffers;
+  const tList<tBuffer<int> >& other_output_buffers;
   int logic_id;
   
   cTaskContext(const tBuffer<int>& inputs, const tBuffer<int>& outputs,
                const tList<tBuffer<int> >& other_inputs,
                const tList<tBuffer<int> >& other_outputs, int in_logic_id)
-  : input_buffer(3), output_buffer(3), logic_id(in_logic_id)
+    : input_buffer(inputs), output_buffer(outputs), other_input_buffers(other_inputs),
+    other_output_buffers(other_outputs), logic_id(in_logic_id)
   {
-    input_buffer = inputs;
-    output_buffer = outputs;
-    other_input_buffers.Copy(other_inputs);
-    other_output_buffers.Copy(other_outputs);
   }
 };
 
@@ -82,11 +100,11 @@
   cTaskEntry* AddTask(const cString& name);
   const cTaskEntry& GetTask(int id) const;
   
-  cTaskContext* SetupTests(const tBuffer<int>& inputs, const tBuffer<int>& outputs,
+  cTaskContext SetupTests(const tBuffer<int>& inputs, const tBuffer<int>& outputs,
                           const tList<tBuffer<int> >& other_inputs,
                           const tList<tBuffer<int> >& other_outputs) const
   {
-    return new cTaskContext(inputs, outputs, other_inputs, other_outputs, SetupLogicTests(inputs, outputs));
+    return cTaskContext(inputs, outputs, other_inputs, other_outputs, SetupLogicTests(inputs, outputs));
   }
   inline double TestOutput(const cTaskEntry& task, cTaskContext* ctx) const;
 

Modified: development/source/main/cWorld.h
===================================================================
--- development/source/main/cWorld.h	2006-03-17 12:01:57 UTC (rev 522)
+++ development/source/main/cWorld.h	2006-03-20 01:16:06 UTC (rev 523)
@@ -45,7 +45,7 @@
   cStats* m_stats;
   cWorldDriver* m_driver;
 
-  cRandomMT m_rng;
+  cRandom m_rng;
   
   bool m_test_on_div;     // flag derived from a collection of configuration settings
   bool m_test_sterilize;  // flag derived from a collection of configuration settings




More information about the Avida-cvs mailing list