[Avida-cvs] [avida-svn] r812 - in development/source: actions event
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Jul 6 19:54:14 PDT 2006
Author: brysonda
Date: 2006-07-06 22:54:14 -0400 (Thu, 06 Jul 2006)
New Revision: 812
Modified:
development/source/actions/LandscapeActions.cc
development/source/actions/PopulationActions.cc
development/source/event/cEventManager.cc
Log:
Transition SerialTransfer, along with HillClimb* into the actions framework.
Modified: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc 2006-07-07 02:34:09 UTC (rev 811)
+++ development/source/actions/LandscapeActions.cc 2006-07-07 02:54:14 UTC (rev 812)
@@ -632,6 +632,157 @@
};
+class cActionHillClimb : public cAction // @not_parallized
+{
+private:
+ cString m_filename;
+
+public:
+ cActionHillClimb(cWorld* world, const cString& args)
+ : cAction(world, args), m_filename("hillclimb.dat")
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_filename = largs.PopWord();
+ }
+
+ const cString GetDescription()
+ {
+ return "HillClimb [filename='hillclimb.dat']";
+ }
+
+ void Process(cAvidaContext& ctx)
+ {
+ cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+ std::ofstream& outfile = m_world->GetDataFileOFStream(m_filename);
+
+ if (ctx.GetAnalyzeMode()) {
+ if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_ON) {
+ cString msg("Calculating Hill Climb on batch ");
+ msg += cStringUtil::Convert(m_world->GetAnalyze().GetCurrentBatchID());
+ m_world->GetDriver().NotifyComment(msg);
+ } else if (m_world->GetConfig().VERBOSITY.Get() > VERBOSE_SILENT) {
+ m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
+ }
+
+ tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
+ cAnalyzeGenotype* genotype = NULL;
+ while (genotype = batch_it.Next()) {
+ cLandscape land(m_world, genotype->GetGenome(), inst_set);
+ land.HillClimb(ctx, outfile);
+ }
+ } else {
+ if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_DETAILS)
+ m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
+
+ const cGenome& best_genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
+ cLandscape land(m_world, best_genome, inst_set);
+ land.HillClimb(ctx, outfile);
+ }
+ }
+};
+
+
+class cActionHillClimbNeut : public cAction // @not_parallized
+{
+private:
+ cString m_filename;
+
+public:
+ cActionHillClimbNeut(cWorld* world, const cString& args)
+ : cAction(world, args), m_filename("hillclimb.dat")
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_filename = largs.PopWord();
+ }
+
+ const cString GetDescription()
+ {
+ return "HillClimbNeut [filename='hillclimb.dat']";
+ }
+
+ void Process(cAvidaContext& ctx)
+ {
+ cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+ std::ofstream& outfile = m_world->GetDataFileOFStream(m_filename);
+
+ if (ctx.GetAnalyzeMode()) {
+ if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_ON) {
+ cString msg("Calculating Hill Climb on batch ");
+ msg += cStringUtil::Convert(m_world->GetAnalyze().GetCurrentBatchID());
+ m_world->GetDriver().NotifyComment(msg);
+ } else if (m_world->GetConfig().VERBOSITY.Get() > VERBOSE_SILENT) {
+ m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
+ }
+
+ tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
+ cAnalyzeGenotype* genotype = NULL;
+ while (genotype = batch_it.Next()) {
+ cLandscape land(m_world, genotype->GetGenome(), inst_set);
+ land.HillClimb_Neut(ctx, outfile);
+ }
+ } else {
+ if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_DETAILS)
+ m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
+
+ const cGenome& best_genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
+ cLandscape land(m_world, best_genome, inst_set);
+ land.HillClimb_Neut(ctx, outfile);
+ }
+ }
+};
+
+
+class cActionHillClimbRand : public cAction // @not_parallized
+{
+private:
+ cString m_filename;
+
+public:
+ cActionHillClimbRand(cWorld* world, const cString& args)
+ : cAction(world, args), m_filename("hillclimb.dat")
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_filename = largs.PopWord();
+ }
+
+ const cString GetDescription()
+ {
+ return "HillClimbRand [filename='hillclimb.dat']";
+ }
+
+ void Process(cAvidaContext& ctx)
+ {
+ cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+ std::ofstream& outfile = m_world->GetDataFileOFStream(m_filename);
+
+ if (ctx.GetAnalyzeMode()) {
+ if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_ON) {
+ cString msg("Calculating Hill Climb on batch ");
+ msg += cStringUtil::Convert(m_world->GetAnalyze().GetCurrentBatchID());
+ m_world->GetDriver().NotifyComment(msg);
+ } else if (m_world->GetConfig().VERBOSITY.Get() > VERBOSE_SILENT) {
+ m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
+ }
+
+ tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
+ cAnalyzeGenotype* genotype = NULL;
+ while (genotype = batch_it.Next()) {
+ cLandscape land(m_world, genotype->GetGenome(), inst_set);
+ land.HillClimb_Rand(ctx, outfile);
+ }
+ } else {
+ if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_DETAILS)
+ m_world->GetDriver().NotifyComment("Calculating Hill Climb...");
+
+ const cGenome& best_genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
+ cLandscape land(m_world, best_genome, inst_set);
+ land.HillClimb_Rand(ctx, outfile);
+ }
+ }
+};
+
+
+
class cActionMutationalNeighborhood : public cAction // @parallelized
{
private:
@@ -719,5 +870,10 @@
action_lib->Register<cActionPredictNuLandscape>("PredictNuLandscape");
action_lib->Register<cActionRandomLandscape>("RandomLandscape");
action_lib->Register<cActionSampleLandscape>("SampleLandscape");
+ action_lib->Register<cActionHillClimb>("HillClimb");
+ action_lib->Register<cActionHillClimb>("HillClimbNeut");
+ action_lib->Register<cActionHillClimb>("HillClimbRand");
+
action_lib->Register<cActionMutationalNeighborhood>("MutationalNeighborhood");
+
}
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2006-07-07 02:34:09 UTC (rev 811)
+++ development/source/actions/PopulationActions.cc 2006-07-07 02:54:14 UTC (rev 812)
@@ -428,7 +428,7 @@
/*
Randomly removes a certain proportion of the population.
- In principle, this event does the same thing as the apocalypse event.
+ In principle, this event does the same thing as the KillProb action.
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
@@ -537,7 +537,46 @@
};
+/*
+ This event does again the same thing as KillProb. However, now
+ the number of organisms to be retained can be specified
+ exactly. Also, it is possible to specify whether any of these
+ organisms may be dead or not.
+
+ Parameters:
+ transfer size (int) default: 1
+ The number of organisms to retain. If there are fewer living
+ organisms than the specified transfer size, then all living
+ organisms are retained.
+ ignore deads (int) default: 1
+ When set to 1, only living organisms are retained. Otherwise,
+ every type of organism can be retained.
+*/
+class cActionSerialTransfer : public cAction
+{
+private:
+ int m_size;
+ int m_ignore_deads;
+public:
+ cActionSerialTransfer(cWorld* world, const cString& args) : cAction(world, args), m_size(1), m_ignore_deads(1)
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_size = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_ignore_deads = largs.PopWord().AsInt();
+
+ if (m_size < 0) m_size = 1;
+ }
+
+ const cString GetDescription() { return "SerialTransfer [int transfer_size=1] [int ignore_deads=1]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ m_world->GetPopulation().SerialTransfer(m_size, m_ignore_deads);
+ }
+};
+
+
void RegisterPopulationActions(cActionLibrary* action_lib)
{
action_lib->Register<cActionInject>("Inject");
@@ -552,6 +591,7 @@
action_lib->Register<cActionKillProb>("KillProb");
action_lib->Register<cActionKillProb>("KillRate");
action_lib->Register<cActionKillRectangle>("KillRectangle");
+ action_lib->Register<cActionSerialTransfer>("SerialTransfer");
// @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
@@ -564,4 +604,5 @@
action_lib->Register<cActionKillProb>("apocalypse");
action_lib->Register<cActionKillRate>("rate_kill");
action_lib->Register<cActionKillRectangle>("kill_rectangle");
+ action_lib->Register<cActionSerialTransfer>("serial_transfer");
}
Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc 2006-07-07 02:34:09 UTC (rev 811)
+++ development/source/event/cEventManager.cc 2006-07-07 02:54:14 UTC (rev 812)
@@ -582,129 +582,6 @@
};
-///// serial_transfer /////
-
-/**
-* This event does again the same thing as apocalypse. However, now
- * the number of organisms to be retained can be specified
- * exactly. Also, it is possible to specify whether any of these
- * organisms may be dead or not.
- *
- * Parameters:
- * transfer size (int) default: 1
- * The number of organisms to retain. If there are fewer living
- * organisms than the specified transfer size, then all living
- * organisms are retained.
- * ignore deads (int) default: 1
- * When set to 1, only living organisms are retained. Otherwise,
- * every type of organism can be retained.
- **/
-
-
-class cEvent_serial_transfer : public cEvent {
-private:
- int transfer_size;
- int ignore_deads;
-public:
- const cString GetName() const { return "serial_transfer"; }
- const cString GetDescription() const { return "serial_transfer [int transfer_size=1] [int ignore_deads=1]"; }
-
- void Configure(cWorld* world, const cString& in_args)
- {
- m_world = world;
- m_args = in_args;
- cString args(in_args);
- if (args == "") transfer_size=1; else transfer_size=args.PopWord().AsInt();
- if (args == "") ignore_deads=1; else ignore_deads=args.PopWord().AsInt();
- }
- ///// serial_transfer /////
- void Process(){
- m_world->GetPopulation().SerialTransfer( transfer_size, ignore_deads );
- }
-};
-
-///// hillclimb /////
-
-/**
-* Does a hill climb with the dominant genotype.
- **/
-
-
-class cEvent_hillclimb : public cEvent {
-private:
-public:
- const cString GetName() const { return "hillclimb"; }
- const cString GetDescription() const { return "hillclimb"; }
-
- void Configure(cWorld* world, const cString& in_args)
- {
- m_world = world;
- m_args = in_args; }
- ///// hillclimb /////
- void Process(){
- cAvidaContext& ctx = m_world->GetDefaultContext();
-
- cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
- cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
- landscape.HillClimb(ctx, m_world->GetDataFileOFStream("hillclimb.dat"));
- m_world->GetDataFileManager().Remove("hillclimb.dat");
- }
-};
-
-///// hillclimb_neut /////
-
-/**
-**/
-
-
-class cEvent_hillclimb_neut : public cEvent {
-private:
-public:
- const cString GetName() const { return "hillclimb_neut"; }
- const cString GetDescription() const { return "hillclimb_neut"; }
-
- void Configure(cWorld* world, const cString& in_args)
- {
- m_world = world;
- m_args = in_args; }
- ///// hillclimb_neut /////
- void Process(){
- cAvidaContext& ctx = m_world->GetDefaultContext();
-
- cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
- cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
- landscape.HillClimb_Neut(ctx, m_world->GetDataFileOFStream("hillclimb.dat"));
- m_world->GetDataFileManager().Remove("hillclimb.dat");
- }
-};
-
-///// hillclimb_rand /////
-
-/**
-**/
-
-
-class cEvent_hillclimb_rand : public cEvent {
-private:
-public:
- const cString GetName() const { return "hillclimb_rand"; }
- const cString GetDescription() const { return "hillclimb_rand"; }
-
- void Configure(cWorld* world, const cString& in_args)
- {
- m_world = world;
- m_args = in_args; }
- ///// hillclimb_rand /////
- void Process(){
- cAvidaContext& ctx = m_world->GetDefaultContext();
-
- cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
- cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
- landscape.HillClimb_Rand(ctx, m_world->GetDataFileOFStream("hillclimb.dat"));
- m_world->GetDataFileManager().Remove("hillclimb.dat");
- }
-};
-
///// compete_demes /////
/**
@@ -1794,10 +1671,6 @@
REGISTER(task_snapshot);
REGISTER(print_viable_tasks_data);
- REGISTER(serial_transfer);
- REGISTER(hillclimb);
- REGISTER(hillclimb_neut);
- REGISTER(hillclimb_rand);
REGISTER(compete_demes);
REGISTER(reset_demes);
REGISTER(print_deme_stats);
More information about the Avida-cvs
mailing list