[Avida-SVN] r2124 - in branches/energy: . documentation source/actions source/analyze source/cpu source/main source/tools support/config

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Thu Oct 4 05:15:23 PDT 2007


Author: beckma24
Date: 2007-10-04 08:15:21 -0400 (Thu, 04 Oct 2007)
New Revision: 2124

Modified:
   branches/energy/CMakeLists.txt
   branches/energy/documentation/actions.html
   branches/energy/documentation/environment.html
   branches/energy/source/actions/EnvironmentActions.cc
   branches/energy/source/analyze/cAnalyzeGenotype.cc
   branches/energy/source/cpu/cHardwareBase.cc
   branches/energy/source/cpu/cHardwareCPU.cc
   branches/energy/source/cpu/cHardwareCPU.h
   branches/energy/source/cpu/cHardwareExperimental.cc
   branches/energy/source/cpu/cHardwareGX.cc
   branches/energy/source/cpu/cHardwareSMT.cc
   branches/energy/source/cpu/cHardwareTransSMT.cc
   branches/energy/source/cpu/cInstLib.h
   branches/energy/source/cpu/cInstSet.cc
   branches/energy/source/cpu/cInstSet.h
   branches/energy/source/cpu/tInstLib.h
   branches/energy/source/main/cEnvironment.cc
   branches/energy/source/main/cEnvironment.h
   branches/energy/source/main/cOrganism.h
   branches/energy/source/main/cPhenPlastGenotype.cc
   branches/energy/source/main/cPhenotype.cc
   branches/energy/source/main/cPopulation.cc
   branches/energy/source/main/cPopulation.h
   branches/energy/source/main/cReaction.cc
   branches/energy/source/main/cReaction.h
   branches/energy/source/main/cResourceCount.cc
   branches/energy/source/main/cResourceCount.h
   branches/energy/source/tools/cString.h
   branches/energy/support/config/avida.cfg
Log:
Merged development into energy

Modified: branches/energy/CMakeLists.txt
===================================================================
--- branches/energy/CMakeLists.txt	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/CMakeLists.txt	2007-10-04 12:15:21 UTC (rev 2124)
@@ -34,13 +34,22 @@
     SET(COMPILER_WARNING_FLAGS "")
     SET(COMPILER_OPTIMIZATION_FLAGS "-ffast-math -fno-rtti -funroll-loops -fstrict-aliasing -OPT:Olimit=0")
   ELSE (CMAKE_CXX_COMPILER MATCHES ".*pathCC.*")
-    SET(COMPILER_WARNING_FLAGS "-Wextra -Wno-unknown-pragmas -Wconversion -Wno-trigraphs")
-    SET(COMPILER_OPTIMIZATION_FLAGS "-ffast-math -fno-rtti -funroll-loops -fstrict-aliasing -ftree-vectorize -fvisibility-inlines-hidden")
+    IF (CMAKE_CXX_COMPILER MATCHES ".*icpc.*")
+      SET(COMPILER_WARNING_FLAGS "")
+      SET(COMPILER_OPTIMIZATION_FLAGS "")
+    ELSE (CMAKE_CXX_COMPILER MATCHES ".*icpc.*")
+      SET(COMPILER_WARNING_FLAGS "-Wextra -Wno-unknown-pragmas -Wconversion -Wno-trigraphs")
+      SET(COMPILER_OPTIMIZATION_FLAGS "-ffast-math -fno-rtti -funroll-loops -fstrict-aliasing -ftree-vectorize -fvisibility-inlines-hidden")
+    ENDIF (CMAKE_CXX_COMPILER MATCHES ".*icpc.*")
   ENDIF (CMAKE_CXX_COMPILER MATCHES ".*pathCC.*")
 
   INCLUDE(CheckCSourceCompiles)
-  SET(CMAKE_REQUIRED_FLAGS "-mno-fused-madd")
-  CHECK_C_SOURCE_COMPILES("int main() { return 0; }" HAVE_FUSED_MADD)
+  IF (CMAKE_CXX_COMPILER MATCHES ".*icpc.*")
+    SET(HAVE_FUSED_MADD FALSE)
+  ELSE (CMAKE_CXX_COMPILER MATCHES ".*icpc.*")
+    SET(CMAKE_REQUIRED_FLAGS "-mno-fused-madd")
+    CHECK_C_SOURCE_COMPILES("int main() { return 0; }" HAVE_FUSED_MADD)
+  ENDIF (CMAKE_CXX_COMPILER MATCHES ".*icpc.*")
   SET(CMAKE_REQUIRED_FLAGS "")
 
   IF(HAVE_FUSED_MADD)
@@ -301,7 +310,11 @@
 # Build Instructions for the TCMalloc library
 # ------------------------------------------------------------------------------
 IF(UNIX)
-  SET(AVD_ENABLE_TCMALLOC TRUE)
+  IF (CMAKE_CXX_COMPILER MATCHES ".*icpc.*")
+    SET(AVD_ENABLE_TCMALLOC FALSE)
+  ELSE (CMAKE_CXX_COMPILER MATCHES ".*icpc.*")
+    SET(AVD_ENABLE_TCMALLOC TRUE)
+  ENDIF (CMAKE_CXX_COMPILER MATCHES ".*icpc.*")
 ELSE(UNIX)
   SET(AVD_ENABLE_TCMALLOC FALSE)
 ENDIF(UNIX)

Modified: branches/energy/documentation/actions.html
===================================================================
--- branches/energy/documentation/actions.html	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/documentation/actions.html	2007-10-04 12:15:21 UTC (rev 2124)
@@ -90,11 +90,11 @@
       <br /><a href="#KillRate">KillRate</a>
       <br /><a href="#KillRectangle">KillRectangle</a>
       <br /><a href="#LoadClone">LoadClone</a>
+      <br /><a href="#LoadPopulation">LoadPopulation</a>
+      <br /><a href="#ModMutProb">ModMutProb</a>
     </td>
     <td>
-      <a href="#LoadPopulation">LoadPopulation</a>
-      <br /><a href="#ModMutProb">ModMutProb</a>
-      <br /><a href="#OutflowScaledResource">OutflowScaledResource</a>
+      <a href="#OutflowScaledResource">OutflowScaledResource</a>
       <br /><a href="#PairTestLandscape">PairTestLandscape</a>
       <br /><a href="#PrecalcLandscape">PrecalcLandscape</a>
       <br /><a href="#PredictNuLandscape">PredictNuLandscape</a>
