[Avida-cvs] [avida-svn] r811 - in development/source: actions event
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Jul 6 19:34:10 PDT 2006
Author: brysonda
Date: 2006-07-06 22:34:09 -0400 (Thu, 06 Jul 2006)
New Revision: 811
Modified:
development/source/actions/PopulationActions.cc
development/source/event/cEventManager.cc
Log:
Transition KillRate event into actions framework. Rename Apocalypse action to KillProb so that it matches the family of Kill* actions.
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2006-07-07 02:03:16 UTC (rev 810)
+++ development/source/actions/PopulationActions.cc 2006-07-07 02:34:09 UTC (rev 811)
@@ -17,6 +17,7 @@
#include "cInstUtil.h"
#include "cPopulation.h"
#include "cPopulationCell.h"
+#include "cStats.h"
#include "cWorld.h"
@@ -401,18 +402,18 @@
removal probability (double) default: 0.9
The probability with which a single organism is removed.
*/
-class cActionApocalypse : public cAction
+class cActionKillProb : public cAction
{
private:
double m_killprob;
public:
- cActionApocalypse(cWorld* world, const cString& args) : cAction(world, args), m_killprob(0.9)
+ cActionKillProb(cWorld* world, const cString& args) : cAction(world, args), m_killprob(0.9)
{
cString largs(args);
if (largs.GetSize()) m_killprob = largs.PopWord().AsDouble();
}
- const cString GetDescription() { return "Apocalypse [double killprob=0.9]"; }
+ const cString GetDescription() { return "KillProb [double probability=0.9]"; }
void Process(cAvidaContext& ctx)
{
@@ -426,6 +427,46 @@
/*
+ Randomly removes a certain proportion of the population.
+ In principle, this event does the same thing as the apocalypse event.
+ However, instead of a probability, here one has to specify a rate. The
+ rate has the same unit as fitness. So if the average fitness is 20000,
+ then you remove 50% of the population on every update with a removal rate
+ of 10000.
+
+ Parameters:
+ removal rate (double)
+ The rate at which organisms are removed.
+*/
+class cActionKillRate : public cAction
+{
+private:
+ double m_killrate;
+public:
+ cActionKillRate(cWorld* world, const cString& args) : cAction(world, args), m_killrate(0.0)
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_killrate = largs.PopWord().AsDouble();
+ }
+
+ const cString GetDescription() { return "KillRate <double probability>"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ double ave_merit = m_world->GetStats().SumMerit().Average();
+ if (ave_merit <= 0) ave_merit = 1; // make sure that we don't get NAN's or negative numbers
+ ave_merit /= m_world->GetConfig().AVE_TIME_SLICE.Get();
+ const double kill_prob = m_killrate / ave_merit;
+ for (int i = 0; i < m_world->GetPopulation().GetSize(); i++) {
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(i);
+ if (cell.IsOccupied() == false) continue;
+ if (ctx.GetRandom().P(kill_prob)) m_world->GetPopulation().KillOrganism(cell);
+ }
+ }
+};
+
+
+/*
Kills all cell in a rectangle.
Parameters:
@@ -508,7 +549,8 @@
action_lib->Register<cActionInjectParasite>("InjectParasite");
action_lib->Register<cActionInjectParasitePair>("InjectParasitePair");
- action_lib->Register<cActionApocalypse>("Apocalypse");
+ action_lib->Register<cActionKillProb>("KillProb");
+ action_lib->Register<cActionKillProb>("KillRate");
action_lib->Register<cActionKillRectangle>("KillRectangle");
@@ -519,6 +561,7 @@
action_lib->Register<cActionInjectRange>("inject_range");
action_lib->Register<cActionInject>("inject_sequence");
- action_lib->Register<cActionApocalypse>("apocalypse");
+ action_lib->Register<cActionKillProb>("apocalypse");
+ action_lib->Register<cActionKillRate>("rate_kill");
action_lib->Register<cActionKillRectangle>("kill_rectangle");
}
Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc 2006-07-07 02:03:16 UTC (rev 810)
+++ development/source/event/cEventManager.cc 2006-07-07 02:34:09 UTC (rev 811)
@@ -582,52 +582,6 @@
};
-
-///// rate_kill /////
-
-/**
-* Randomly removes a certain proportion of the population.
- * In principle, this event does the same thing as the apocalypse event.
- * However, instead of a probability, here one has to specify a rate. The
- * rate has the same unit as fitness. So if the average fitness is 20000,
- * then you remove 50% of the population on every update with a removal rate
- * of 10000.
- *
- * Parameters:
- * removal rate (double)
- * The rate at which organisms are removed.
- **/
-
-
-class cEvent_rate_kill : public cEvent {
-private:
- double kill_rate;
-public:
- const cString GetName() const { return "rate_kill"; }
- const cString GetDescription() const { return "rate_kill <double kill_rate>"; }
-
- void Configure(cWorld* world, const cString& in_args)
- {
- m_world = world;
- m_args = in_args;
- cString args(in_args);
- kill_rate = args.PopWord().AsDouble();
- }
- ///// rate_kill /////
- void Process(){
- double ave_merit = m_world->GetStats().SumMerit().Average();
- if ( ave_merit <= 0 )
- ave_merit = 1; // make sure that we don't get NAN's or negative numbers
- ave_merit /= m_world->GetConfig().AVE_TIME_SLICE.Get();
- const double kill_prob = kill_rate / ave_merit;
- for (int i = 0; i < m_world->GetPopulation().GetSize(); i++) {
- cPopulationCell & cell = m_world->GetPopulation().GetCell(i);
- if (cell.IsOccupied() == false) continue;
- if (m_world->GetRandom().P(kill_prob)) m_world->GetPopulation().KillOrganism(cell);
- }
- }
-};
-
///// serial_transfer /////
/**
@@ -1840,7 +1794,6 @@
REGISTER(task_snapshot);
REGISTER(print_viable_tasks_data);
- REGISTER(rate_kill);
REGISTER(serial_transfer);
REGISTER(hillclimb);
REGISTER(hillclimb_neut);
More information about the Avida-cvs
mailing list