[Avida-SVN] r3439 - in development/source: actions targets/avida-viewer
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Fri Oct 2 10:40:41 PDT 2009
Author: brysonda
Date: 2009-10-02 13:40:41 -0400 (Fri, 02 Oct 2009)
New Revision: 3439
Modified:
development/source/actions/PrintActions.cc
development/source/targets/avida-viewer/cViewInfo.cc
Log:
Add new print action, DumpGenotypeColorGrid. This action dumps a genotype color mapping in the same manner as the viewer.
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2009-10-02 15:55:44 UTC (rev 3438)
+++ development/source/actions/PrintActions.cc 2009-10-02 17:40:41 UTC (rev 3439)
@@ -2592,7 +2592,7 @@
void Process(cAvidaContext& ctx)
{
cString filename(m_filename);
- if (filename == "") filename.Set("grid_fitness.%d.dat", m_world->GetStats().GetUpdate());
+ if (filename == "") filename.Set("grid_fitness-%d.dat", m_world->GetStats().GetUpdate());
ofstream& fp = m_world->GetDataFileOFStream(filename);
for (int i = 0; i < m_world->GetPopulation().GetWorldX(); i++) {
@@ -2623,7 +2623,7 @@
void Process(cAvidaContext& ctx)
{
cString filename(m_filename);
- if (filename == "") filename.Set("grid_genotype_id.%d.dat", m_world->GetStats().GetUpdate());
+ if (filename == "") filename.Set("grid_genotype_id-%d.dat", m_world->GetStats().GetUpdate());
ofstream& fp = m_world->GetDataFileOFStream(filename);
for (int j = 0; j < m_world->GetPopulation().GetWorldY(); j++) {
@@ -2638,7 +2638,59 @@
}
};
+class cActionDumpGenotypeColorGrid : public cAction
+{
+private:
+ int m_num_colors;
+ cString m_filename;
+
+public:
+ cActionDumpGenotypeColorGrid(cWorld* world, const cString& args) : cAction(world, args), m_num_colors(12), m_filename("")
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_num_colors = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_filename = largs.PopWord();
+ }
+ static const cString GetDescription() { return "Arguments: [int num_colors=12] [string fname='']"; }
+ void Process(cAvidaContext& ctx)
+ {
+ cGenotype** genotype_chart = new cGenotype*[m_num_colors];
+ cGenotype* temp_gen = m_world->GetClassificationManager().GetBestGenotype();
+ for (int i = 0; i < m_num_colors; i++) {
+ if (temp_gen) {
+ genotype_chart[i] = temp_gen;
+ temp_gen = temp_gen->GetNext();
+ } else {
+ genotype_chart[i] = NULL;
+ }
+ }
+
+ cString filename(m_filename);
+ if (filename == "") filename.Set("grid_genotype_color-%d.dat", m_world->GetStats().GetUpdate());
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
+
+ for (int j = 0; j < m_world->GetPopulation().GetWorldY(); j++) {
+ for (int i = 0; i < m_world->GetPopulation().GetWorldX(); i++) {
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(j * m_world->GetPopulation().GetWorldX() + i);
+ temp_gen = (cell.IsOccupied()) ? cell.GetOrganism()->GetGenotype() : NULL;
+ if (temp_gen) {
+ int color = 0;
+ for (; color < m_num_colors; color++) if (genotype_chart[color] == temp_gen) break;
+ if (color == m_num_colors && temp_gen->GetThreshold()) color++;
+ fp << (color) << " ";
+ } else {
+ fp << "-1 ";
+ }
+ }
+ fp << endl;
+ }
+ m_world->GetDataFileManager().Remove(filename);
+
+ delete genotype_chart;
+ }
+};
+
class cActionDumpPhenotypeIDGrid : public cAction
{
private:
@@ -3200,6 +3252,7 @@
action_lib->Register<cActionDumpMemory>("DumpMemory");
action_lib->Register<cActionDumpFitnessGrid>("DumpFitnessGrid");
action_lib->Register<cActionDumpGenotypeIDGrid>("DumpGenotypeIDGrid");
+ action_lib->Register<cActionDumpGenotypeColorGrid>("DumpGenotypeColorGrid");
action_lib->Register<cActionDumpPhenotypeIDGrid>("DumpPhenotypeIDGrid");
action_lib->Register<cActionDumpLineageGrid>("DumpLineageGrid");
action_lib->Register<cActionDumpTaskGrid>("DumpTaskGrid");
Modified: development/source/targets/avida-viewer/cViewInfo.cc
===================================================================
--- development/source/targets/avida-viewer/cViewInfo.cc 2009-10-02 15:55:44 UTC (rev 3438)
+++ development/source/targets/avida-viewer/cViewInfo.cc 2009-10-02 17:40:41 UTC (rev 3439)
@@ -25,8 +25,8 @@
cViewInfo::cViewInfo(cWorld* world, cView_Base* view)
- : m_world(world)
- , m_view(view)
+: m_world(world)
+, m_view(view)
{
active_cell = NULL;
pause_level = PAUSE_OFF;
@@ -34,9 +34,9 @@
thread_lock = -1;
step_organism_id = -1;
map_mode=0;
-
+
// Handle genotype & species managing...
-
+
for (int i = 0; i < NUM_SYMBOLS; i++) {
genotype_chart[i] = NULL;
species_chart[i] = NULL;
@@ -82,95 +82,95 @@
typedef char (*SymbolMethod)(const cPopulationCell & cell);
SymbolMethod map_method = NULL;
SymbolMethod color_method = NULL;
-
+
switch (map_mode) {
- case MAP_BASIC:
- if (use_color) color_method = &cSymbolUtil::GetBasicSymbol;
- else map_method = &cSymbolUtil::GetBasicSymbol;
- break;
- case MAP_SPECIES:
- if (use_color) color_method = &cSymbolUtil::GetSpeciesSymbol;
- else map_method = &cSymbolUtil::GetSpeciesSymbol;
- break;
- case MAP_COMBO:
- color_method = &cSymbolUtil::GetBasicSymbol;
- map_method = &cSymbolUtil::GetSpeciesSymbol;
- break;
- case MAP_INJECT:
- if (use_color) color_method = &cSymbolUtil::GetModifiedSymbol;
- else map_method = &cSymbolUtil::GetModifiedSymbol;
- break;
- case MAP_RESOURCE:
- map_method = &cSymbolUtil::GetResourceSymbol;
- break;
- case MAP_AGE:
- map_method = &cSymbolUtil::GetAgeSymbol;
- break;
- case MAP_BREED_TRUE:
- if (use_color) color_method = &cSymbolUtil::GetBreedSymbol;
- else map_method = &cSymbolUtil::GetBreedSymbol;
- break;
- case MAP_PARASITE:
- if (use_color) color_method = &cSymbolUtil::GetParasiteSymbol;
- else map_method = &cSymbolUtil::GetParasiteSymbol;
- break;
- case MAP_MUTATIONS:
- if (use_color) color_method = &cSymbolUtil::GetMutSymbol;
- else map_method = &cSymbolUtil::GetMutSymbol;
- break;
- case MAP_THREAD:
- //if (use_color) color_method = &cSymbolUtil::GetThreadSymbol;
- map_method = &cSymbolUtil::GetThreadSymbol;
- break;
- case MAP_LINEAGE:
- if (use_color) color_method = &cSymbolUtil::GetLineageSymbol;
- else map_method = &cSymbolUtil::GetLineageSymbol;
- break;
+ case MAP_BASIC:
+ if (use_color) color_method = &cSymbolUtil::GetBasicSymbol;
+ else map_method = &cSymbolUtil::GetBasicSymbol;
+ break;
+ case MAP_SPECIES:
+ if (use_color) color_method = &cSymbolUtil::GetSpeciesSymbol;
+ else map_method = &cSymbolUtil::GetSpeciesSymbol;
+ break;
+ case MAP_COMBO:
+ color_method = &cSymbolUtil::GetBasicSymbol;
+ map_method = &cSymbolUtil::GetSpeciesSymbol;
+ break;
+ case MAP_INJECT:
+ if (use_color) color_method = &cSymbolUtil::GetModifiedSymbol;
+ else map_method = &cSymbolUtil::GetModifiedSymbol;
+ break;
+ case MAP_RESOURCE:
+ map_method = &cSymbolUtil::GetResourceSymbol;
+ break;
+ case MAP_AGE:
+ map_method = &cSymbolUtil::GetAgeSymbol;
+ break;
+ case MAP_BREED_TRUE:
+ if (use_color) color_method = &cSymbolUtil::GetBreedSymbol;
+ else map_method = &cSymbolUtil::GetBreedSymbol;
+ break;
+ case MAP_PARASITE:
+ if (use_color) color_method = &cSymbolUtil::GetParasiteSymbol;
+ else map_method = &cSymbolUtil::GetParasiteSymbol;
+ break;
+ case MAP_MUTATIONS:
+ if (use_color) color_method = &cSymbolUtil::GetMutSymbol;
+ else map_method = &cSymbolUtil::GetMutSymbol;
+ break;
+ case MAP_THREAD:
+ //if (use_color) color_method = &cSymbolUtil::GetThreadSymbol;
+ map_method = &cSymbolUtil::GetThreadSymbol;
+ break;
+ case MAP_LINEAGE:
+ if (use_color) color_method = &cSymbolUtil::GetLineageSymbol;
+ else map_method = &cSymbolUtil::GetLineageSymbol;
+ break;
}
-
+
const int num_cells = m_world->GetPopulation().GetSize();
map.Resize(num_cells);
color_map.Resize(num_cells);
-
+
for (int i = 0; i < num_cells; i++) {
if (map_method == 0) map[i] = 0;
else map[i] = (*map_method)(m_world->GetPopulation().GetCell(i));
-
+
if (color_method == 0) color_map[i] = 0;
else color_map[i] = (*color_method)(m_world->GetPopulation().GetCell(i));
}
-
+
}
void cViewInfo::UpdateSymbols()
{
// First, clean up the genotype_chart & species_chart.
-
+
int i, pos;
for (i = 0; i < NUM_SYMBOLS; i++) {
if (genotype_chart[i]) {
pos = m_world->GetClassificationManager().FindPos(*(genotype_chart[i]));
if (pos < 0) genotype_chart[i] = NULL;
if (pos >= NUM_SYMBOLS) {
- if (genotype_chart[i]->GetThreshold())
- genotype_chart[i]->SetSymbol('+');
- else genotype_chart[i]->SetSymbol('.');
- genotype_chart[i] = NULL;
+ if (genotype_chart[i]->GetThreshold())
+ genotype_chart[i]->SetSymbol('+');
+ else genotype_chart[i]->SetSymbol('.');
+ genotype_chart[i] = NULL;
}
}
if (species_chart[i]) {
pos = m_world->GetClassificationManager().FindPos(*(species_chart[i]));
if (pos < 0) species_chart[i] = NULL;
if (pos >= NUM_SYMBOLS) {
- species_chart[i]->SetSymbol('+');
- species_chart[i] = NULL;
+ species_chart[i]->SetSymbol('+');
+ species_chart[i] = NULL;
}
}
}
-
+
// Now, fill in any missing spaces...
-
+
cGenotype * temp_gen = m_world->GetClassificationManager().GetBestGenotype();
cSpecies * temp_species = m_world->GetClassificationManager().GetFirstSpecies();
for (i = 0; i < SYMBOL_THRESHOLD; i++) {
@@ -206,7 +206,7 @@
if (active_cell != NULL && active_cell->IsOccupied()) {
return active_cell->GetOrganism()->GetGenotype();
}
-
+
return NULL;
}
More information about the Avida-cvs
mailing list