@@ -127,13 +127,13 @@
       <br /><a href="#PrintLogFitnessHistogram">PrintLogFitnessHistogram</a>
       <br /><a href="#PrintMutationRateData">PrintMutationRateData</a>
       <br /><a href="#PrintPhenotypeData">PrintPhenotypeData</a>
-    </td>
-    <td>
-      <a href="#PrintPhenotypeStatus">PrintPhenotypeStatus</a>
+      <br /><a href="#PrintPhenotypeStatus">PrintPhenotypeStatus</a>
       <br /><a href="#PrintPhenotypicPlasticity">PrintPhenotypicPlasticity</a>
       <br /><a href="#PrintPopulationDistanceData">PrintPopulationDistanceData</a>
       <br /><a href="#PrintRelativeFitnessHistogram">PrintRelativeFitnessHistogram</a>
-      <br /><a href="#PrintResourceData">PrintResourceData</a>
+    </td>
+    <td>
+      <a href="#PrintResourceData">PrintResourceData</a>
       <br /><a href="#PrintSpeciesAbundanceData">PrintSpeciesAbundanceData</a>
       <br /><a href="#PrintStatsData">PrintStatsData</a>
       <br /><a href="#PrintTasksSnapshot">PrintTasksSnapshot</a>
@@ -154,11 +154,16 @@
       <br /><a href="#SavePopulation">SavePopulation</a>
       <br /><a href="#SaveSexPopulation">SaveSexPopulation</a>
       <br /><a href="#SerialTransfer">SerialTransfer</a>
+      <br /><a href="#SetEnvironmentInputs">SetEnvironmentInputs</a>
       <br /><a href="#SetMutProb">SetMutProb</a>
       <br /><a href="#SetReactionInst">SetReactionInst</a>
+      <br /><a href="#SetReactionMinTaskCount">SetReactionMinTaskCount</a>
+      <br /><a href="#SetReactionMaxTaskCount">SetReactionMaxTaskCount</a>
       <br /><a href="#SetReactionValue">SetReactionValue</a>
       <br /><a href="#SetReactionValueMult">SetReactionValueMult</a>
       <br /><a href="#SetResource">SetResource</a>
+      <br /><a href="#SetResourceInflow">SetResourceInflow</a>
+      <br /><a href="#SetResourceOutflow">SetResourceOutflow</a>
       <br /><a href="#SetVerbose">SetVerbose</a>
       <br /><a href="#SeverGridCol">SeverGridCol</a>
       <br /><a href="#SeverGridRow">SeverGridRow</a>
@@ -1010,7 +1015,21 @@
   <p>
   </p>
 </li>
+
 <li>
+  <strong><a name="SetEnvironmentInputs">SetEnvironmentInputs</a></strong>
+  &lt;<span class="cmdarg">int input.1</span>&gt; &lt;<span class="cmdarg">int input.2</span>&gt; 
+  &lt;<span class="cmdarg">int input.3</span>&gt;
+  
+  <p>
+  Set the inputs that all organisms get from the environment when doing IO to these specific values. There must 
+  be exactly three inputs, and they must have the usual values for the top 8 "key" bits, i.e. they must be of the form
+  0x0F?????? 0x33?????? 0x55?????? where ? can be replaced with any hexadecimal digit.
+  </p>
+</li>
+
+
+<li>
   <strong><a name="SetResource">SetResource</a></strong>
   &lt;<span class="cmdarg">string res_name</span>&gt; &lt;<span class="cmdarg">double res_count</span>&gt;
   
@@ -1022,6 +1041,29 @@
 </li>
 
 <li>
+  <strong><a name="SetResourceInflow">SetResourceInflow</a></strong>
+  &lt;<span class="cmdarg">string res_name</span>&gt; &lt;<span class="cmdarg">double inflow</span>&gt;
+  
+  <p>
+  Set the resource inflow to a specific level.
+  <span class="cmdarg">res_name</span> must already exist as
+  a resource in environment file.
+  </p>
+</li>
+
+<li>
+  <strong><a name="SetResourceOutflow">SetResourceOutflow</a></strong>
+  &lt;<span class="cmdarg">string res_name</span>&gt; &lt;<span class="cmdarg">double outflow</span>&gt;
+  
+  <p>
+  Set the resource outflow to a specific level.
+  <span class="cmdarg">res_name</span> must already exist as
+  a resource in environment file.
+  </p>
+</li>
+
+
+<li>
   <strong><a name="SetReactionValue">SetReactionValue</a></strong>
   &lt;<span class="cmdarg">string reaction_name</span>&gt; &lt;<span class="cmdarg">double value</span>&gt;
   
@@ -1033,6 +1075,28 @@
   </p>
 </li>
 <li>
+  <strong><a name="SetReactionMinTaskCount">SetReactionMinTaskCount</a></strong>
+  &lt;<span class="cmdarg">string reaction_name</span>&gt; &lt;<span class="cmdarg">int task_count</span>&gt;
+  
+  <p>
+  Set the min task count required to trigger a reaction to <span class="cmdarg">task_count</span>.
+  <span class="cmdarg">reaction_name</span> must already 
+  exist in the environment file.
+  </p>
+</li>
+
+<li>
+  <strong><a name="SetReactionMaxTaskCount">SetReactionMaxTaskCount</a></strong>
+  &lt;<span class="cmdarg">string reaction_name</span>&gt; &lt;<span class="cmdarg">int task_count</span>&gt;
+  
+  <p>
+  Set the max task count required to trigger a reaction to <span class="cmdarg">task_count</span>.
+  <span class="cmdarg">reaction_name</span> must already 
+  exist in the environment file.
+  </p>
+</li>
+
+<li>
   <strong><a name="SetReactionValueMult">SetReactionValueMult</a></strong>
   &lt;<span class="cmdarg">string reaction_name</span>&gt; &lt;<span class="cmdarg">double value</span>&gt;
   

Modified: branches/energy/documentation/environment.html
===================================================================
--- branches/energy/documentation/environment.html	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/documentation/environment.html	2007-10-04 12:15:21 UTC (rev 2124)
@@ -266,8 +266,8 @@
 from the top and flows towards the bottom where it exits the system,
 you could use:
 <pre>
-  RESOURCE lactose:initial=100000:inflow=100:outflow=0.1:inflowx1=0:\
-  inflowx2=100:inflowy1=0:inflowy2=0:outflowx1=0:outflowx2=100:\
+  RESOURCE lactose:geometry=grid:initial=100000:inflow=100:outflow=0.1:\
+  inflowx1=0:inflowx2=100:inflowy1=0:inflowy2=0:outflowx1=0:outflowx2=100:\
   outflowy1=100:outflowy2=100:ygravity=0.5
 </pre>
 </p>

