[Avida-SVN] r1552 - in development/source: actions classification main
matt at myxo.css.msu.edu
matt at myxo.css.msu.edu
Mon May 14 11:25:33 PDT 2007
Author: matt
Date: 2007-05-14 14:25:33 -0400 (Mon, 14 May 2007)
New Revision: 1552
Modified:
development/source/actions/PrintActions.cc
development/source/classification/cClassificationManager.cc
development/source/classification/cClassificationManager.h
development/source/classification/cLineage.cc
development/source/classification/cLineage.h
development/source/main/cAvidaConfig.h
development/source/main/cOrganism.h
development/source/main/cPopulation.cc
development/source/main/cPopulation.h
development/source/main/cWorld.cc
Log:
Implement coalescence clade tracking, a second pass operation.
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2007-05-14 18:21:34 UTC (rev 1551)
+++ development/source/actions/PrintActions.cc 2007-05-14 18:25:33 UTC (rev 1552)
@@ -685,6 +685,92 @@
/*
+ This function requires that TRACK_CCLADES be enabled and avida is
+ not in analyze mode.
+
+ Parameters
+ filename (cString)
+ Where the clade information should be stored.
+
+ Please note the structure to this file is not a matrix.
+ Each line is formatted as follows:
+ update number_cclades ccladeID0 ccladeID0_count ccladeID1
+
+ @MRR May 2007
+ */
+class cActionPrintCCladeCounts : public cAction
+{
+private:
+ cString filename;
+ bool first_time;
+
+public:
+ cActionPrintCCladeCounts(cWorld* world, const cString& args)
+ : cAction(world, args)
+ {
+ cString largs(args);
+ filename = (!largs.GetSize()) ? "cclade_count.dat" : largs.PopWord();
+ first_time = true;
+ }
+
+ static const cString GetDescription() { return "Arguments: [filename = \"cclade_count.dat\"]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ //Handle possible errors
+ if (ctx.GetAnalyzeMode())
+ m_world->GetDriver().RaiseFatalException(1, "PrintCCladeCount requires avida to be in run mode.");
+
+ if (m_world->GetConfig().TRACK_CCLADES.Get() == 0)
+ m_world->GetDriver().RaiseFatalException(1, "PrintCCladeCount requires coalescence clade tracking to be enabled.");
+
+
+ tHashTable<int, int> cclade_count; //A count for each clade in the population
+ set<int> clade_ids;
+
+ cPopulation& pop = m_world->GetPopulation();
+ const int update = m_world->GetStats().GetUpdate();
+
+ //For each organism in the population, find what coalescence clade it belongs to and count
+ for (int k = 0; k < pop.GetSize(); k++)
+ {
+ if (!pop.GetCell(k).IsOccupied())
+ continue;
+ int cclade_id = pop.GetCell(k).GetOrganism()->GetCCladeLabel();
+ int count = 0;
+ if (!cclade_count.Find(cclade_id,count))
+ clade_ids.insert(cclade_id);
+ cclade_count.SetValue(cclade_id, ++count);
+ }
+
+ ofstream& fp = m_world->GetDataFileManager().GetOFStream(filename);
+ if (!fp.is_open())
+ m_world->GetDriver().RaiseFatalException(1, "PrintCCladeCount: Unable to open output file.");
+ if (first_time)
+ {
+ fp << "# Each line is formatted as follows:" << endl;
+ fp << "# update number_cclades ccladeID0 ccladeID0_count ccladeID1" << endl;
+ fp << endl;
+ first_time = false;
+ }
+ fp << update << " "
+ << clade_ids.size() << " ";
+
+ set<int>::iterator sit = clade_ids.begin();
+ while(sit != clade_ids.end())
+ {
+ int count = 0;
+ cclade_count.Find(*sit, count);
+ fp << *sit << " " << count << " ";
+ sit++;
+ }
+ fp << endl;
+
+ }
+};
+
+
+/*
@MRR March 2007
This function prints out fitness data. The main point is that it
calculates the average fitness from info from the testCPU + the actual
@@ -1808,6 +1894,8 @@
action_lib->Register<cActionPrintPhenotypeData>("PrintPhenotypeData");
action_lib->Register<cActionPrintPhenotypeStatus>("PrintPhenotypeStatus");
action_lib->Register<cActionPrintDemeStats>("PrintDemeStats");
+ action_lib->Register<cActionPrintCCladeCounts>("PrintCCladeCounts");
+
// Processed Data
action_lib->Register<cActionPrintData>("PrintData");
Modified: development/source/classification/cClassificationManager.cc
===================================================================
--- development/source/classification/cClassificationManager.cc 2007-05-14 18:21:34 UTC (rev 1551)
+++ development/source/classification/cClassificationManager.cc 2007-05-14 18:25:33 UTC (rev 1552)
@@ -1260,7 +1260,29 @@
fp << endl;
}
+//@MRR Coalescence Clades
+void cClassificationManager::LoadCCladeFounders(const cString& filename)
+{
+ ifstream fin(filename);
+ if (!fin.is_open())
+ m_world->GetDriver().RaiseFatalException(1, "Unable to open coalescence clade ids.");
+ int id;
+ fin >> id;
+ while(!fin.eof())
+ {
+ m_cclade_ids.insert(id);
+ fin >> id;
+ }
+ fin.close();
+}
+bool cClassificationManager::IsCCladeFounder(const int id) const
+{
+ set<int>::const_iterator it = m_cclade_ids.find(id);
+ return (it == m_cclade_ids.end()) ? false : true;
+}
+
+
unsigned int cClassificationManager::FindCRC(const cGenome & in_genome) const
{
unsigned int total = 0;
Modified: development/source/classification/cClassificationManager.h
===================================================================
--- development/source/classification/cClassificationManager.h 2007-05-14 18:21:34 UTC (rev 1551)
+++ development/source/classification/cClassificationManager.h 2007-05-14 18:25:33 UTC (rev 1552)
@@ -27,6 +27,7 @@
#define cClassificationManager_h
#include <list>
+#include <set>
#ifndef defs_h
#include "defs.h"
@@ -96,6 +97,9 @@
cLineage* m_max_fitness_lineage; // lineage with the single highest fitness
cLineage* m_dominant_lineage; // the lineage with the largest number of creatures.
int m_lineage_next_id;
+
+ // CClade @MRR
+ std::set<int> m_cclade_ids;
// Private Helper Functions
@@ -206,7 +210,10 @@
void PrintLineageTotals(const cString& filename, bool verbose=false);
void PrintLineageCurCounts(const cString& filename);
-
+ // Coalescence Clade
+ void LoadCCladeFounders(const cString& filename);
+ bool IsCCladeFounder(const int id) const;
+
// Utility Functions
bool SaveClone(std::ofstream& fp);
bool LoadClone(std::ifstream & fp);
Modified: development/source/classification/cLineage.cc
===================================================================
--- development/source/classification/cLineage.cc 2007-05-14 18:21:34 UTC (rev 1551)
+++ development/source/classification/cLineage.cc 2007-05-14 18:25:33 UTC (rev 1552)
@@ -149,4 +149,12 @@
m_ave_fitness_changed = false;
}
+tArray<const cGenotype*> cLineage::GetCurrentGenotypes(cAvidaContext& ctx) const
+{
+ tArray<const cGenotype*> genotypes;
+ map<const cGenotype*, int, gt_gentype>::const_iterator it = m_genotype_map.begin();
+ for(; it != m_genotype_map.end(); it++)
+ genotypes.Push(it->first);
+ return genotypes;
+}
Modified: development/source/classification/cLineage.h
===================================================================
--- development/source/classification/cLineage.h 2007-05-14 18:21:34 UTC (rev 1551)
+++ development/source/classification/cLineage.h 2007-05-14 18:25:33 UTC (rev 1552)
@@ -27,6 +27,7 @@
#define cLineage_h
#include <map>
+#include "tArray.h"
class cAvidaContext;
class cGenotype;
@@ -150,6 +151,8 @@
* the creation of this lineage
**/
double GetLineageStat2 () const { return m_lineage_stat2; }
+
+ tArray<const cGenotype*> cLineage::GetCurrentGenotypes(cAvidaContext& ctx) const;
};
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2007-05-14 18:21:34 UTC (rev 1551)
+++ development/source/main/cAvidaConfig.h 2007-05-14 18:25:33 UTC (rev 1552)
@@ -345,6 +345,10 @@
CONFIG_ADD_VAR(ANALYZE_OPTION_1, cString, "", "String variable accessible from analysis scripts");
CONFIG_ADD_VAR(ANALYZE_OPTION_2, cString, "", "String variable accessible from analysis scripts");
+ CONFIG_ADD_GROUP(SECOND_PASS_GROUP, "Tracking metrics known after the running experiment previously");
+ CONFIG_ADD_VAR(TRACK_CCLADES, int, 0, "Enable tracking of coalescence clades");
+ CONFIG_ADD_VAR(TRACK_CCLADES_IDS, cString, "coalescence.ids", "File storing coalescence IDs");
+
#endif
void Load(const cString& filename, const bool& crash_if_not_found);
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2007-05-14 18:21:34 UTC (rev 1551)
+++ development/source/main/cOrganism.h 2007-05-14 18:25:33 UTC (rev 1552)
@@ -95,8 +95,9 @@
int m_id; // unique id for each org, is just the number it was born
int m_lineage_label; // a lineages tag; inherited unchanged in offspring
cLineage* m_lineage; // A lineage descriptor... (different from label)
-
- // Other stats
+ int cclade_id; // @MRR Coalescence clade information (set in cPopulation)
+
+ // Other stats
cCPUMemory m_child_genome; // Child genome, while under construction.
sCPUStats m_cpu_stats; // Info for statistics
@@ -160,6 +161,10 @@
void SetLineage(cLineage* in_lineage) { m_lineage = in_lineage; }
cLineage* GetLineage() const { return m_lineage; }
+ void SetCCladeLabel( int in_label ) { cclade_id = in_label; }; //@MRR
+ int GetCCladeLabel() const { return cclade_id; }
+
+
int GetMaxExecuted() const { return m_max_executed; }
cCPUMemory& ChildGenome() { return m_child_genome; }
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2007-05-14 18:21:34 UTC (rev 1551)
+++ development/source/main/cPopulation.cc 2007-05-14 18:25:33 UTC (rev 1552)
@@ -280,6 +280,10 @@
// Do lineage tracking for the new organisms.
LineageSetupOrganism(child_array[i], parent_organism.GetLineage(),
parent_organism.GetLineageLabel(), parent_genotype);
+
+ // @MRR Do coalescence clade set up for new organisms.
+ CCladeSetupOrganism(child_array[i], parent_organism.GetCCladeLabel());
+
}
@@ -1294,6 +1298,24 @@
/**
+This function will set up coalescence clade information. If this feature is activated in the configuration,
+ a list of coalescence ids must be read in initially. These are furnished by doing an initial run with the
+ same seed and setup and retrieving information from the final dominant lineage and coalescence points.
+ @MRR May 2007
+ **/
+void cPopulation::CCladeSetupOrganism(cOrganism* organism, int parent_cclade_id)
+{
+ int clade_id = -1; //Default if this isn't being used;
+ if (m_world->GetConfig().TRACK_CCLADES.Get() > 0)
+ {
+ clade_id = (m_world->GetClassificationManager().IsCCladeFounder(organism->GetID())) ?
+ organism->GetID() : parent_cclade_id;
+ }
+ organism->SetCCladeLabel(clade_id);
+}
+
+
+/**
* This function directs which position function should be used. It
* could have also been done with a function pointer, but the dividing
* of an organism takes enough time that this will be a negligible addition,
Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h 2007-05-14 18:21:34 UTC (rev 1551)
+++ development/source/main/cPopulation.h 2007-05-14 18:25:33 UTC (rev 1552)
@@ -131,7 +131,8 @@
void InjectClone(int cell_id, cOrganism& orig_org);
void LineageSetupOrganism(cOrganism* organism, cLineage* lineage, int lin_label, cGenotype* parent_genotype = NULL);
-
+ void CCladeSetupOrganism(cOrganism* organism, int parent_cclade_id);
+
// Must be called to activate *any* organism in the population.
void ActivateOrganism(cAvidaContext& ctx, cOrganism* in_organism, cPopulationCell& target_cell);
Modified: development/source/main/cWorld.cc
===================================================================
--- development/source/main/cWorld.cc 2007-05-14 18:21:34 UTC (rev 1551)
+++ development/source/main/cWorld.cc 2007-05-14 18:25:33 UTC (rev 1552)
@@ -112,6 +112,9 @@
ExitAvida(-1);
}
+ // @MRR CClade Tracking
+ if (m_conf->TRACK_CCLADES.Get() > 0)
+ m_class_mgr->LoadCCladeFounders(m_conf->TRACK_CCLADES_IDS.Get());
const bool revert_fatal = m_conf->REVERT_FATAL.Get() > 0.0;
const bool revert_neg = m_conf->REVERT_DETRIMENTAL.Get() > 0.0;
More information about the Avida-cvs
mailing list