[Avida-SVN] r2367 - in development/source: actions main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Sat Feb 23 12:35:08 PST 2008


Author: brysonda
Date: 2008-02-23 15:35:07 -0500 (Sat, 23 Feb 2008)
New Revision: 2367

Modified:
   development/source/actions/EnvironmentActions.cc
   development/source/main/cEnvironment.cc
   development/source/main/cEnvironment.h
Log:
Change environment mask behavior to specify the bits bits to randomize within specific inputs.

Modified: development/source/actions/EnvironmentActions.cc
===================================================================
--- development/source/actions/EnvironmentActions.cc	2008-02-23 17:39:22 UTC (rev 2366)
+++ development/source/actions/EnvironmentActions.cc	2008-02-23 20:35:07 UTC (rev 2367)
@@ -430,29 +430,26 @@
 
 
 
-class cActionSetEnvironmentInputMask : public cAction
+class cActionSetEnvironmentRandomMask : public cAction
 {
 private:
   unsigned int m_mask;
-  unsigned int m_value;
   
 public:
-  cActionSetEnvironmentInputMask(cWorld* world, const cString& args) : cAction(world, args), m_mask(0), m_value(0)
+  cActionSetEnvironmentRandomMask(cWorld* world, const cString& args) : cAction(world, args), m_mask(0)
   {
     cString largs(args);
     if (largs.GetSize()) m_mask = largs.PopWord().AsInt();
-    if (largs.GetSize()) m_value = largs.PopWord().AsInt();
   }
   
-  static const cString GetDescription() { return "Arguments: <int mask> <int value> "; }
+  static const cString GetDescription() { return "Arguments: <int mask>"; }
   
   void Process(cAvidaContext& ctx)
   {
-    //First change the environmental inputs
-    m_world->GetEnvironment().SetInputMask(m_mask, m_value);
+    // First change the environmental input mask
+    m_world->GetEnvironment().SetSpecificRandomMask(m_mask);
     
-    //Now immediately change the inputs in each cell and
-    //clear the input array of each organism so changes take effect
+    // Now immediately change the inputs in each cell and clear the input array of each organism so changes take effect
     m_world->GetPopulation().ResetInputs(ctx);
   }
 };
@@ -731,7 +728,7 @@
   action_lib->Register<cActionSetResourceOutflow>("SetResourceOutflow");
 
   action_lib->Register<cActionSetEnvironmentInputs>("SetEnvironmentInputs");
-  action_lib->Register<cActionSetEnvironmentInputMask>("SetEnvironmentInputMask");
+  action_lib->Register<cActionSetEnvironmentRandomMask>("SetEnvironmentRandomMask");
 
   action_lib->Register<cActionSetPeriodicResource>("SetPeriodicResource");
   action_lib->Register<cActionSetNumInstBefore0Energy>("SetNumInstBefore0Energy");

Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc	2008-02-23 17:39:22 UTC (rev 2366)
+++ development/source/main/cEnvironment.cc	2008-02-23 20:35:07 UTC (rev 2367)
@@ -799,6 +799,13 @@
   {
     // Specific inputs trump everything
     input_array = m_specific_inputs;
+    
+    // If a mask has been set, process the inputs with it
+    if (m_mask) {
+      for (int i = 0; i < m_input_size; i++) {
+        input_array[i] = (input_array[i] & ~m_mask) | (m_mask & ctx.GetRandom().GetUInt(1 << 24));
+      }
+    }
   } else if (random) {
     if (m_true_rand) {
       for (int i = 0; i < m_input_size; i++) {
@@ -827,9 +834,6 @@
       input_array[i] = input_array[i % 3] << (i / 3);
     }
   }
-  
-  // If a mask has been set, process the inputs with it
-  if (m_mask) for (int i = 0; i < m_input_size; i++) input_array[i] = (input_array[i] & ~m_mask) | m_mask_value;
 }
 
 

Modified: development/source/main/cEnvironment.h
===================================================================
--- development/source/main/cEnvironment.h	2008-02-23 17:39:22 UTC (rev 2366)
+++ development/source/main/cEnvironment.h	2008-02-23 20:35:07 UTC (rev 2367)
@@ -94,7 +94,6 @@
   tArray<int>  m_specific_inputs;
   
   unsigned int m_mask;
-  unsigned int m_mask_value;
   
   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);
@@ -129,7 +128,7 @@
   // 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 SetInputMask(unsigned int mask, unsigned int value) { m_mask = mask; m_mask_value = mask & value; }
+  void SetSpecificRandomMask(unsigned int mask) { m_mask = mask; }
   void SwapInputs(cAvidaContext& ctx, tArray<int>& src_input_array, tArray<int>& dest_input_array) const;
 
 
@@ -172,7 +171,7 @@
 
 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_use_specific_inputs(false), m_specific_inputs(), m_mask(0), m_mask_value(0)
+  m_use_specific_inputs(false), m_specific_inputs(), m_mask(0)
 {
   mut_rates.Setup(world);
 }




More information about the Avida-cvs mailing list