[Avida-SVN] r2282 - in development/source: actions main
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Sun Jan 27 12:41:10 PST 2008
Author: brysonda
Date: 2008-01-27 15:41:10 -0500 (Sun, 27 Jan 2008)
New Revision: 2282
Modified:
development/source/actions/EnvironmentActions.cc
development/source/main/cEnvironment.cc
development/source/main/cEnvironment.h
Log:
Implement input masking, allowing for arbitrary fixed components of inputs.
Modified: development/source/actions/EnvironmentActions.cc
===================================================================
--- development/source/actions/EnvironmentActions.cc 2008-01-27 14:47:33 UTC (rev 2281)
+++ development/source/actions/EnvironmentActions.cc 2008-01-27 20:41:10 UTC (rev 2282)
@@ -408,6 +408,36 @@
+class cActionSetEnvironmentInputMask : 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)
+ {
+ 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> "; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ //First change the environmental inputs
+ m_world->GetEnvironment().SetInputMask(m_mask, m_value);
+
+ //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);
+ }
+};
+
+
+
+
class cActionSetTaskArgInt : public cAction
{
private:
@@ -678,6 +708,7 @@
action_lib->Register<cActionSetResourceOutflow>("SetResourceOutflow");
action_lib->Register<cActionSetEnvironmentInputs>("SetEnvironmentInputs");
+ action_lib->Register<cActionSetEnvironmentInputMask>("SetEnvironmentInputMask");
action_lib->Register<cActionSetPeriodicResource>("SetPeriodicResource");
action_lib->Register<cActionSetNumInstBefore0Energy>("SetNumInstBefore0Energy");
Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc 2008-01-27 14:47:33 UTC (rev 2281)
+++ development/source/main/cEnvironment.cc 2008-01-27 20:41:10 UTC (rev 2282)
@@ -789,15 +789,11 @@
{
input_array.Resize(m_input_size);
- //Specific inputs trump everything
if (m_use_specific_inputs)
{
+ // Specific inputs trump everything
input_array = m_specific_inputs;
- return;
- }
-
-
- if (random) {
+ } else if (random) {
if (m_true_rand) {
for (int i = 0; i < m_input_size; i++) {
input_array[i] = ctx.GetRandom().GetUInt((unsigned int) 1 << 31);
@@ -825,6 +821,9 @@
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-01-27 14:47:33 UTC (rev 2281)
+++ development/source/main/cEnvironment.h 2008-01-27 20:41:10 UTC (rev 2282)
@@ -93,6 +93,9 @@
bool m_use_specific_inputs; // Use specific inputs, rather than generating random ones
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);
static bool AssertInputDouble(const cString& input, const cString& name, const cString& type);
@@ -125,8 +128,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 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 SwapInputs(cAvidaContext& ctx, tArray<int>& src_input_array, tArray<int>& dest_input_array) const;
@@ -169,7 +172,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_use_specific_inputs(false), m_specific_inputs(), m_mask(0), m_mask_value(0)
{
mut_rates.Setup(world);
}
More information about the Avida-cvs
mailing list