Modified: branches/energy/source/actions/EnvironmentActions.cc
===================================================================
--- branches/energy/source/actions/EnvironmentActions.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/actions/EnvironmentActions.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -266,6 +266,146 @@
   }
 };
 
+class cActionSetReactionMinTaskCount : public cAction
+{
+private:
+  cString m_name;
+  int m_min_count;
+  
+public:
+  cActionSetReactionMinTaskCount(cWorld* world, const cString& args) : cAction(world, args), m_name(""), m_min_count(0)
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_name = largs.PopWord();
+    if (largs.GetSize()) m_min_count = largs.PopWord().AsInt();
+  }
+  
+  static const cString GetDescription() { return "Arguments: <string reaction_name> <int min_count>"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    m_world->GetEnvironment().SetReactionMinTaskCount(m_name, m_min_count);
+  }
+};
+
+class cActionSetReactionMaxTaskCount : public cAction
+{
+private:
+  cString m_name;
+  int m_max_count;
+  
+public:
+  cActionSetReactionMaxTaskCount(cWorld* world, const cString& args) : cAction(world, args), m_name(""), m_max_count(0)
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_name = largs.PopWord();
+    if (largs.GetSize()) m_max_count = largs.PopWord().AsInt();
+  }
+  
+  static const cString GetDescription() { return "Arguments: <string reaction_name> <int max_count>"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    m_world->GetEnvironment().SetReactionMaxTaskCount(m_name, m_max_count);
+  }
+};
+
+class cActionSetResourceInflow : public cAction
+{
+private:
+  cString m_name;
+  double m_inflow;
+  
+public:
+  cActionSetResourceInflow(cWorld* world, const cString& args) : cAction(world, args), m_name(""), m_inflow(0.0)
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_name = largs.PopWord();
+    if (largs.GetSize()) m_inflow = largs.PopWord().AsDouble();
+  }
+  
+  static const cString GetDescription() { return "Arguments: <string resource_name> <int inflow>"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    m_world->GetEnvironment().SetResourceInflow(m_name, m_inflow);
+      //This doesn't actually update the rate in the population, so...
+    m_world->GetPopulation().GetResourceCount().SetInflow(m_name, m_inflow);
+  }
+};
+
+class cActionSetResourceOutflow : public cAction
+{
+private:
+  cString m_name;
+  double m_outflow;
+  
+public:
+  cActionSetResourceOutflow(cWorld* world, const cString& args) : cAction(world, args), m_name(""), m_outflow(0.0)
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_name = largs.PopWord();
+    if (largs.GetSize()) m_outflow = largs.PopWord().AsDouble();
+    assert(m_outflow < 1.0);
+    assert(m_outflow > 0.0);
+  }
+  
+  static const cString GetDescription() { return "Arguments: <string resource_name> <int outflow>"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    m_world->GetEnvironment().SetResourceOutflow(m_name, m_outflow);
+      //This doesn't actually update the rate in the population, so...
+    m_world->GetPopulation().GetResourceCount().SetDecay(m_name, 1-m_outflow);
+  }
+};
+
+class cActionSetEnvironmentInputs : public cAction
+{
+private:
+  tArray<int> m_inputs;
+  
+public:
+  cActionSetEnvironmentInputs(cWorld* world, const cString& args) : cAction(world, args), m_inputs()
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_inputs.Push(largs.PopWord().AsInt());
+    if (largs.GetSize()) m_inputs.Push(largs.PopWord().AsInt());
+    if (largs.GetSize()) m_inputs.Push(largs.PopWord().AsInt());
+        
+    if ( m_inputs.GetSize() != 3 )
+    {
+      cerr << "Must have exactly 3 inputs for SetEnvironmentInputs action." << endl;
+      exit(1);
+    }
+    
+    if ( (m_inputs[0] >> 24 != 15) || (m_inputs[1] >> 24 != 51) || (m_inputs[2] >> 24 != 85) )
+    {
+      cerr << "Inputs must begin 0F, 33, 55 for SetEnvironmentInputs" << endl;
+      cerr << "They are: " << m_inputs[0] << " " << m_inputs[1] << " " << m_inputs[2] << endl;
+      exit(1);    
+    }
+    
+  }
+  
+  static const cString GetDescription() { return "Arguments: <int input_1> <int input_2> <int input_3> "; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    //First change the environmental inputs
+    cEnvironment& env = m_world->GetEnvironment();
+    env.SetSpecificInputs(m_inputs);
+    
+    //Now immediately change the inputs in each cell and
+    //clear the input array of each organism so changes take effect
+    
+    cPopulation& pop = m_world->GetPopulation();
+    pop.ResetInputs(ctx);
+  }
+};
+
+
+
 class cActionSetTaskArgInt : public cAction
 {
 private:
@@ -500,7 +640,14 @@
   action_lib->Register<cActionSetReactionValue>("SetReactionValue");
   action_lib->Register<cActionSetReactionValueMult>("SetReactionValueMult");
   action_lib->Register<cActionSetReactionInst>("SetReactionInst");
+  action_lib->Register<cActionSetReactionMinTaskCount>("SetReactionMinTaskCount");
+  action_lib->Register<cActionSetReactionMaxTaskCount>("SetReactionMaxTaskCount");
 
+  action_lib->Register<cActionSetResourceInflow>("SetResourceInflow");
+  action_lib->Register<cActionSetResourceOutflow>("SetResourceOutflow");
+
+  action_lib->Register<cActionSetEnvironmentInputs>("SetEnvironmentInputs");
+
   action_lib->Register<cActionSetPeriodicResource>("SetPeriodicResource");
   action_lib->Register<cActionSetNumInstBefore0Energy>("SetNumInstBefore0Energy");
 

Modified: branches/energy/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- branches/energy/source/analyze/cAnalyzeGenotype.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/analyze/cAnalyzeGenotype.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -388,6 +388,7 @@
 
 void cAnalyzeGenotype::Recalculate(cAvidaContext& ctx, cTestCPU* testcpu, cAnalyzeGenotype* parent_genotype, cCPUTestInfo* test_info, int num_trials)
 {
+  // We are not going to use this testcpu ...
   
   //Allocate our own test info if it wasn't provided
   cCPUTestInfo* temp_test_info = NULL;

Modified: branches/energy/source/cpu/cHardwareBase.cc
===================================================================
--- branches/energy/source/cpu/cHardwareBase.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/cpu/cHardwareBase.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -799,6 +799,9 @@
 // @JEB Check implicit repro conditions -- meant to be called at the end of SingleProcess
 void cHardwareBase::CheckImplicitRepro(cAvidaContext& ctx, bool exec_last_inst)         
 {  
+  //Dividing a dead organism causes all kinds of problems
+  if (organism->IsDead()) return;
+
   if( (m_world->GetConfig().IMPLICIT_REPRO_TIME.Get() && (organism->GetPhenotype().GetTimeUsed() >= m_world->GetConfig().IMPLICIT_REPRO_TIME.Get()))
    || (m_world->GetConfig().IMPLICIT_REPRO_CPU_CYCLES.Get() && (organism->GetPhenotype().GetCPUCyclesUsed() >= m_world->GetConfig().IMPLICIT_REPRO_CPU_CYCLES.Get()))
    || (m_world->GetConfig().IMPLICIT_REPRO_BONUS.Get() && (organism->GetPhenotype().GetCurBonus() >= m_world->GetConfig().IMPLICIT_REPRO_BONUS.Get()))

Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/cpu/cHardwareCPU.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -363,7 +363,8 @@
     tInstLibEntry<tMethod>("terminate", &cHardwareCPU::Inst_Terminate),
     tInstLibEntry<tMethod>("regulate", &cHardwareCPU::Inst_Regulate),
     tInstLibEntry<tMethod>("numberate", &cHardwareCPU::Inst_Numberate),
-    
+    tInstLibEntry<tMethod>("bit-cons", &cHardwareCPU::Inst_BitConsensus),
+
     // Energy usage
     tInstLibEntry<tMethod>("double-energy-usage", &cHardwareCPU::Inst_DoubleEnergyUsage),
     tInstLibEntry<tMethod>("half-energy-usage", &cHardwareCPU::Inst_HalfEnergyUsage),
@@ -374,7 +375,7 @@
     tInstLibEntry<tMethod>("retrieve-msg", &cHardwareCPU::Inst_RetrieveMessage),
         
     // Placebo instructions
-//    tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip),
+    tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip),
 
     // Must always be the last instruction in the array
     tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
@@ -393,11 +394,10 @@
   static tMethod functions[f_size];
   for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 
-	const cInstruction error(255);
-	const cInstruction def(0);
-  const cInstruction null_inst(f_size - 1);
+	const int def = 0;
+  const int null_inst = f_size - 1;
   
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
 cHardwareCPU::cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
@@ -523,6 +523,7 @@
 
 void cHardwareCPU::SingleProcess(cAvidaContext& ctx)
 {
+
   int last_IP_pos = IP().GetPosition();
   
   // Mark this organism as running...
@@ -612,7 +613,7 @@
     } // if exec
         
   } // Previous was executed once for each thread...
-  
+
   // Kill creatures who have reached their max num of instructions executed
   const int max_executed = organism->GetMaxExecuted();
   if ((max_executed > 0 && phenotype.GetTimeUsed() >= max_executed)
@@ -620,8 +621,10 @@
     organism->Die();
   }
   
+  // Note: if organism just died, this will NOT let it repro.
+  CheckImplicitRepro(ctx, last_IP_pos > IP().GetPosition());
+  
   organism->SetRunning(false);
-  CheckImplicitRepro(ctx, last_IP_pos > IP().GetPosition());
 }
 
 // This method will handle the actual execution of an instruction
@@ -2577,6 +2580,7 @@
       }
     }
   }
