[Avida-SVN] r2119 - in development: documentation source/actions source/cpu source/main source/tools support/config

barrick at myxo.css.msu.edu barrick at myxo.css.msu.edu
Tue Oct 2 06:49:15 PDT 2007


Author: barrick
Date: 2007-10-02 09:49:10 -0400 (Tue, 02 Oct 2007)
New Revision: 2119

Modified:
   development/documentation/actions.html
   development/source/actions/EnvironmentActions.cc
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/main/cEnvironment.cc
   development/source/main/cEnvironment.h
   development/source/main/cOrganism.h
   development/source/main/cPopulation.cc
   development/source/main/cPopulation.h
   development/source/tools/cString.h
   development/support/config/avida.cfg
Log:
1. SetEnvironmentInputs action

Allows setting specific inputs for all organisms in the population (and changing them during the run). Inspired by Matt, orgs can now "sense" rewards if they change at the same time as inputs by looking at the input numbers directly.

2. BitConsensus instruction

Sets a register to 0 or 1 by looking at how many of the individual bits of a register value are one. Majority (>=50%) 1's, gives a 1, otherwise 0. (Useful for sensing the difference between input numbers.)

3. cString::AsInt will now convert 0xFF67A621 style values.




Modified: development/documentation/actions.html
===================================================================
--- development/documentation/actions.html	2007-10-02 12:47:30 UTC (rev 2118)
+++ development/documentation/actions.html	2007-10-02 13:49:10 UTC (rev 2119)
@@ -130,10 +130,10 @@
       <br /><a href="#PrintPhenotypeStatus">PrintPhenotypeStatus</a>
       <br /><a href="#PrintPhenotypicPlasticity">PrintPhenotypicPlasticity</a>
       <br /><a href="#PrintPopulationDistanceData">PrintPopulationDistanceData</a>
+      <br /><a href="#PrintRelativeFitnessHistogram">PrintRelativeFitnessHistogram</a>
     </td>
     <td>
-	  <a href="#PrintRelativeFitnessHistogram">PrintRelativeFitnessHistogram</a>
-      <br /><a href="#PrintResourceData">PrintResourceData</a>
+      <a href="#PrintResourceData">PrintResourceData</a>
       <br /><a href="#PrintSpeciesAbundanceData">PrintSpeciesAbundanceData</a>
       <br /><a href="#PrintStatsData">PrintStatsData</a>
       <br /><a href="#PrintTasksSnapshot">PrintTasksSnapshot</a>
@@ -154,6 +154,7 @@
       <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>
@@ -1014,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;
   

Modified: development/source/actions/EnvironmentActions.cc
===================================================================
--- development/source/actions/EnvironmentActions.cc	2007-10-02 12:47:30 UTC (rev 2118)
+++ development/source/actions/EnvironmentActions.cc	2007-10-02 13:49:10 UTC (rev 2119)
@@ -360,6 +360,52 @@
   }
 };
 
+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:
@@ -598,6 +644,8 @@
   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: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2007-10-02 12:47:30 UTC (rev 2118)
+++ development/source/cpu/cHardwareCPU.cc	2007-10-02 13:49:10 UTC (rev 2119)
@@ -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),
@@ -4474,6 +4475,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: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2007-10-02 12:47:30 UTC (rev 2118)
+++ development/source/cpu/cHardwareCPU.h	2007-10-02 13:49:10 UTC (rev 2119)
@@ -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: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc	2007-10-02 12:47:30 UTC (rev 2118)
+++ development/source/main/cEnvironment.cc	2007-10-02 13:49:10 UTC (rev 2119)
@@ -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++) {

Modified: development/source/main/cEnvironment.h
===================================================================
--- development/source/main/cEnvironment.h	2007-10-02 12:47:30 UTC (rev 2118)
+++ development/source/main/cEnvironment.h	2007-10-02 13:49:10 UTC (rev 2119)
@@ -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;
 
 
@@ -164,7 +168,8 @@
 
 
 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: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h	2007-10-02 12:47:30 UTC (rev 2118)
+++ development/source/main/cOrganism.h	2007-10-02 13:49:10 UTC (rev 2119)
@@ -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: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2007-10-02 12:47:30 UTC (rev 2118)
+++ development/source/main/cPopulation.cc	2007-10-02 13:49:10 UTC (rev 2119)
@@ -2768,6 +2768,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: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h	2007-10-02 12:47:30 UTC (rev 2118)
+++ development/source/main/cPopulation.h	2007-10-02 13:49:10 UTC (rev 2119)
@@ -244,6 +244,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: development/source/tools/cString.h
===================================================================
--- development/source/tools/cString.h	2007-10-02 12:47:30 UTC (rev 2118)
+++ development/source/tools/cString.h	2007-10-02 13:49:10 UTC (rev 2119)
@@ -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: development/support/config/avida.cfg
===================================================================
--- development/support/config/avida.cfg	2007-10-02 12:47:30 UTC (rev 2118)
+++ development/support/config/avida.cfg	2007-10-02 13:49:10 UTC (rev 2119)
@@ -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