[Avida-SVN] r3249 - development/source/actions
connel42 at myxo.css.msu.edu
connel42 at myxo.css.msu.edu
Wed May 20 08:24:43 PDT 2009
Author: connel42
Date: 2009-05-20 11:24:43 -0400 (Wed, 20 May 2009)
New Revision: 3249
Modified:
development/source/actions/PopulationActions.cc
Log:
Added deme random kill event, KillDemePercent
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2009-05-20 13:53:19 UTC (rev 3248)
+++ development/source/actions/PopulationActions.cc 2009-05-20 15:24:43 UTC (rev 3249)
@@ -2859,6 +2859,52 @@
};
+
+
+/*
+ Kill a percentage of organisms in all demes
+
+ Parameters:
+ - The percent of living organisms to kill (default: 0)
+ */
+
+class cActionKillDemePercent : public cAction
+ {
+ private:
+ double m_pctkills;
+ public:
+ cActionKillDemePercent(cWorld* world, const cString& args) : cAction(world, args), m_pctkills(0)
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_pctkills = largs.PopWord().AsDouble();
+
+ assert(m_pctkills >= 0);
+ assert(m_pctkills <= 1);
+ }
+
+ static const cString GetDescription() { return "Arguments: [int pctkills=0.0]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ int target_cell;
+
+ for (int d = 0; d < m_world->GetPopulation().GetNumDemes(); d++) {
+ for (int c = 0; c < m_world->GetPopulation().GetDeme(d).GetWidth() * m_world->GetPopulation().GetDeme(d).GetHeight(); c++) {
+ target_cell = m_world->GetPopulation().GetDeme(d).GetCellID(c);
+
+ if( m_world->GetRandom().GetDouble() < m_pctkills) {
+ m_world->GetPopulation().KillOrganism(m_world->GetPopulation().GetCell(target_cell));
+ m_world->GetStats().IncNumOrgsKilled();
+ }
+
+ } //End iterating through all cells
+
+ } //End iterating through all demes
+
+ } //End Process()
+ };
+
+
void RegisterPopulationActions(cActionLibrary* action_lib)
{
action_lib->Register<cActionInject>("Inject");
@@ -2966,4 +3012,5 @@
action_lib->Register<cActionConnectCells>("connect_cells");
action_lib->Register<cActionDisconnectCells>("disconnect_cells");
action_lib->Register<cActionSwapCells>("swap_cells");
+ action_lib->Register<cActionKillDemePercent>("KillDemePercent");
}
More information about the Avida-cvs
mailing list