+  
   Divide_DoMutations(ctx);
   
   // Many tests will require us to run the offspring through a test CPU;
@@ -3067,13 +3071,18 @@
     } 
   }
   
-  // Take the log after adding resource amounts together!
-  // Otherwise 
+  // Take the log after adding resource amounts together! This way a zero can be assigned to INT_MIN
   if (conversion_method == 0) // Log2
   {
     // You really shouldn't be using the log method if you can get to zero resources
-    assert(dresource_result != 0);
-    resource_result = (int)(log(dresource_result)/log(base));
+    if(dresource_result == 0.0)
+    {
+      resource_result = INT_MIN;
+    }
+    else
+    {
+      resource_result = (int)(log(dresource_result)/log(base));
+    }
   }
     
   //Dump this value into an arbitrary register: BX
@@ -4480,6 +4489,27 @@
   return code;
 }
 
+/*! 
+  Sets BX to 1 if >=50% of the bits in the specified register
+  are 1's and zero otherwise.
+*/
+
+bool cHardwareCPU::Inst_BitConsensus(cAvidaContext& ctx)
+{
+  const int reg_used = FindModifiedRegister(REG_BX);
+  int reg_val = GetRegister(REG_CX);
+  unsigned int bits_on = 0;
+  
+  for (unsigned int i = 0; i < sizeof(int) * 8; i++)
+  {
+    bits_on += (reg_val & 1);
+    reg_val >>= 1;
+  }
+  
+  GetRegister(reg_used) = ( bits_on >= (sizeof(int) * 8)/2 ) ? 1 : 0;
+  return true; 
+}
+
 /*! Send a message to the organism that is currently faced by this cell,
 where the label field of sent message is from register ?BX?, and the data field
 is from register ~?BX?.

Modified: branches/energy/source/cpu/cHardwareCPU.h
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.h	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/cpu/cHardwareCPU.h	2007-10-04 12:15:21 UTC (rev 2124)
@@ -553,6 +553,7 @@
   bool Inst_Terminate(cAvidaContext& ctx);
   bool Inst_Regulate(cAvidaContext& ctx);
   bool Inst_Numberate(cAvidaContext& ctx);
+  bool Inst_BitConsensus(cAvidaContext& ctx);
 
     // Helper functions //
   bool IsActivePromoter();

Modified: branches/energy/source/cpu/cHardwareExperimental.cc
===================================================================
--- branches/energy/source/cpu/cHardwareExperimental.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/cpu/cHardwareExperimental.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -136,11 +136,10 @@
   static tMethod functions[f_size];
   for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 
-	const cInstruction error(255);
-	const cInstruction def(0);
-  const cInstruction null_inst(4);
+	const int def = 0;
+  const int null_inst = 4;
   
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
 cHardwareExperimental::cHardwareExperimental(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: branches/energy/source/cpu/cHardwareGX.cc
===================================================================
--- branches/energy/source/cpu/cHardwareGX.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/cpu/cHardwareGX.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -301,11 +301,10 @@
   static tMethod functions[f_size];
   for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 
-	const cInstruction error(255);
-	const cInstruction def(0);
-  const cInstruction null_inst(f_size - 1);
+	const int def = 0;
+  const int null_inst = f_size - 1;
   
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
 

Modified: branches/energy/source/cpu/cHardwareSMT.cc
===================================================================
--- branches/energy/source/cpu/cHardwareSMT.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/cpu/cHardwareSMT.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -127,11 +127,10 @@
   static tMethod functions[f_size];
   for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 	
-	const cInstruction error(255);
-	const cInstruction def(0);
-	const cInstruction null_inst(f_size - 1);
+	const int def = 0;
+  const int null_inst = f_size - 1;
   
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
 cHardwareSMT::cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: branches/energy/source/cpu/cHardwareTransSMT.cc
===================================================================
--- branches/energy/source/cpu/cHardwareTransSMT.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/cpu/cHardwareTransSMT.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -126,11 +126,10 @@
   static tMethod functions[f_size];
   for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 	
-	const cInstruction error(255);
-	const cInstruction def(0);
-  const cInstruction null_inst(f_size - 1);
+	const int def = 0;
+  const int null_inst = f_size - 1;
 	
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
 cHardwareTransSMT::cHardwareTransSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: branches/energy/source/cpu/cInstLib.h
===================================================================
--- branches/energy/source/cpu/cInstLib.h	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/cpu/cInstLib.h	2007-10-04 12:15:21 UTC (rev 2124)
@@ -45,15 +45,14 @@
   const int m_size;
   tDictionary<int> m_namemap;
 
-  const cInstruction m_inst_error;
-  const cInstruction m_inst_default;
-  const cInstruction m_inst_null;
+  int m_inst_default;
+  int m_inst_null;
   
   cInstLib(); // @not_implemented
   
 public:
-  cInstLib(int size, const cInstruction inst_error, const cInstruction inst_default, const cInstruction inst_null)
-    : m_size(size), m_inst_error(inst_error), m_inst_default(inst_default), m_inst_null(inst_null) { ; }
+  cInstLib(int size, int inst_default, int inst_null)
+    : m_size(size), m_inst_default(inst_default), m_inst_null(inst_null) { ; }
   virtual ~cInstLib() { ; }
 
   inline int GetSize() const { return m_size; }
@@ -69,11 +68,13 @@
   virtual int GetNopMod(const unsigned int id) = 0;
   virtual int GetNopMod(const cInstruction& inst) = 0;
   
-  inline cInstruction GetInst(const cString& name);
 
-  const cInstruction GetInstError() const { return m_inst_error; }
-  const cInstruction GetInstDefault() const { return m_inst_default; }
-  const cInstruction GetInstNull() const { return m_inst_null; }
+  int GetInstDefault() const { return m_inst_default; }
+  int GetInstNull() const { return m_inst_null; }
+
+private:
+    inline cInstruction GetInst(const cString& name);
+
 };
 
 
@@ -88,7 +89,7 @@
 {
   int idx;
   if (m_namemap.Find(name, idx)) return cInstruction(idx);
-  return m_inst_error;
+  return cInstruction(255);
 }
 
 

Modified: branches/energy/source/cpu/cInstSet.cc
===================================================================
--- branches/energy/source/cpu/cInstSet.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/cpu/cInstSet.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -38,7 +38,7 @@
 
 bool cInstSet::OK() const
 {
-  assert(m_lib_name_map.GetSize() < 256);
+  assert(m_lib_name_map.GetSize() < 255);
   assert(m_lib_nopmod_map.GetSize() < m_lib_name_map.GetSize());
 
   // Make sure that all of the redundancies are represented the appropriate
@@ -67,7 +67,7 @@
 cInstruction cInstSet::ActivateNullInst()
 {  
   const int inst_id = m_lib_name_map.GetSize();
-  const int null_fun_id = m_inst_lib->GetInstNull().GetOp();
+  const int null_fun_id = m_inst_lib->GetInstNull();
   
   assert(inst_id < 255);
   
@@ -196,7 +196,7 @@
     }
     
     // Check to make sure we are not inserting the special NULL instruction
-    if (fun_id == m_inst_lib->GetInstNull().GetOp()) {
+    if (fun_id == m_inst_lib->GetInstNull()) {
       errors.PushRear(new cString("Invalid use of NULL instruction"));
       success = false;
       continue;
@@ -342,7 +342,7 @@
 
     
     
-    if (fun_id == m_inst_lib->GetInstNull().GetOp())
+    if (fun_id == m_inst_lib->GetInstNull())
       m_world->GetDriver().RaiseFatalException(1,"Invalid use of NULL instruction");
     
     const int inst_id = m_lib_name_map.GetSize();

Modified: branches/energy/source/cpu/cInstSet.h
===================================================================
--- branches/energy/source/cpu/cInstSet.h	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/cpu/cInstSet.h	2007-10-04 12:15:21 UTC (rev 2124)
@@ -133,8 +133,8 @@
   cString FindBestMatch(const cString& in_name) const;
   bool InstInSet(const cString& in_name) const;
 
-  cInstruction GetInstDefault() const { return m_inst_lib->GetInstDefault(); }
-  cInstruction GetInstError() const { return m_inst_lib->GetInstError(); }
+  cInstruction GetInstDefault() const { return cInstruction(m_inst_lib->GetInstDefault()); }
+  cInstruction GetInstError() const { return cInstruction(255); }
   
   void LoadFromConfig();
   void LoadFromFile(const cString& filename);
@@ -183,12 +183,7 @@
 
 
   // Adding default answer if nothing is found...
-  /*
-  FIXME:  this return value is supposed to be cInstSet::GetInstError
-  which should be the same as m_inst_lib->GetInstError().
-  -- kgn
-  */
-  return cInstruction(0);
+  return cInstruction(255);
 }
 
 #endif

