[Avida-cvs] [avida-svn] r847 - in development/source: actions analyze event
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Fri Jul 21 07:30:31 PDT 2006
Author: brysonda
Date: 2006-07-21 10:30:30 -0400 (Fri, 21 Jul 2006)
New Revision: 847
Modified:
development/source/actions/LandscapeActions.cc
development/source/analyze/cAnalyzeUtil.cc
development/source/analyze/cAnalyzeUtil.h
development/source/event/cEventManager.cc
Log:
Move Pair Test landscape into actions framework.
Modified: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc 2006-07-20 20:11:15 UTC (rev 846)
+++ development/source/actions/LandscapeActions.cc 2006-07-21 14:30:30 UTC (rev 847)
@@ -406,7 +406,7 @@
const cString GetDescription()
{
- return "PredictWLandscape [filename='land-predict.dat']";
+ return "PredictWLandscape [string filename='land-predict.dat']";
}
void Process(cAvidaContext& ctx)
@@ -456,7 +456,7 @@
const cString GetDescription()
{
- return "PredictNuLandscape [filename='land-predict.dat']";
+ return "PredictNuLandscape [string filename='land-predict.dat']";
}
void Process(cAvidaContext& ctx)
@@ -511,7 +511,7 @@
const cString GetDescription()
{
- return "RandomLandscape [filename='land-random.dat'] [int distance=1] [int trials=0]";
+ return "RandomLandscape [string filename='land-random.dat'] [int distance=1] [int trials=0]";
}
void Process(cAvidaContext& ctx)
@@ -582,7 +582,7 @@
const cString GetDescription()
{
- return "SampleLandscape [filename='land-sample.dat'] [int trials=0]";
+ return "SampleLandscape [string filename='land-sample.dat'] [int trials=0]";
}
void Process(cAvidaContext& ctx)
@@ -647,7 +647,7 @@
const cString GetDescription()
{
- return "HillClimb [filename='hillclimb.dat']";
+ return "HillClimb [string filename='hillclimb.dat']";
}
void Process(cAvidaContext& ctx)
@@ -697,7 +697,7 @@
const cString GetDescription()
{
- return "HillClimbNeut [filename='hillclimb.dat']";
+ return "HillClimbNeut [string filename='hillclimb.dat']";
}
void Process(cAvidaContext& ctx)
@@ -747,7 +747,7 @@
const cString GetDescription()
{
- return "HillClimbRand [filename='hillclimb.dat']";
+ return "HillClimbRand [string filename='hillclimb.dat']";
}
void Process(cAvidaContext& ctx)
@@ -859,6 +859,65 @@
};
+class cActionPairTestLandscape : public cAction // @not_parallelized
+{
+private:
+ cString m_filename;
+ int m_sample_size;
+
+public:
+ cActionPairTestLandscape(cWorld* world, const cString& args)
+ : cAction(world, args), m_filename(""), m_sample_size(0)
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_filename = largs.PopWord();
+ if (largs.GetSize()) m_sample_size = largs.PopWord().AsInt();
+ }
+
+ const cString GetDescription()
+ {
+ return "PairTestLandscape [string filename=''] [int sample_size=0]";
+ }
+
+ void Process(cAvidaContext& ctx)
+ {
+ cString filename(m_filename);
+ if (filename == "") filename.Set("land-pairs-%d.dat", m_world->GetStats().GetUpdate());
+
+ cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+ std::ofstream& outfile = m_world->GetDataFileOFStream(filename);
+
+ if (ctx.GetAnalyzeMode()) {
+ if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_ON) {
+ cString msg("Pair Testing Landscape 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("Pair Testing Landscape...");
+ }
+
+ 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);
+ if (m_sample_size) land.TestPairs(ctx, m_sample_size, outfile);
+ else land.TestAllPairs(ctx, outfile);
+ }
+ } else {
+ if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_DETAILS)
+ m_world->GetDriver().NotifyComment("Pair Testing Landscape...");
+
+ const cGenome& best_genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
+ cLandscape land(m_world, best_genome, inst_set);
+ if (m_sample_size) land.TestPairs(ctx, m_sample_size, outfile);
+ else land.TestAllPairs(ctx, outfile);
+ }
+
+ m_world->GetDataFileManager().Remove(filename);
+ }
+};
+
+
void RegisterLandscapeActions(cActionLibrary* action_lib)
{
action_lib->Register<cActionAnalyzeLandscape>("AnalyzeLandscape");
@@ -873,6 +932,7 @@
action_lib->Register<cActionHillClimb>("HillClimb");
action_lib->Register<cActionHillClimb>("HillClimbNeut");
action_lib->Register<cActionHillClimb>("HillClimbRand");
+ action_lib->Register<cActionPairTestLandscape>("PairTestLandscape");
action_lib->Register<cActionMutationalNeighborhood>("MutationalNeighborhood");
Modified: development/source/analyze/cAnalyzeUtil.cc
===================================================================
--- development/source/analyze/cAnalyzeUtil.cc 2006-07-20 20:11:15 UTC (rev 846)
+++ development/source/analyze/cAnalyzeUtil.cc 2006-07-21 14:30:30 UTC (rev 847)
@@ -111,24 +111,6 @@
}
-void cAnalyzeUtil::PairTestLandscape(cWorld* world, const cGenome &genome, cInstSet &inst_set,
- int sample_size, int update)
-{
- cAvidaContext& ctx = world->GetDefaultContext();
-
- cLandscape landscape(world, genome, inst_set);
-
- cString filename;
- filename.Set("pairtest.%d.dat", update);
- ofstream& fp = world->GetDataFileOFStream(filename);
-
- if (sample_size != 0) landscape.TestPairs(ctx, sample_size, fp);
- else landscape.TestAllPairs(ctx, fp);
-
- world->GetDataFileManager().Remove(filename);
-}
-
-
void cAnalyzeUtil::CalcConsensus(cWorld* world, int lines_saved)
{
const int num_inst = world->GetHardwareManager().GetInstSet().GetSize();
Modified: development/source/analyze/cAnalyzeUtil.h
===================================================================
--- development/source/analyze/cAnalyzeUtil.h 2006-07-20 20:11:15 UTC (rev 846)
+++ development/source/analyze/cAnalyzeUtil.h 2006-07-21 14:30:30 UTC (rev 847)
@@ -34,11 +34,6 @@
int num_trials, int update);
- // Landscape-based analysis
- static void PairTestLandscape(cWorld* world, const cGenome & genome, cInstSet & inst_set,
- int sample_size=0, int update=-1);
-
-
// Population-wide analysis
static void CalcConsensus(cWorld* world, int lines_saved);
Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc 2006-07-20 20:11:15 UTC (rev 846)
+++ development/source/event/cEventManager.cc 2006-07-21 14:30:30 UTC (rev 847)
@@ -253,35 +253,6 @@
}
};
-///// pairtest_landscape /////
-
-/**
-* If sample_size = 0, pairtest the full landscape.
- **/
-
-
-class cEvent_pairtest_landscape : public cEvent {
-private:
- int sample_size;
-public:
- const cString GetName() const { return "pairtest_landscape"; }
- const cString GetDescription() const { return "pairtest_landscape [int sample_size=0]"; }
-
- void Configure(cWorld* world, const cString& in_args)
- {
- m_world = world;
- m_args = in_args;
- cString args(in_args);
- if (args == "") sample_size=0; else sample_size=args.PopWord().AsInt();
- }
- ///// pairtest_landscape /////
- void Process(){
- cGenome & genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
- cAnalyzeUtil::PairTestLandscape(m_world, genome, m_world->GetHardwareManager().GetInstSet(),
- sample_size, m_world->GetStats().GetUpdate());
- }
-};
-
///// test_dom /////
/**
@@ -1473,7 +1444,6 @@
REGISTER(set_copy_mut);
REGISTER(mod_point_mut);
REGISTER(set_point_mut);
- REGISTER(pairtest_landscape);
REGISTER(test_dom);
REGISTER(analyze_population);
More information about the Avida-cvs
mailing list