[Avida-cvs] [avida-svn] r763 - in development/source: actions analyze
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Tue Jun 20 18:15:57 PDT 2006
Author: brysonda
Date: 2006-06-20 21:15:57 -0400 (Tue, 20 Jun 2006)
New Revision: 763
Modified:
development/source/actions/LandscapeActions.cc
development/source/analyze/cAnalyze.cc
development/source/analyze/cAnalyze.h
development/source/analyze/cAnalyzeGenotype.cc
development/source/analyze/cAnalyzeGenotype.h
Log:
Restore Lazy evaluation of landscapes when printing out items in a DETAIL command. Lazy evaluation will be serialized, though. On multi-cpu systems it will be better to call the CalcLandscape action in advance.
Modified: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc 2006-06-21 00:17:43 UTC (rev 762)
+++ development/source/actions/LandscapeActions.cc 2006-06-21 01:15:57 UTC (rev 763)
@@ -136,6 +136,43 @@
};
+/*
+ Precalculates landscape data for use in detail files. The primary advantage of
+ this is that it supports multithreaded execution, whereas lazy evaluation during
+ detailing will be serialized.
+*/
+class cActionCalcLandscape : public cAction
+{
+public:
+ cActionCalcLandscape(cWorld* world, const cString& args) : cAction(world, args) { ; }
+
+ const cString GetDescription()
+ {
+ return "CalcLandscape";
+ }
+
+ void Process(cAvidaContext& ctx)
+ {
+ if (ctx.GetAnalyzeMode()) {
+ if (m_world->GetConfig().VERBOSITY.Get() >= VERBOSE_ON) {
+ cString msg("Precalculating landscape for 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("Precalculating landscape...");
+ }
+
+ cAnalyzeJobQueue& jobqueue = m_world->GetAnalyze().GetJobQueue();
+ tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
+ for (cAnalyzeGenotype* cur_genotype = batch_it.Next(); cur_genotype; cur_genotype = batch_it.Next()) {
+ jobqueue.AddJob(new tAnalyzeJob<cAnalyzeGenotype>(cur_genotype, &cAnalyzeGenotype::CalcLandscape));
+ }
+ jobqueue.Execute();
+ }
+ }
+};
+
+
class cActionFullLandscape : public cAction
{
private:
@@ -348,6 +385,7 @@
void RegisterLandscapeActions(cActionLibrary* action_lib)
{
action_lib->Register<cActionAnalyzeLandscape>("AnalyzeLandscape");
+ action_lib->Register<cActionCalcLandscape>("CalcLandscape");
action_lib->Register<cActionFullLandscape>("FullLandscape");
action_lib->Register<cActionRandomLandscape>("RandomLandscape");
action_lib->Register<cActionSampleLandscape>("SampleLandscape");
Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc 2006-06-21 00:17:43 UTC (rev 762)
+++ development/source/analyze/cAnalyze.cc 2006-06-21 01:15:57 UTC (rev 763)
@@ -980,10 +980,10 @@
for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
cString cur_line = input_file.GetLine(line_id);
- cAnalyzeGenotype * genotype = new cAnalyzeGenotype(m_world, default_genome, inst_set);
+ cAnalyzeGenotype* genotype = new cAnalyzeGenotype(m_world, default_genome, inst_set);
output_it.Reset();
- tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+ tDataEntryCommand<cAnalyzeGenotype>* data_command = NULL;
while ((data_command = output_it.Next()) != NULL) {
data_command->SetTarget(genotype);
// genotype->SetSpecialArgs(data_command->GetArgs());
@@ -1667,18 +1667,6 @@
}
}
-void cAnalyze::CommandCalcLandscape(cString cur_string)
-{
- tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-
- cout << "Calculating Landscape..." << endl;
-
- for (cAnalyzeGenotype* cur_genotype = batch_it.Next(); cur_genotype; cur_genotype = batch_it.Next()) {
- m_jobqueue.AddJob(new tAnalyzeJob<cAnalyzeGenotype>(cur_genotype, &cAnalyzeGenotype::CalcLandscape));
- }
- m_jobqueue.Execute();
-}
-
void cAnalyze::CommandDetail(cString cur_string)
{
if (verbose >= nAnalyze::VERBOSE_ON) cout << "Detailing batch " << cur_batch << endl;
@@ -7751,7 +7739,6 @@
AddLibraryDef("INCLUDE", &cAnalyze::IncludeFile);
AddLibraryDef("SYSTEM", &cAnalyze::CommandSystem);
AddLibraryDef("INTERACTIVE", &cAnalyze::CommandInteractive);
- AddLibraryDef("CALC_LANDSCAPE", &cAnalyze::CommandCalcLandscape);
// Functions...
AddLibraryDef("FUNCTION", &cAnalyze::FunctionCreate);
Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h 2006-06-21 00:17:43 UTC (rev 762)
+++ development/source/analyze/cAnalyze.h 2006-06-21 01:15:57 UTC (rev 763)
@@ -237,7 +237,6 @@
void IncludeFile(cString cur_string);
void CommandSystem(cString cur_string);
void CommandInteractive(cString cur_string);
- void CommandCalcLandscape(cString cur_string);
// Functions...
void FunctionCreate(cString cur_string, tList<cAnalyzeCommand> & clist);
Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc 2006-06-21 00:17:43 UTC (rev 762)
+++ development/source/analyze/cAnalyzeGenotype.cc 2006-06-21 01:15:57 UTC (rev 763)
@@ -14,7 +14,6 @@
#include "cCPUTestInfo.h"
#include "cHardwareManager.h"
#include "cInstSet.h"
-#include "cLandscape.h"
#include "cOrganism.h"
#include "cPhenotype.h"
#include "cTestCPU.h"
@@ -56,12 +55,7 @@
, ancestor_dist(0)
, parent_muts("")
, knockout_stats(NULL)
- , land_frac_dead(0.0)
- , land_frac_neg(0.0)
- , land_frac_neut(0.0)
- , land_frac_pos(0.0)
- , land_complexity(0.0)
- , land_ave_fitness(0.0)
+ , m_land(NULL)
{
// Make sure that the sequences jive with the inst_set
for (int i = 0; i < genome.GetSize(); i++) {
@@ -106,16 +100,11 @@
, ancestor_dist(0)
, parent_muts("")
, knockout_stats(NULL)
- , land_frac_dead(0.0)
- , land_frac_neg(0.0)
- , land_frac_neut(0.0)
- , land_frac_pos(0.0)
- , land_complexity(0.0)
- , land_ave_fitness(0.0)
+ , m_land(NULL)
{
}
-cAnalyzeGenotype::cAnalyzeGenotype(const cAnalyzeGenotype & _gen)
+cAnalyzeGenotype::cAnalyzeGenotype(const cAnalyzeGenotype& _gen)
: m_world(_gen.m_world)
, genome(_gen.genome)
, inst_set(_gen.inst_set)
@@ -146,12 +135,7 @@
, ancestor_dist(_gen.ancestor_dist)
, parent_muts(_gen.parent_muts)
, knockout_stats(NULL)
- , land_frac_dead(_gen.land_frac_dead)
- , land_frac_neg(_gen.land_frac_neg)
- , land_frac_neut(_gen.land_frac_neut)
- , land_frac_pos(_gen.land_frac_pos)
- , land_complexity(_gen.land_complexity)
- , land_ave_fitness(_gen.land_ave_fitness)
+ , m_land(NULL)
{
if (_gen.knockout_stats != NULL) {
knockout_stats = new cAnalyzeKnockouts;
@@ -337,17 +321,21 @@
delete testcpu;
}
+void cAnalyzeGenotype::CheckLand() const
+{
+ if (m_land == NULL) {
+ m_land = new cLandscape(m_world, genome, inst_set);
+ m_land->SetDistance(1);
+ m_land->Process(m_world->GetDefaultContext());
+ }
+}
+
+
void cAnalyzeGenotype::CalcLandscape(cAvidaContext& ctx)
{
- cLandscape landscape(m_world, genome, inst_set);
- landscape.SetDistance(1);
- landscape.Process(ctx);
- land_frac_dead = landscape.GetProbDead();
- land_frac_neg = landscape.GetProbNeg();
- land_frac_neut = landscape.GetProbNeut();
- land_frac_pos = landscape.GetProbPos();
- land_complexity = landscape.GetComplexity();
- land_ave_fitness = landscape.GetAveFitness();
+ if (m_land == NULL) m_land = new cLandscape(m_world, genome, inst_set);
+ m_land->SetDistance(1);
+ m_land->Process(ctx);
}
void cAnalyzeGenotype::Recalculate(cAvidaContext& ctx, cTestCPU* testcpu, cAnalyzeGenotype* parent_genotype)
Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h 2006-06-21 00:17:43 UTC (rev 762)
+++ development/source/analyze/cAnalyzeGenotype.h 2006-06-21 01:15:57 UTC (rev 763)
@@ -19,6 +19,9 @@
#ifndef cGenome_h
#include "cGenome.h"
#endif
+#ifndef cLandscape_h
+#include "cLandscape.h"
+#endif
#ifndef cString_h
#include "cString.h"
#endif
@@ -121,12 +124,7 @@
};
mutable cAnalyzeKnockouts * knockout_stats;
- double land_frac_dead;
- double land_frac_neg;
- double land_frac_neut;
- double land_frac_pos;
- double land_complexity;
- double land_ave_fitness;
+ mutable cLandscape* m_land;
// Group 5 : More complex stats (obtained indvidually, through tests)
cString task_order;
@@ -144,6 +142,9 @@
int CalcMaxGestation() const;
void CalcKnockouts(bool check_pairs = false, bool check_chart = false) const;
+ void CheckLand() const;
+
+
public:
cAnalyzeGenotype(cWorld* world, cString symbol_string, cInstSet & in_inst_set);
cAnalyzeGenotype(cWorld* world, const cGenome & _genome, cInstSet & in_inst_set);
@@ -243,12 +244,12 @@
const tArray< tArray<int> > & GetKO_TaskCounts() const;
// Landscape accessors
- double GetFracDead() const { return land_frac_dead; }
- double GetFracNeg() const { return land_frac_neg; }
- double GetFracNeut() const { return land_frac_neut; }
- double GetFracPos() const { return land_frac_pos; }
- double GetComplexity() const { return land_complexity; }
- double GetLandscapeFitness() const { return land_ave_fitness; }
+ double GetFracDead() const { CheckLand(); return m_land->GetProbDead(); }
+ double GetFracNeg() const { CheckLand(); return m_land->GetProbNeg(); }
+ double GetFracNeut() const { CheckLand(); return m_land->GetProbNeut(); }
+ double GetFracPos() const { CheckLand(); return m_land->GetProbPos(); }
+ double GetComplexity() const { CheckLand(); return m_land->GetComplexity(); }
+ double GetLandscapeFitness() const { CheckLand(); return m_land->GetAveFitness(); }
double GetFitnessRatio() const { return fitness_ratio; }
double GetEfficiencyRatio() const { return efficiency_ratio; }
More information about the Avida-cvs
mailing list