Modified: branches/energy/source/cpu/tInstLib.h
===================================================================
--- branches/energy/source/cpu/tInstLib.h	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/cpu/tInstLib.h	2007-10-04 12:15:21 UTC (rev 2124)
@@ -47,8 +47,8 @@
 
 public:
   tInstLib(int size, const tInstLibEntry<MethodType>* entries, cString* nopmod_names, const int* nopmods,
-           const MethodType* functions, const cInstruction error, const cInstruction def, const cInstruction null_inst)
-  : cInstLib(size, error, def, null_inst), m_entries(entries), 
+           const MethodType* functions, int def, int null_inst)
+  : cInstLib(size, def, null_inst), m_entries(entries), 
     m_nopmod_names(nopmod_names),
     m_nopmods(nopmods),
     m_functions(functions)

Modified: branches/energy/source/main/cEnvironment.cc
===================================================================
--- branches/energy/source/main/cEnvironment.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/main/cEnvironment.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -789,6 +789,14 @@
 {
   input_array.Resize(m_input_size);
   
+  //Specific inputs trump everything
+  if (m_use_specific_inputs)
+  {
+    input_array = m_specific_inputs;
+    return;
+  }
+  
+  
   if (random) {
     if (m_true_rand) {
       for (int i = 0; i < m_input_size; i++) {
@@ -1121,3 +1129,33 @@
   return true;
 }
 
+bool cEnvironment::SetReactionMinTaskCount(const cString& name, int min_count)
+{
+  cReaction* found_reaction = reaction_lib.GetReaction(name);
+  if (found_reaction == NULL) return false;
+  return found_reaction->SetMinTaskCount( min_count );
+}
+
+bool cEnvironment::SetReactionMaxTaskCount(const cString& name, int max_count)
+{
+  cReaction* found_reaction = reaction_lib.GetReaction(name);
+  if (found_reaction == NULL) return false;
+  return found_reaction->SetMaxTaskCount( max_count );
+}
+
+bool cEnvironment::SetResourceInflow(const cString& name, double _inflow )
+{
+  cResource* found_resource = resource_lib.GetResource(name);
+  if (found_resource == NULL) return false;
+  found_resource->SetInflow( _inflow );
+  return true;
+}
+
+bool cEnvironment::SetResourceOutflow(const cString& name, double _outflow )
+{
+  cResource* found_resource = resource_lib.GetResource(name);
+  if (found_resource == NULL) return false;
+  found_resource->SetOutflow( _outflow );
+  return true;
+}
+

Modified: branches/energy/source/main/cEnvironment.h
===================================================================
--- branches/energy/source/main/cEnvironment.h	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/main/cEnvironment.h	2007-10-04 12:15:21 UTC (rev 2124)
@@ -90,6 +90,8 @@
   int m_output_size;
   bool m_true_rand;
   
+  bool m_use_specific_inputs;  // Use specific inputs, rather than generating random ones
+  tArray<int>  m_specific_inputs;
   
   static bool ParseSetting(cString entry, cString& var_name, cString& var_value, const cString& var_type);
   static bool AssertInputInt(const cString& input, const cString& name, const cString& type);
@@ -123,6 +125,8 @@
 
   // Interaction with the organisms
   void SetupInputs(cAvidaContext& ctx, tArray<int>& input_array, bool random = true) const;
+  void SetSpecificInputs(const tArray<int> in_input_array) 
+    { m_use_specific_inputs = true; m_specific_inputs = in_input_array; }
   void SwapInputs(cAvidaContext& ctx, tArray<int>& src_input_array, tArray<int>& dest_input_array) const;
 
 
@@ -155,11 +159,17 @@
   bool SetReactionValue(cAvidaContext& ctx, const cString& name, double value);
   bool SetReactionValueMult(const cString& name, double value_mult);
   bool SetReactionInst(const cString& name, cString inst_name);
+  bool SetReactionMinTaskCount(const cString& name, int min_count);
+  bool SetReactionMaxTaskCount(const cString& name, int max_count);
+  bool SetResourceInflow(const cString& name, double _inflow );
+  bool SetResourceOutflow(const cString& name, double _outflow );
+  
 };
 
 
 inline cEnvironment::cEnvironment(cWorld* world) : m_world(world) , m_tasklib(world),
-  m_input_size(INPUT_SIZE_DEFAULT), m_output_size(OUTPUT_SIZE_DEFAULT), m_true_rand(false)
+  m_input_size(INPUT_SIZE_DEFAULT), m_output_size(OUTPUT_SIZE_DEFAULT), m_true_rand(false),
+  m_use_specific_inputs(false), m_specific_inputs()
 {
   mut_rates.Setup(world);
 }

Modified: branches/energy/source/main/cOrganism.h
===================================================================
--- branches/energy/source/main/cOrganism.h	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/main/cOrganism.h	2007-10-04 12:15:21 UTC (rev 2124)
@@ -225,6 +225,7 @@
   //! Check tasks based on the passed-in IO buffers and value (on_divide=false).
   void DoOutput(cAvidaContext& ctx, tBuffer<int>& input_buffer, tBuffer<int>& output_buffer, const int value);  
 
+
 protected:
   /*! The main DoOutput function.  The DoOutputs above all forward to this function. */
   void DoOutput(cAvidaContext& ctx, tBuffer<int>& input_buffer, 
@@ -232,6 +233,7 @@
 
 public:
   void ClearInput() { m_input_buf.Clear(); }
+  void ResetInput() {m_input_pointer = 0; m_input_buf.Clear(); };
   void AddOutput(int val) { m_output_buf.Add(val); }
 
   // --------  Divide Methods  --------

Modified: branches/energy/source/main/cPhenPlastGenotype.cc
===================================================================
--- branches/energy/source/main/cPhenPlastGenotype.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/main/cPhenPlastGenotype.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -47,7 +47,7 @@
 {
   UniquePhenotypes::iterator it = m_unique.begin();
   while (it != m_unique.end()){
-    delete *it;
+    delete static_cast<cPlasticPhenotype*>(*it);  // Remember to cast back
     ++it;
   }
 }
@@ -71,6 +71,7 @@
       }
     }
   }
