[Avida-cvs] [avida-svn] r846 - in development/source: actions analyze event
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Jul 20 13:11:15 PDT 2006
Author: brysonda
Date: 2006-07-20 16:11:15 -0400 (Thu, 20 Jul 2006)
New Revision: 846
Modified:
development/source/actions/PrintActions.cc
development/source/analyze/cAnalyzeUtil.cc
development/source/analyze/cAnalyzeUtil.h
development/source/event/cEventManager.cc
Log:
Move printing of population genetic distance data into actions.
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2006-07-20 18:43:25 UTC (rev 845)
+++ development/source/actions/PrintActions.cc 2006-07-20 20:11:15 UTC (rev 846)
@@ -745,7 +745,7 @@
if (largs.GetSize()) m_filename = largs.PopWord();
}
- const cString GetDescription() { return "PrintDumpMemory [string fname='']"; }
+ const cString GetDescription() { return "DumpMemory [string fname='']"; }
void Process(cAvidaContext& ctx)
{
@@ -757,6 +757,77 @@
};
+/*
+ This action goes through all genotypes currently present in the population,
+ and writes into an output file the names of the genotypes, the fitness as
+ determined in the test cpu, and the genetic distance to a reference genome.
+*/
+class cActionPrintPopulationDistanceData : public cAction
+{
+private:
+ cString m_creature;
+ cString m_filename;
+ int m_save_genotypes;
+
+public:
+ cActionPrintPopulationDistanceData(cWorld* world, const cString& args)
+ : cAction(world, args), m_creature("START_CREATURE"), m_filename(""), m_save_genotypes(0)
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_creature = largs.PopWord();
+ if (largs.GetSize()) m_filename = largs.PopWord();
+ if (largs.GetSize()) m_save_genotypes = largs.PopWord().AsInt();
+
+ if (m_creature == "" || m_creature == "START_CREATURE") m_creature = m_world->GetConfig().START_CREATURE.Get();
+}
+
+ const cString GetDescription() { return "PrintPopulationDistanceData [string creature=\"START_CREATURE\"] [string fname=\"\"] [int save_genotypes=0]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ cString filename(m_filename);
+ if (filename == "") filename.Set("pop_distance-%d.dat", m_world->GetStats().GetUpdate());
+ cDataFile& df = m_world->GetDataFile(filename);
+
+ double sum_fitness = 0;
+ int sum_num_organisms = 0;
+
+ // load the reference genome
+ cGenome reference_genome(cInstUtil::LoadGenome(m_creature, m_world->GetHardwareManager().GetInstSet()));
+
+ // cycle over all genotypes
+ cGenotype* cur_genotype = m_world->GetClassificationManager().GetBestGenotype();
+ for (int i = 0; i < m_world->GetClassificationManager().GetGenotypeCount(); i++) {
+ const cGenome& genome = cur_genotype->GetGenome();
+ const int num_orgs = cur_genotype->GetNumOrganisms();
+
+ // now output
+
+ sum_fitness += cur_genotype->GetTestFitness() * num_orgs;
+ sum_num_organisms += num_orgs;
+
+ df.Write(cur_genotype->GetName(), "Genotype Name");
+ df.Write(cur_genotype->GetTestFitness(), "Fitness (test-cpu)");
+ df.Write(num_orgs, "Abundance");
+ df.Write(cGenomeUtil::FindHammingDistance(reference_genome, genome), "Hamming distance to reference");
+ df.Write(cGenomeUtil::FindEditDistance(reference_genome, genome), "Levenstein distance to reference");
+ df.Write(genome.AsString(), "Genome");
+
+ // save into archive
+ if (m_save_genotypes) {
+ cTestUtil::PrintGenome(m_world, genome, cStringUtil::Stringf("archive/%s.org", static_cast<const char*>(cur_genotype->GetName())));
+ }
+
+ // ...and advance to the next genotype...
+ cur_genotype = cur_genotype->GetNext();
+ }
+ df.WriteRaw(cStringUtil::Stringf("# ave fitness from Test CPU's: %d\n", sum_fitness / sum_num_organisms));
+
+ m_world->GetDataFileManager().Remove(filename);
+ }
+};
+
+
void RegisterPrintActions(cActionLibrary* action_lib)
{
// Stats Out Files
@@ -796,6 +867,7 @@
action_lib->Register<cActionPrintDominantParasiteGenotype>("PrintDominantParasiteGenotype");
action_lib->Register<cActionPrintDetailedFitnessData>("PrintDetailedFitnessData");
action_lib->Register<cActionPrintGeneticDistanceData>("PrintGenericDistanceData");
+ action_lib->Register<cActionPrintPopulationDistanceData>("PrintPopulationDistanceData");
action_lib->Register<cActionPrintDebug>("PrintDebug");
action_lib->Register<cActionPrintGenotypes>("PrintGenotypes");
@@ -837,6 +909,7 @@
action_lib->Register<cActionPrintDominantParasiteGenotype>("print_dom_parasite");
action_lib->Register<cActionPrintDetailedFitnessData>("print_detailed_fitness_data");
action_lib->Register<cActionPrintGeneticDistanceData>("print_genetic_distance_data");
+ action_lib->Register<cActionPrintPopulationDistanceData>("genetic_distance_pop_dump");
action_lib->Register<cActionPrintGenotypes>("print_genotypes");
action_lib->Register<cActionDumpMemory>("dump_memory");
Modified: development/source/analyze/cAnalyzeUtil.cc
===================================================================
--- development/source/analyze/cAnalyzeUtil.cc 2006-07-20 18:43:25 UTC (rev 845)
+++ development/source/analyze/cAnalyzeUtil.cc 2006-07-20 20:11:15 UTC (rev 846)
@@ -366,65 +366,6 @@
/**
-* This function goes through all genotypes currently present in the soup,
- * and writes into an output file the names of the genotypes, the fitness
- * as determined in the test cpu, and the genetic distance to a reference
- * genome.
- *
- * @param fp The stream into which the data should be saved.
- * @param reference_genome The reference genome.
- * @param save_creatures A bool that indicates whether creatures should be
- * saved into the classmgr or not.
- **/
-
-void cAnalyzeUtil::GeneticDistancePopDump(cWorld* world, ofstream& fp,
- const char * creature_name, bool save_creatures)
-{
- double sum_fitness = 0;
- int sum_num_organisms = 0;
-
- // load the reference genome
- cGenome reference_genome( cInstUtil::LoadGenome(creature_name, world->GetHardwareManager().GetInstSet()) );
-
- // first, print out some documentation...
- fp << "# (1) genotype name (2) fitness [test-cpu] (3) abundance (4) Hamming distance to reference (5) Levenstein distance to reference" << endl;
- fp << "# reference genome is the START_CREATURE" << endl;
-
- // cycle over all genotypes
- cGenotype * cur_genotype = world->GetClassificationManager().GetBestGenotype();
- for (int i = 0; i < world->GetClassificationManager().GetGenotypeCount(); i++) {
- const cGenome & genome = cur_genotype->GetGenome();
- const int num_orgs = cur_genotype->GetNumOrganisms();
-
- // now output
-
- sum_fitness += cur_genotype->GetTestFitness() * num_orgs;
- sum_num_organisms += num_orgs;
-
- fp << cur_genotype->GetName() << " " // 1 name
- << cur_genotype->GetTestFitness() << " " // 2 fitness
- << num_orgs << " " // 3 abundance
- << cGenomeUtil::FindHammingDistance(reference_genome, genome) << " "
- << cGenomeUtil::FindEditDistance(reference_genome, genome) << " " // 5
- << genome.AsString() << " " // 6 genome
- << endl;
-
- // save into classmgr
- if (save_creatures) {
- char filename[40];
- sprintf(filename, "classmgr/%s", static_cast<const char*>(cur_genotype->GetName()) );
- cTestUtil::PrintGenome(world, genome, filename);
- }
-
- // ...and advance to the next genotype...
- cur_genotype = cur_genotype->GetNext();
- }
- fp << "# ave fitness from Test CPU's: "
- << sum_fitness/sum_num_organisms << endl;
-}
-
-
-/**
* This function goes through all creatures in the soup, and writes out
* how many tasks the different creatures have done up to now. It counts
* every task only once, i.e., if a creature does 'put' three times, that
Modified: development/source/analyze/cAnalyzeUtil.h
===================================================================
--- development/source/analyze/cAnalyzeUtil.h 2006-07-20 18:43:25 UTC (rev 845)
+++ development/source/analyze/cAnalyzeUtil.h 2006-07-20 20:11:15 UTC (rev 846)
@@ -46,9 +46,6 @@
double sample_prob=1, bool landscape=false,
bool save_genotype=false);
- static void GeneticDistancePopDump(cWorld* world, std::ofstream& fp,
- const char * creature_name, bool save_creatures=false);
-
static void TaskSnapshot(cWorld* world, std::ofstream& fp);
static void TaskGrid(cWorld* world, std::ofstream& fp);
static void PrintViableTasksData(cWorld* world, std::ofstream& fp);
Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc 2006-07-20 18:43:25 UTC (rev 845)
+++ development/source/event/cEventManager.cc 2006-07-20 20:11:15 UTC (rev 846)
@@ -342,42 +342,6 @@
};
-///// genetic_distance_pop_dump /////
-
-/**
-**/
-
-
-class cEvent_genetic_distance_pop_dump : public cEvent {
-private:
- cString creature_name;
- cString filename;
- int save_genotype;
-public:
- const cString GetName() const { return "genetic_distance_pop_dump"; }
- const cString GetDescription() const { return "genetic_distance_pop_dump [string creature_name=\"\"] [string filename=\"\"] [int save_genotype=0]"; }
-
- void Configure(cWorld* world, const cString& in_args)
- {
- m_world = world;
- m_args = in_args;
- cString args(in_args);
- if (args == "") creature_name=""; else creature_name=args.PopWord();
- if (args == "") filename=""; else filename=args.PopWord();
- if (args == "") save_genotype=0; else save_genotype=args.PopWord().AsInt();
- }
- ///// genetic_distance_pop_dump /////
- void Process() {
- if (creature_name == "" || creature_name == "START_CREATURE")
- creature_name = m_world->GetConfig().START_CREATURE.Get();
- if (filename == "" || filename == "AUTO")
- filename.Set("pop_dump_%d.dat",m_world->GetStats().GetUpdate());
- cAnalyzeUtil::GeneticDistancePopDump(m_world, m_world->GetDataFileOFStream(filename),
- creature_name, save_genotype);
- m_world->GetDataFileManager().Remove(filename);
- }
-};
-
///// task_snapshot /////
/**
@@ -1513,7 +1477,6 @@
REGISTER(test_dom);
REGISTER(analyze_population);
- REGISTER(genetic_distance_pop_dump);
REGISTER(task_snapshot);
REGISTER(print_viable_tasks_data);
@@ -1547,7 +1510,7 @@
REGISTER(set_reaction_inst);
}
-cEvent* cEventManager::ConstructEvent(const cString name, const cString & args)
+cEvent* cEventManager::ConstructEvent(const cString name, const cString& args)
{
cEvent* event = Create(name);
More information about the Avida-cvs
mailing list