[Avida-SVN] r1477 - in development/source: actions main utils/process_map
ofria at myxo.css.msu.edu
ofria at myxo.css.msu.edu
Tue Apr 17 09:36:39 PDT 2007
Author: ofria
Date: 2007-04-17 12:36:39 -0400 (Tue, 17 Apr 2007)
New Revision: 1477
Modified:
development/source/actions/PrintActions.cc
development/source/main/cPhenotype.h
development/source/utils/process_map/process_map.cc
Log:
Added in a CalcID() mmethod to the cPhenotype class. It will return a number
that indicates which tasks are being performed.
Added a DumpPhenotypeIDGrid() action and corresponding dump_phenotype_grid event.
Added a type option to process_map. If type is set to 0 (default) it will
load in genotype grids. If type is set to 1, it will load phenotype grids.
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2007-04-17 08:16:55 UTC (rev 1476)
+++ development/source/actions/PrintActions.cc 2007-04-17 16:36:39 UTC (rev 1477)
@@ -857,7 +857,7 @@
if (!analyze.GetCurrentBatch().IsAligned()) analyze.CommandAlign(""); //Let analyze take charge of aligning this batch
tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
cAnalyzeGenotype* genotype = NULL;
- while(genotype = batch_it.Next())
+ while((genotype = batch_it.Next()))
{
aligned.Push(genotype->GetAlignedSequence());
}
@@ -1549,6 +1549,37 @@
};
+class cActionDumpPhenotypeIDGrid : public cAction
+{
+private:
+ cString m_filename;
+
+public:
+ cActionDumpPhenotypeIDGrid(cWorld* world, const cString& args) : cAction(world, args), m_filename("")
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_filename = largs.PopWord();
+ }
+ static const cString GetDescription() { return "Arguments: [string fname='']"; }
+ void Process(cAvidaContext& ctx)
+ {
+ cString filename(m_filename);
+ if (filename == "") filename.Set("grid_phenotype_id.%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);
+ int id = (cell.IsOccupied()) ? cell.GetOrganism()->GetPhenotype().CalcID() : -1;
+ fp << id << " ";
+ }
+ fp << endl;
+ }
+ m_world->GetDataFileManager().Remove(filename);
+ }
+};
+
+
class cActionDumpLineageGrid : public cAction
{
private:
@@ -1866,6 +1897,7 @@
action_lib->Register<cActionDumpMemory>("dump_memory");
action_lib->Register<cActionDumpFitnessGrid>("dump_fitness_grid");
action_lib->Register<cActionDumpGenotypeIDGrid>("dump_genotype_grid");
+ action_lib->Register<cActionDumpPhenotypeIDGrid>("dump_phenotype_grid");
action_lib->Register<cActionDumpLineageGrid>("dump_lineage_grid");
action_lib->Register<cActionDumpTaskGrid>("dump_task_grid");
action_lib->Register<cActionDumpDonorGrid>("dump_donor_grid");
Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h 2007-04-17 08:16:55 UTC (rev 1476)
+++ development/source/main/cPhenotype.h 2007-04-17 16:36:39 UTC (rev 1477)
@@ -216,6 +216,13 @@
const double cur_fitness = merit_base * cur_bonus / time_used;
return cur_fitness / last_fitness;
}
+ int CalcID() const {
+ int phen_id = 0;
+ for (int i = 0; i < last_task_count.GetSize(); i++) {
+ if (last_task_count[i] > 0) phen_id += (1 << i);
+ }
+ return phen_id;
+ }
///////////////////// Accessors -- Retrieving ////////////////////
const cMerit & GetMerit() const { assert(initialized == true); return merit; }
Modified: development/source/utils/process_map/process_map.cc
===================================================================
--- development/source/utils/process_map/process_map.cc 2007-04-17 08:16:55 UTC (rev 1476)
+++ development/source/utils/process_map/process_map.cc 2007-04-17 16:36:39 UTC (rev 1477)
@@ -31,6 +31,7 @@
AddSetting("step", 100, "Number of updates to skip between frames.");
AddSetting("stop", 10000, "Last update to frame (inclusive)");
AddSetting("seed", 1, "Random number seed");
+ AddSetting("type", 0, "Type of files to load (0=genotype, 1=phenotype)");
AddSetting("num_demes", 0, "How many demes in the population (0=none)");
AddSetting("num_colors", 65, "Number of colors in map (Use 43 for bright colors)");
AddSetting("threshold1", 10, "Abundance threshold for color shift.");
@@ -95,12 +96,13 @@
// Load in the status of all arguments.
int UD_start, UD_step, UD_stop, seed, num_demes;
- int num_colors, threshold1, threshold2;
+ int num_colors, threshold1, threshold2, type=0;
value_dict.Find("start", UD_start);
value_dict.Find("step", UD_step);
value_dict.Find("stop", UD_stop);
value_dict.Find("seed", seed);
+ value_dict.Find("type", type);
value_dict.Find("num_demes", num_demes);
value_dict.Find("num_colors", num_colors);
value_dict.Find("threshold1", threshold1);
@@ -114,7 +116,8 @@
// Load in the first file to get some basic information about the grids.
cString filename;
- filename.Set("grid_genotype_id.%d.dat", (UD_step + UD_start));
+ if (type == 0) filename.Set("grid_genotype_id.%d.dat", (UD_step + UD_start));
+ else filename.Set("grid_phenotype_id.%d.dat", (UD_step + UD_start));
cInitFile file1(filename);
file1.Load();
file1.Close();
@@ -147,7 +150,7 @@
// Loop through all files, loading them in.
int update = UD_start;
int max_id = -1;
- const int file_step = num_files / 50;
+ const int file_step = (num_files > 50) ? num_files / 50 : 1;
cerr << "LOADING FILES....................................." << endl;
for (int file_id = 0; file_id < num_files; file_id++) {
// Keep a status bar printing on the screen.
@@ -158,7 +161,8 @@
// Generate the filename...
update += UD_step;
- filename.Set("grid_genotype_id.%d.dat", update);
+ if (type == 0) filename.Set("grid_genotype_id.%d.dat", update);
+ else filename.Set("grid_phenotype_id.%d.dat", update);
cInitFile file(filename);
file.Load();
More information about the Avida-cvs
mailing list