+  
   // Update statistics
   UniquePhenotypes::iterator uit = m_unique.begin();
   m_max_fitness     =  -1.0;

Modified: branches/energy/source/main/cPhenotype.cc
===================================================================
--- branches/energy/source/main/cPhenotype.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/main/cPhenotype.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -537,11 +537,9 @@
   // and it will also be propagated to the child
   const int merit_default_bonus = m_world->GetConfig().MERIT_DEFAULT_BONUS.Get();
   if (merit_default_bonus) {
-    merit = cur_merit_base * m_world->GetConfig().DEFAULT_BONUS.Get();
+    cur_bonus = m_world->GetConfig().DEFAULT_BONUS.Get();
   }
-  else { // Default
-    merit = cur_merit_base * cur_bonus;
-  }
+  merit = cur_merit_base * cur_bonus;
   
   //BB:TODO update energy store
   SetEnergy(energy_store + cur_energy_bonus);
@@ -682,7 +680,11 @@
 
   // Update these values as needed...
   int cur_merit_base = CalcSizeMerit();
-  merit           = cur_merit_base * cur_bonus;
+  const int merit_default_bonus = m_world->GetConfig().MERIT_DEFAULT_BONUS.Get();
+  if (merit_default_bonus) {
+    cur_bonus = m_world->GetConfig().DEFAULT_BONUS.Get();
+  }
+  merit = cur_merit_base * cur_bonus;
 
   genome_length   = _genome.GetSize();
   (void) copied_size;                            // Unchanged
