[Avida-SVN] r2114 - in development: documentation source/actions source/main
barrick at myxo.css.msu.edu
barrick at myxo.css.msu.edu
Wed Sep 26 18:20:54 PDT 2007
Author: barrick
Date: 2007-09-26 21:20:54 -0400 (Wed, 26 Sep 2007)
New Revision: 2114
Modified:
development/documentation/actions.html
development/source/actions/EnvironmentActions.cc
development/source/main/cEnvironment.cc
development/source/main/cEnvironment.h
development/source/main/cReaction.cc
development/source/main/cReaction.h
development/source/main/cResourceCount.cc
development/source/main/cResourceCount.h
Log:
New environment actions:
cActionSetReactionMinTaskCount
cActionSetReactionMaxTaskCount
cActionSetResourceInflow
cActionSetResourceOutflow
Even added documentation (!).
Modified: development/documentation/actions.html
===================================================================
--- development/documentation/actions.html 2007-09-26 22:39:32 UTC (rev 2113)
+++ development/documentation/actions.html 2007-09-27 01:20:54 UTC (rev 2114)
@@ -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,12 +127,12 @@
<br /><a href="#PrintLogFitnessHistogram">PrintLogFitnessHistogram</a>
<br /><a href="#PrintMutationRateData">PrintMutationRateData</a>
<br /><a href="#PrintPhenotypeData">PrintPhenotypeData</a>
+ <br /><a href="#PrintPhenotypeStatus">PrintPhenotypeStatus</a>
+ <br /><a href="#PrintPhenotypicPlasticity">PrintPhenotypicPlasticity</a>
+ <br /><a href="#PrintPopulationDistanceData">PrintPopulationDistanceData</a>
</td>
<td>
- <a href="#PrintPhenotypeStatus">PrintPhenotypeStatus</a>
- <br /><a href="#PrintPhenotypicPlasticity">PrintPhenotypicPlasticity</a>
- <br /><a href="#PrintPopulationDistanceData">PrintPopulationDistanceData</a>
- <br /><a href="#PrintRelativeFitnessHistogram">PrintRelativeFitnessHistogram</a>
+ <a href="#PrintRelativeFitnessHistogram">PrintRelativeFitnessHistogram</a>
<br /><a href="#PrintResourceData">PrintResourceData</a>
<br /><a href="#PrintSpeciesAbundanceData">PrintSpeciesAbundanceData</a>
<br /><a href="#PrintStatsData">PrintStatsData</a>
@@ -156,9 +156,13 @@
<br /><a href="#SerialTransfer">SerialTransfer</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>
@@ -1022,6 +1026,29 @@
</li>
<li>
+ <strong><a name="SetResourceInflow">SetResourceInflow</a></strong>
+ <<span class="cmdarg">string res_name</span>> <<span class="cmdarg">double inflow</span>>
+
+ <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>
+ <<span class="cmdarg">string res_name</span>> <<span class="cmdarg">double outflow</span>>
+
+ <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>
<<span class="cmdarg">string reaction_name</span>> <<span class="cmdarg">double value</span>>
@@ -1033,6 +1060,28 @@
</p>
</li>
<li>
+ <strong><a name="SetReactionMinTaskCount">SetReactionMinTaskCount</a></strong>
+ <<span class="cmdarg">string reaction_name</span>> <<span class="cmdarg">int task_count</span>>
+
+ <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>
+ <<span class="cmdarg">string reaction_name</span>> <<span class="cmdarg">int task_count</span>>
+
+ <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>
<<span class="cmdarg">string reaction_name</span>> <<span class="cmdarg">double value</span>>
Modified: development/source/actions/EnvironmentActions.cc
===================================================================
--- development/source/actions/EnvironmentActions.cc 2007-09-26 22:39:32 UTC (rev 2113)
+++ development/source/actions/EnvironmentActions.cc 2007-09-27 01:20:54 UTC (rev 2114)
@@ -266,6 +266,100 @@
}
};
+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 cActionSetTaskArgInt : public cAction
{
private:
@@ -498,7 +592,12 @@
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<cActionSetPeriodicResource>("SetPeriodicResource");
action_lib->Register<cActionSetNumInstBefore0Energy>("SetNumInstBefore0Energy");
Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc 2007-09-26 22:39:32 UTC (rev 2113)
+++ development/source/main/cEnvironment.cc 2007-09-27 01:20:54 UTC (rev 2114)
@@ -1121,3 +1121,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: development/source/main/cEnvironment.h
===================================================================
--- development/source/main/cEnvironment.h 2007-09-26 22:39:32 UTC (rev 2113)
+++ development/source/main/cEnvironment.h 2007-09-27 01:20:54 UTC (rev 2114)
@@ -155,6 +155,11 @@
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 );
+
};
Modified: development/source/main/cReaction.cc
===================================================================
--- development/source/main/cReaction.cc 2007-09-26 22:39:32 UTC (rev 2113)
+++ development/source/main/cReaction.cc 2007-09-27 01:20:54 UTC (rev 2114)
@@ -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: development/source/main/cReaction.h
===================================================================
--- development/source/main/cReaction.h 2007-09-26 22:39:32 UTC (rev 2113)
+++ development/source/main/cReaction.h 2007-09-27 01:20:54 UTC (rev 2114)
@@ -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: development/source/main/cResourceCount.cc
===================================================================
--- development/source/main/cResourceCount.cc 2007-09-26 22:39:32 UTC (rev 2113)
+++ development/source/main/cResourceCount.cc 2007-09-27 01:20:54 UTC (rev 2114)
@@ -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: development/source/main/cResourceCount.h
===================================================================
--- development/source/main/cResourceCount.h 2007-09-26 22:39:32 UTC (rev 2113)
+++ development/source/main/cResourceCount.h 2007-09-27 01:20:54 UTC (rev 2114)
@@ -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(); }
More information about the Avida-cvs
mailing list