@@ -1440,11 +1442,9 @@
   // and it will also be propagated to the child
   int merit_default_bonus = m_world->GetConfig().MERIT_DEFAULT_BONUS.Get();
   if (merit_default_bonus) {
-    merit = cur_merit_base * m_world->GetConfig().DEFAULT_BONUS.Get();
+    cur_bonus = m_world->GetConfig().DEFAULT_BONUS.Get();
   }
-  else { // Default
-    merit = cur_merit_base * cur_bonus;
-  }
+  merit = cur_merit_base * cur_bonus;
   
   // update energy store
   energy_store += cur_energy_bonus;
@@ -1565,11 +1565,9 @@
   // and it will also be propagated to the child
   const int merit_default_bonus = m_world->GetConfig().MERIT_DEFAULT_BONUS.Get();
   if (merit_default_bonus) {
-    merit = cur_merit_base * m_world->GetConfig().DEFAULT_BONUS.Get();
+    cur_bonus = m_world->GetConfig().DEFAULT_BONUS.Get();
   }
-  else { // Defaul
-    merit = cur_merit_base * cur_bonus;
-  }
+  merit = cur_merit_base * cur_bonus;
 
   //BB:TODO update energy store
   SetEnergy(energy_store + cur_energy_bonus);

Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/main/cPopulation.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -81,10 +81,7 @@
   // Avida specific information.
   world_x = world->GetConfig().WORLD_X.Get();
   world_y = world->GetConfig().WORLD_Y.Get();
-  if(m_world->GetConfig().NUM_DEMES.Get() < 1) {
-    cout<<"There must be at least 1 deme.  Update your Avida configuration file.\n";
-    exit(1);
-  }
+
   int num_demes = m_world->GetConfig().NUM_DEMES.Get();
   const int num_cells = world_x * world_y;
   const int geometry = world->GetConfig().WORLD_GEOMETRY.Get();
@@ -110,16 +107,23 @@
     }
   }
   
+  // Invalid settings should be changed to one deme
+  if (num_demes <= 0) {
+    cout << "**********************************************\n"
+         << "******* There must be at least 1 deme. *******\n"
+         << "**** Update your Avida configuration file.****\n"
+         << "**********************************************\n";
+    num_demes = 1; // One population == one deme.
+  }
+
   // Error checking for demes vs. non-demes setup.
 #ifdef DEBUG
   const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
-#endif
-  if(num_demes > 0) {
+
+  if(num_demes > 1) {
     assert(birth_method != POSITION_CHILD_FULL_SOUP_ELDEST);
-  } else {
-    assert(birth_method != POSITION_CHILD_DEME_RANDOM);
-    num_demes = 1; // One population == one deme.
   }
+#endif
   
   // Allocate the cells, resources, and market.
   cell_array.ResizeClear(num_cells);
@@ -2856,6 +2860,19 @@
   resource_count.Set(id, new_level);
 }
 
+void cPopulation::ResetInputs(cAvidaContext& ctx)
+{
+  for (int i=0; i<GetSize(); i++)
+  {
+    cPopulationCell& cell = GetCell(i);
+    cell.ResetInputs(ctx);
+    if (cell.IsOccupied())
+    {
+      cell.GetOrganism()->ResetInput();
+    }
+  }
+}
+
 void cPopulation::BuildTimeSlicer(cChangeList * change_list)
 {
   switch (m_world->GetConfig().SLICING_METHOD.Get()) {

Modified: branches/energy/source/main/cPopulation.h
===================================================================
--- branches/energy/source/main/cPopulation.h	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/main/cPopulation.h	2007-10-04 12:15:21 UTC (rev 2124)
@@ -249,6 +249,8 @@
   double GetResource(int id) const { return resource_count.Get(id); }
   cResourceCount& GetResourceCount() { return resource_count; }
 
+  void ResetInputs(cAvidaContext& ctx);
+
   cEnvironment& GetEnvironment() { return environment; }
   int GetNumOrganisms() { return num_organisms; }
 

Modified: branches/energy/source/main/cReaction.cc
===================================================================
--- branches/energy/source/main/cReaction.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/main/cReaction.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -81,7 +81,21 @@
   return true;
 }
 
+bool cReaction::SetMinTaskCount(int min_count, int requisite_num) 
+{
+  if (requisite_num >= requisite_list.GetSize() || requisite_num < 0) return false;
+  requisite_list.GetPos(requisite_num)->SetMinTaskCount(min_count);
+  return true;
+}
 
+bool cReaction::SetMaxTaskCount(int max_count, int requisite_num) 
+{
+  if (requisite_num >= requisite_list.GetSize() || requisite_num < 0) return false;
+  requisite_list.GetPos(requisite_num)->SetMaxTaskCount(max_count);
+  return true;
+}
+
+
 double cReaction::GetValue(int process_num)
 { 
   if (process_num >= process_list.GetSize() || process_num < 0) return false;

Modified: branches/energy/source/main/cReaction.h
===================================================================
--- branches/energy/source/main/cReaction.h	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/main/cReaction.h	2007-10-04 12:15:21 UTC (rev 2124)
@@ -75,6 +75,10 @@
   // This method will modify the instruction triggered by this process
   bool ModifyInst(int inst_id, int process_num = 0); 
 
+  // These methods will modify the min/max count of the requisite for this process
+  bool SetMinTaskCount(int min_count, int requisite_num = 0); 
+  bool SetMaxTaskCount(int max_count, int requisite_num = 0); 
+
   double GetValue(int process_num = 0);
 };
 

Modified: branches/energy/source/main/cResourceCount.cc
===================================================================
--- branches/energy/source/main/cResourceCount.cc	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/main/cResourceCount.cc	2007-10-04 12:15:21 UTC (rev 2124)
@@ -283,6 +283,43 @@
   spatial_resource_count[id].SetOutflowY2(in_outflowY2);
 }
 
+int cResourceCount::GetResourceCountID(const cString& res_name)
+{
+    for (int i = 0; i < resource_name.GetSize(); i++) {
+      if (resource_name[i] == res_name) return i;
+    }
+    cerr << "Error: Unknown resource '" << res_name << "'." << endl;
+    return -1;
+}
+
+void cResourceCount::SetInflow(const cString& name, const double _inflow)
+{
+  int id = GetResourceCountID(name);
+  if (id == -1) return;
+
+  inflow_rate[id] = _inflow;
+  double step_inflow = _inflow * UPDATE_STEP;
+  double step_decay = pow(decay_rate[id], UPDATE_STEP);
+
+  inflow_precalc(id, 0) = 0.0;
+  for (int i = 1; i <= PRECALC_DISTANCE; i++) {
+    inflow_precalc(id, i) = inflow_precalc(id, i-1) * step_decay + step_inflow;
+  }
+}
+
+void cResourceCount::SetDecay(const cString& name, const double _decay)
+{
+  int id = GetResourceCountID(name);
+  if (id == -1) return;
+
+  decay_rate[id] = _decay;
+  double step_decay = pow(_decay, UPDATE_STEP);
+  decay_precalc(id, 0) = 1.0;
+  for (int i = 1; i <= PRECALC_DISTANCE; i++) {
+    decay_precalc(id, i)  = decay_precalc(id, i-1) * step_decay;
+  }
+}
+
 void cResourceCount::Update(double in_time) 
 { 
   update_time += in_time;

Modified: branches/energy/source/main/cResourceCount.h
===================================================================
--- branches/energy/source/main/cResourceCount.h	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/main/cResourceCount.h	2007-10-04 12:15:21 UTC (rev 2124)
@@ -85,6 +85,11 @@
              int in_outflowX1, int in_outflowX2, int in_outflowY1, 
              int in_outflowY, tArray<cCellResource> *in_cell_list_ptr,
              int verbosity_level);
+             
+  int GetResourceCountID(const cString& res_name);
+  void SetInflow(const cString& name, const double _inflow);
+  void SetDecay(const cString& name, const double _decay);
+  
   void Update(double in_time);
 
   int GetSize(void) const { return resource_count.GetSize(); }

Modified: branches/energy/source/tools/cString.h
===================================================================
--- branches/energy/source/tools/cString.h	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/source/tools/cString.h	2007-10-04 12:15:21 UTC (rev 2124)
@@ -331,8 +331,8 @@
    *
    * @return The integer value corresponding to the string.
    **/
-  int AsInt() const { return static_cast<int>(strtol(*this, NULL, 10)); }
-  
+  int AsInt() const { return static_cast<int>(strtol(*this, NULL, 0)); }
+
   /**
    * Convert string to double.
    *

Modified: branches/energy/support/config/avida.cfg
===================================================================
--- branches/energy/support/config/avida.cfg	2007-10-04 01:42:29 UTC (rev 2123)
+++ branches/energy/support/config/avida.cfg	2007-10-04 12:15:21 UTC (rev 2124)
@@ -36,6 +36,9 @@
 # Configuration Files
 DATA_DIR data                       # Directory in which config files are found
 INST_SET -                          # File containing instruction set
+INST_SET_FORMAT 0                   # Instruction set file format.
+                                    # 0 = Default
+                                    # 1 = New Style
 EVENT_FILE events.cfg               # File containing list of events during run
 ANALYZE_FILE analyze.cfg            # File used for analysis mode
 ENVIRONMENT_FILE environment.cfg    # File that describes the environment
@@ -50,8 +53,11 @@
                              # germline replication.
 GERMLINE_REPLACES_SOURCE 0   # Whether the source germline is updated
                              # on replication; 0=no.
-GERMLINE_RANDOM_PLACEMENT 0  # Whether the seed for a germline is placed
-                             #  randomly within the deme; 0=no.
+GERMLINE_RANDOM_PLACEMENT 0  # Defines how the seed for a germline is placed
+                             #  within the deme;
+                             # 0 = organisms is placed in center of deme, no orientation
+                             # 1 = organisms is placed in center of deme and oriented
+                             # 2 = organism is randomly placed in deme, no orientation
 MAX_DEME_AGE 500             # The maximum age of a deme (in updates) to be
                              # used for age-based replication (default=500).
 
@@ -294,6 +300,7 @@
                                        # 0 = on divide
                                        # 1 = on completion of task
                                        # 2 = on sleep
+FRAC_ENERGY_TRANSFER 0.0               # Fraction of replaced organism's energy take by new resident
 LOG_SLEEP_TIMES 0                      # Log sleep start and end times. 0/1 (off/on)
                                        # WARNING: may use lots of memory.
 
@@ -315,14 +322,20 @@
 # Promoters
 PROMOTERS_ENABLED 0             # Use the promoter/terminator execution scheme.
                                 # Certain instructions must also be included.
-PROMOTER_MAX_INST 20            # Maximum number of instructions to execute before terminating.
+PROMOTER_INST_MAX 0             # Maximum number of instructions to execute before terminating. 0 = off
 PROMOTER_PROCESSIVITY 1.0       # Chance of not terminating after each cpu cycle.
 PROMOTER_PROCESSIVITY_INST 1.0  # Chance of not terminating after each instruction.
-PROMOTER_BG_STRENGTH 0          # Probability of positions that are not promoter
-                                # instructions initiating execution (promoters are 1).
-REGULATION_STRENGTH 1           # Strength added or subtracted to a promoter by regulation.
-REGULATION_DECAY_FRAC 0.1       # Fraction of regulation that decays away. 
-                                # Max regulation = 2^(REGULATION_STRENGTH/REGULATION_DECAY_FRAC)
+TERMINATION_RESETS 0            # Does termination reset the thread's state?
+NO_ACTIVE_PROMOTER_EFFECT 0     # What happens when there are no active promoters?
+                                # 0 = Start execution at the beginning of the genome.
+                                # 1 = Kill the organism.
+                                # 2 = Stop the organism from executing any further instructions.
+PROMOTER_EXE_LENGTH 4           # Length of promoter windows used to determine execution.
+PROMOTER_EXE_THRESHOLD 3        # Minimum number of bits that must be set in a promoter window to allow execution.
+INST_CODE_LENGTH 4              # Instruction binary code length (number of bits)
+INST_CODE_DEFAULT_TYPE 0        # Default value of instruction binary code value.
+                                # 0 = All zeros
+                                # 1 = Based off the instruction number
 
 ### COLORS_GROUP ###
 # Output colors for when data files are printed in HTML mode.




More information about the Avida-cvs mailing list