[Avida-cvs] [Avida2-svn] r387 - in development/source: analyze cpu event main testsuites/unit_testsuites/level_1 tools
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Nov 10 13:13:18 PST 2005
Author: brysonda
Date: 2005-11-10 16:12:24 -0500 (Thu, 10 Nov 2005)
New Revision: 387
Modified:
development/source/analyze/cAnalyze.cc
development/source/analyze/cAnalyze.h
development/source/analyze/cAnalyzeGenotype.cc
development/source/analyze/cAnalyzeGenotype.h
development/source/analyze/cAnalyzeUtil.cc
development/source/analyze/cAnalyzeUtil.h
development/source/cpu/cCPUStack.cc
development/source/cpu/cCPUStack.h
development/source/cpu/cCodeLabel.cc
development/source/cpu/cCodeLabel.h
development/source/cpu/cHardware4Stack.cc
development/source/cpu/cHardware4Stack.h
development/source/cpu/cHardware4Stack_Thread.cc
development/source/cpu/cHardware4Stack_Thread.h
development/source/cpu/cHardwareBase.h
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/cpu/cHardwareCPU_Thread.cc
development/source/cpu/cHardwareCPU_Thread.h
development/source/cpu/cHardwareSMT.cc
development/source/cpu/cHardwareSMT.h
development/source/cpu/cHardwareSMT_Thread.cc
development/source/cpu/cHardwareSMT_Thread.h
development/source/cpu/cHardwareStatusPrinter.h
development/source/cpu/cTestCPU.cc
development/source/cpu/cTestCPU.h
development/source/cpu/cTestUtil.cc
development/source/event/cEventList.cc
development/source/event/cEventList.h
development/source/event/cEventListIterator.cc
development/source/event/cEventListIterator.h
development/source/event/cEventManager.cc
development/source/main/cAvidaDriver_Analyze.cc
development/source/main/cAvidaDriver_Analyze.h
development/source/main/cAvidaDriver_Population.h
development/source/main/cFitnessMatrix.cc
development/source/main/cFitnessMatrix.h
development/source/main/cGenebank.cc
development/source/main/cGenebank.h
development/source/main/cGenotype.cc
development/source/main/cGenotype.h
development/source/main/cInjectGenebank.cc
development/source/main/cInjectGenebank.h
development/source/main/cInjectGenotype.cc
development/source/main/cInjectGenotype.h
development/source/main/cInstUtil.cc
development/source/main/cInstUtil.h
development/source/main/cLandscape.cc
development/source/main/cLandscape.h
development/source/main/cLineageControl.cc
development/source/main/cMxCodeArray.cc
development/source/main/cMxCodeArray.h
development/source/main/cOrganism.cc
development/source/main/cOrganism.h
development/source/main/cPhenotype.cc
development/source/main/cPhenotype.h
development/source/main/cPopulation.cc
development/source/main/cPopulation.h
development/source/main/cPopulationCell.cc
development/source/main/cPopulationCell.h
development/source/main/cSpecies.h
development/source/main/cStats.cc
development/source/main/cStats.h
development/source/testsuites/unit_testsuites/level_1/code_label.t.cc
development/source/tools/cDataEntry.cc
development/source/tools/cDataEntry.h
development/source/tools/cDataFile.h
development/source/tools/cDataManager_Base.cc
development/source/tools/cInitFile.cc
development/source/tools/cMerit.cc
development/source/tools/cMerit.h
development/source/tools/cString.cc
development/source/tools/cString.h
development/source/tools/tArgDataEntry.h
development/source/tools/tBuffer.h
development/source/tools/tDataEntry.h
development/source/tools/tDataEntryBase.h
development/source/tools/tDataEntryCommand.h
development/source/tools/tDataManager.h
Log:
Migrate nearly all remaining output files to use cDataFileManager.
Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/analyze/cAnalyze.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -466,25 +466,25 @@
if(which < 0) { assert(0); }
-tArray<double> temp(resources[which].second.size());
-for(unsigned int i=0; i<resources[which].second.size(); i++) {
- temp[i] = resources[which].second[i];
+ tArray<double> temp(resources[which].second.size());
+ for(unsigned int i=0; i<resources[which].second.size(); i++) {
+ temp[i] = resources[which].second[i];
+ }
+ m_world->GetTestCPU().SetupResourceArray(temp);
+
+ return;
}
-m_world->GetTestCPU().SetupResourceArray(temp);
-return;
-}
-
double cAnalyze::AnalyzeEntropy(cAnalyzeGenotype * genotype, double mu)
{
double entropy = 0.0;
-
+
// If the fitness is 0, the entropy is the length of genotype ...
genotype->Recalculate();
if (genotype->GetFitness() == 0) {
return genotype->GetLength();
}
-
+
// Calculate the stats for the genotype we're working with ...
const int num_insts = inst_set.GetSize();
const int num_lines = genotype->GetLength();
@@ -505,9 +505,9 @@
test_genotype.Recalculate();
// Ajust fitness ...
if (test_genotype.GetFitness() <= base_fitness) {
- test_fitness[mod_inst] = test_genotype.GetFitness();
+ test_fitness[mod_inst] = test_genotype.GetFitness();
} else {
- test_fitness[mod_inst] = base_fitness;
+ test_fitness[mod_inst] = base_fitness;
}
}
@@ -518,27 +518,27 @@
double maxFitness = 0.0;
for(int i=0; i<num_insts; i++) {
if(test_fitness[i] > maxFitness) {
- maxFitness = test_fitness[i];
+ maxFitness = test_fitness[i];
}
}
-
+
for(int i=0; i<num_insts; i++) {
test_fitness[i] /= maxFitness;
}
-
+
while(1) {
double sum = 0.0;
for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
- prob[mod_inst] = (mu * w_bar) /
- ((double)num_insts *
- (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
- sum = sum + prob[mod_inst];
+ prob[mod_inst] = (mu * w_bar) /
+ ((double)num_insts *
+ (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
+ sum = sum + prob[mod_inst];
}
if ((sum-1.0)*(sum-1.0) <= 0.0001)
- break;
+ break;
else
- w_bar = w_bar - 0.000001;
+ w_bar = w_bar - 0.000001;
}
// Calculate entropy ...
@@ -555,10 +555,10 @@
}
double cAnalyze::AnalyzeEntropyGivenParent(cAnalyzeGenotype * genotype,
- cAnalyzeGenotype * parent, double mut_rate)
+ cAnalyzeGenotype * parent, double mut_rate)
{
double entropy = 0.0;
-
+
// Calculate the stats for the genotype we're working with ...
genotype->Recalculate();
const int num_insts = inst_set.GetSize();
@@ -566,14 +566,14 @@
const cGenome & base_genome = genotype->GetGenome();
const cGenome & parent_genome = parent->GetGenome();
cGenome mod_genome(base_genome);
-
+
// Loop through all the lines of code, testing all mutations ...
tArray<double> test_fitness(num_insts);
tArray<double> prob(num_insts);
for (int line_no = 0; line_no < num_lines; line_no ++) {
int cur_inst = base_genome[line_no].GetOp();
int parent_inst = parent_genome[line_no].GetOp();
-
+
// Test fitness of each mutant.
for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
mod_genome[line_no].SetOp(mod_inst);
@@ -581,8 +581,8 @@
test_genotype.Recalculate();
test_fitness[mod_inst] = test_genotype.GetFitness();
}
-
-
+
+
// Calculate probabilities at mut-sel balance
double w_bar = 1;
@@ -591,20 +591,20 @@
for(int i=0; i<num_insts; i++) {
if ( i == parent_inst) { continue; }
if (test_fitness[i] > maxFitness) {
- maxFitness = test_fitness[i];
+ maxFitness = test_fitness[i];
}
}
if(maxFitness > 0) {
for(int i = 0; i < num_insts; i ++) {
- if (i == parent_inst) { continue; }
- test_fitness[i] /= maxFitness;
+ if (i == parent_inst) { continue; }
+ test_fitness[i] /= maxFitness;
}
} else {
// every other inst is equally likely to be mutated to
for (int i = 0; i < num_insts; i ++) {
- if (i == parent_inst) { continue; }
- test_fitness[i] = 1;
+ if (i == parent_inst) { continue; }
+ test_fitness[i] = 1;
}
}
@@ -612,17 +612,17 @@
while(1) {
double sum = 0.0;
for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
- if (mod_inst == parent_inst) { continue; }
- prob[mod_inst] = (mut_rate * w_bar) /
- (double_num_insts-2) /
- (w_bar + test_fitness[mod_inst] * mut_rate * (double_num_insts-1) / (double_num_insts - 2)
- - test_fitness[mod_inst]);
- sum = sum + prob[mod_inst];
+ if (mod_inst == parent_inst) { continue; }
+ prob[mod_inst] = (mut_rate * w_bar) /
+ (double_num_insts-2) /
+ (w_bar + test_fitness[mod_inst] * mut_rate * (double_num_insts-1) / (double_num_insts - 2)
+ - test_fitness[mod_inst]);
+ sum = sum + prob[mod_inst];
}
if ((sum-1.0)*(sum-1.0) <= 0.0001)
- break;
+ break;
else
- w_bar = w_bar - 0.000001;
+ w_bar = w_bar - 0.000001;
}
// Calculate entropy ...
@@ -634,7 +634,7 @@
this_entropy += prob[i] * log(static_cast<double>(1.0/prob[i])) / log (static_cast<double>(num_insts));
}
entropy += this_entropy;
-
+
// Reset the mod_genome back to the base_genome.
mod_genome[line_no].SetOp(cur_inst);
}
@@ -642,22 +642,22 @@
}
double cAnalyze::IncreasedInfo(cAnalyzeGenotype * genotype1,
- cAnalyzeGenotype * genotype2,
- double mu)
+ cAnalyzeGenotype * genotype2,
+ double mu)
{
double increased_info = 0.0;
-
+
// Calculate the stats for the genotypes we're working with ...
if ( genotype1->GetLength() != genotype2->GetLength() ) {
cerr << "Error: Two genotypes don't have same length.(cAnalyze::IncreasedInfo)" << endl;
exit(1);
}
-
+
genotype1->Recalculate();
if (genotype1->GetFitness() == 0) {
return 0.0;
}
-
+
const int num_insts = inst_set.GetSize();
const int num_lines = genotype1->GetLength();
const cGenome & genotype1_base_genome = genotype1->GetGenome();
@@ -678,9 +678,9 @@
test_genotype.Recalculate();
// Ajust fitness ...
if (test_genotype.GetFitness() <= genotype1_base_fitness) {
- test_fitness[mod_inst] = test_genotype.GetFitness();
+ test_fitness[mod_inst] = test_genotype.GetFitness();
} else {
- test_fitness[mod_inst] = genotype1_base_fitness;
+ test_fitness[mod_inst] = genotype1_base_fitness;
}
}
@@ -691,7 +691,7 @@
double maxFitness = 0.0;
for(int i=0; i<num_insts; i++) {
if(test_fitness[i] > maxFitness) {
- maxFitness = test_fitness[i];
+ maxFitness = test_fitness[i];
}
}
@@ -702,15 +702,15 @@
while(1) {
double sum = 0.0;
for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
- prob[mod_inst] = (mu * w_bar) /
- ((double)num_insts *
- (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
- sum = sum + prob[mod_inst];
+ prob[mod_inst] = (mu * w_bar) /
+ ((double)num_insts *
+ (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
+ sum = sum + prob[mod_inst];
}
if ((sum-1.0)*(sum-1.0) <= 0.0001)
- break;
+ break;
else
- w_bar = w_bar - 0.000001;
+ w_bar = w_bar - 0.000001;
}
// Calculate entropy ...
@@ -723,7 +723,7 @@
// Reset the mod_genome back to the original sequence.
genotype1_mod_genome[line_no].SetOp(cur_inst);
}
-
+
genotype2->Recalculate();
if (genotype2->GetFitness() == 0) {
for (int line_no = 0; line_no < num_lines; ++ line_no) {
@@ -731,11 +731,11 @@
}
return increased_info;
}
-
+
const cGenome & genotype2_base_genome = genotype2->GetGenome();
cGenome genotype2_mod_genome(genotype2_base_genome);
double genotype2_base_fitness = genotype2->GetFitness();
-
+
// Loop through all the lines of code, calculate increased information
for (int line_no = 0; line_no < num_lines; line_no ++) {
int cur_inst = genotype2_base_genome[line_no].GetOp();
@@ -747,9 +747,9 @@
test_genotype.Recalculate();
// Ajust fitness ...
if (test_genotype.GetFitness() <= genotype2_base_fitness) {
- test_fitness[mod_inst] = test_genotype.GetFitness();
+ test_fitness[mod_inst] = test_genotype.GetFitness();
} else {
- test_fitness[mod_inst] = genotype2_base_fitness;
+ test_fitness[mod_inst] = genotype2_base_fitness;
}
}
@@ -760,7 +760,7 @@
double maxFitness = 0.0;
for(int i=0; i<num_insts; i++) {
if(test_fitness[i] > maxFitness) {
- maxFitness = test_fitness[i];
+ maxFitness = test_fitness[i];
}
}
@@ -771,15 +771,15 @@
while(1) {
double sum = 0.0;
for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
- prob[mod_inst] = (mu * w_bar) /
- ((double)num_insts *
- (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
- sum = sum + prob[mod_inst];
+ prob[mod_inst] = (mu * w_bar) /
+ ((double)num_insts *
+ (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
+ sum = sum + prob[mod_inst];
}
if ((sum-1.0)*(sum-1.0) <= 0.0001)
- break;
+ break;
else
- w_bar = w_bar - 0.000001;
+ w_bar = w_bar - 0.000001;
}
// Calculate entropy ...
@@ -796,8 +796,8 @@
// Reset the mod_genome back to the original sequence.
genotype2_mod_genome[line_no].SetOp(cur_inst);
}
-
-
+
+
return increased_info;
}
@@ -1501,11 +1501,9 @@
}
// Build the hardware status printer for tracing.
- ofstream trace_fp;
- trace_fp.open(filename);
- assert (trace_fp.good() == true); // Unable to open trace file.
+ ofstream& trace_fp = m_world->GetDataFileOFStream(filename);
cHardwareStatusPrinter trace_printer(trace_fp);
-
+
// Build the test info for printing.
cCPUTestInfo test_info;
test_info.TestThreads();
@@ -1514,7 +1512,7 @@
m_world->GetTestCPU().TestGenome(test_info, genotype->GetGenome());
if (verbose) cout << " Tracing: " << filename << endl;
- trace_fp.close();
+ m_world->GetDataFileManager().Remove(filename);
}
if(useResources) {
@@ -1535,7 +1533,7 @@
cString filename("tasks.dat");
if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// Loop through all of the genotypes in this batch...
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
@@ -1572,7 +1570,7 @@
CommandDetail_Header(cout, file_type, output_it);
CommandDetail_Body(cout, file_type, output_it);
} else {
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
CommandDetail_Header(fp, file_type, output_it);
CommandDetail_Body(fp, file_type, output_it);
}
@@ -1617,7 +1615,7 @@
CommandDetail_Header(cout, file_type, output_it, time_step);
CommandDetail_Body(cout, file_type, output_it, time_step, max_time);
} else {
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
CommandDetail_Header(fp, file_type, output_it, time_step);
CommandDetail_Body(fp, file_type, output_it, time_step, max_time);
}
@@ -1627,7 +1625,7 @@
}
-void cAnalyze::CommandDetail_Header(ostream & fp, int format_type,
+void cAnalyze::CommandDetail_Header(ostream& fp, int format_type,
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
int time_step)
{
@@ -1676,7 +1674,7 @@
}
-void cAnalyze::CommandDetail_Body(ostream & fp, int format_type,
+void cAnalyze::CommandDetail_Body(ostream& fp, int format_type,
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
int time_step, int max_time)
{
@@ -1739,9 +1737,9 @@
fp << "</table>" << endl
<< "</center>" << endl;
}
-}
+ }
-void cAnalyze::CommandDetailAverage_Body(ostream & fp, int num_outputs,
+void cAnalyze::CommandDetailAverage_Body(ostream& fp, int num_outputs,
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
{
// Loop through all of the genotypes in this batch...
@@ -1794,7 +1792,7 @@
// check if file is already in use.
bool file_active = m_world->GetDataFileManager().IsOpen(filename);
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// if it's a new file print out the header
if (file_active == false) {
@@ -1849,7 +1847,7 @@
while (file_extension.Find('.') != -1) file_extension.Pop('.');
if (file_extension == "html") file_type = FILE_TYPE_HTML;
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// Write out the header on the file
if (file_type == FILE_TYPE_TEXT) {
@@ -1997,8 +1995,7 @@
}
// Setup the file...
- ofstream fp;
- fp.open(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// Determine the file type...
int file_type = FILE_TYPE_TEXT;
@@ -2056,8 +2053,7 @@
if (file_type == FILE_TYPE_HTML) {
fp << "<tr><th><a href=lineage." << batch_name << ".html>"
<< batch_name << "</a> ";
- }
- else {
+ } else {
fp << batch_name << " ";
}
@@ -2067,14 +2063,13 @@
fp << "<td align=center><a href=\""
<< data_entry->GetName() << "." << batch_name << ".png\">"
<< *data_entry << "</a> ";
- }
- else { // if (file_type == FILE_TYPE_TEXT) {
+ } else { // if (file_type == FILE_TYPE_TEXT) {
fp << *data_entry << " ";
}
- }
+ }
if (file_type == FILE_TYPE_HTML) fp << "</tr>";
fp << endl;
- }
+ }
// If in HTML mode, we need to end the file...
if (file_type == FILE_TYPE_HTML) {
@@ -2108,7 +2103,7 @@
CommandHistogram_Header(cout, file_type, output_it);
CommandHistogram_Body(cout, file_type, output_it);
} else {
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
CommandHistogram_Header(fp, file_type, output_it);
CommandHistogram_Body(fp, file_type, output_it);
}
@@ -2117,8 +2112,8 @@
while (output_list.GetSize() != 0) delete output_list.Pop();
}
-void cAnalyze::CommandHistogram_Header(ostream & fp, int format_type,
- tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
+void cAnalyze::CommandHistogram_Header(ostream& fp, int format_type,
+ tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
{
// Write out the header on the file
if (format_type == FILE_TYPE_TEXT) {
@@ -2140,47 +2135,47 @@
fp << endl;
} else { // if (format_type == FILE_TYPE_HTML) {
fp << "<html>" << endl
- << "<body bgcolor=\"#FFFFFF\"" << endl
- << " text=\"#000000\"" << endl
- << " link=\"#0000AA\"" << endl
- << " alink=\"#0000FF\"" << endl
- << " vlink=\"#000044\">" << endl
- << endl
- << "<h1 align=center>Histograms for " << batch[cur_batch].Name()
- << "</h1>" << endl
- << endl
- << "<center>" << endl
- << "<table border=1 cellpadding=2><tr>" << endl;
+ << "<body bgcolor=\"#FFFFFF\"" << endl
+ << " text=\"#000000\"" << endl
+ << " link=\"#0000AA\"" << endl
+ << " alink=\"#0000FF\"" << endl
+ << " vlink=\"#000044\">" << endl
+ << endl
+ << "<h1 align=center>Histograms for " << batch[cur_batch].Name()
+ << "</h1>" << endl
+ << endl
+ << "<center>" << endl
+ << "<table border=1 cellpadding=2><tr>" << endl;
while (output_it.Next() != NULL) {
const cString & entry_desc = output_it.Get()->GetDesc();
const cString & entry_name = output_it.Get()->GetName();
fp << "<tr><th bgcolor=\"#AAAAFF\"><a href=\"#"
- << entry_name << "\">"
- << entry_desc << "</a></tr>";
+ << entry_name << "\">"
+ << entry_desc << "</a></tr>";
}
fp << "</tr></table>" << endl;
}
-}
+ }
-void cAnalyze::CommandHistogram_Body(ostream & fp, int format_type,
- tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
+void cAnalyze::CommandHistogram_Body(ostream& fp, int format_type,
+ tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
{
output_it.Reset();
tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
-
+
while ((data_command = output_it.Next()) != NULL) {
if (format_type == FILE_TYPE_TEXT) {
fp << "# --- " << data_command->GetDesc() << " ---" << endl;
} else {
fp << "<table cellpadding=3>" << endl
- << "<tr><th colspan=3><a name=\"" << data_command->GetName() << "\">"
- << data_command->GetDesc() << "</th></tr>" << endl;
+ << "<tr><th colspan=3><a name=\"" << data_command->GetName() << "\">"
+ << data_command->GetDesc() << "</th></tr>" << endl;
}
-
+
tDictionary<int> count_dict;
-
+
// Loop through all genotypes in this batch to collect the info we need.
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
cAnalyzeGenotype * cur_genotype;
@@ -2192,11 +2187,11 @@
count += cur_genotype->GetNumCPUs();
count_dict.SetValue(cur_name, count);
}
-
+
tList<cString> name_list;
tList<int> count_list;
count_dict.AsLists(name_list, count_list);
-
+
// Figure out the maximum count and the maximum widths...
int max_count = 0;
int max_name_width = 0;
@@ -2212,10 +2207,10 @@
if (name_width > max_name_width) max_name_width = name_width;
if (count_width > max_count_width) max_count_width = count_width;
}
-
+
// Do some final calculations now that we know the maximums...
const int max_stars = 75 - max_name_width - max_count_width;
-
+
// Now print everything out...
count_it.Reset();
name_it.Reset();
@@ -2224,21 +2219,21 @@
const int cur_count = *(count_it.Get());
if (cur_count == 0) continue;
int num_stars = (cur_count * max_stars) / max_count;
-
+
if (format_type == FILE_TYPE_TEXT) {
- fp << setw(max_name_width) << cur_name << " "
- << setw(max_count_width) << cur_count << " ";
- for (int i = 0; i < num_stars; i++) { fp << '#'; }
- fp << endl;
+ fp << setw(max_name_width) << cur_name << " "
+ << setw(max_count_width) << cur_count << " ";
+ for (int i = 0; i < num_stars; i++) { fp << '#'; }
+ fp << endl;
} else { // FILE_TYPE_HTML
- fp << "<tr><td>" << cur_name
- << "<td>" << cur_count
- << "<td>";
- for (int i = 0; i < num_stars; i++) { fp << '#'; }
- fp << "</tr>" << endl;
+ fp << "<tr><td>" << cur_name
+ << "<td>" << cur_count
+ << "<td>";
+ for (int i = 0; i < num_stars; i++) { fp << '#'; }
+ fp << "</tr>" << endl;
}
}
-
+
if (format_type == FILE_TYPE_TEXT) {
// Skip a line between histograms...
fp << endl;
@@ -2300,7 +2295,7 @@
// Print out the results...
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
fp << "# 1: Number of organisms of this phenotype" << endl
<< "# 2: Number of genotypes of this phenotye" << endl
@@ -2339,7 +2334,7 @@
phenotype_counts[max_position] = 0;
}
- fp.close();
+ m_world->GetDataFileManager().Remove(filename);
}
@@ -2439,33 +2434,33 @@
void cAnalyze::PhyloCommunityComplexity(cString cur_string)
{
-
+
/////////////////////////////////////////////////////////////////////////
// Calculate the mutual information between all genotypes and environment
/////////////////////////////////////////////////////////////////////////
-
+
cout << "Analyze biocomplexity of current population about environment ...\n";
-
+
// Get the number of genotypes that are gonna be analyzed.
int max_genotypes = cur_string.PopWord().AsInt();
-
+
// Get update
int update = cur_string.PopWord().AsInt();
-
+
// Get the directory
cString dir = cur_string.PopWord();
cString defaultDir = "community_cpx/";
cString directory = PopDirectory(dir, defaultDir);
-
+
// Get the file name that saves the result
cString filename = cur_string.PopWord();
if (filename.IsEmpty()) {
filename = "community.complexity.dat";
}
-
+
filename.Set("%s%s", directory(), filename.GetData());
- ofstream cpx_fp(filename());
-
+ ofstream& cpx_fp = m_world->GetDataFileOFStream(filename);
+
cpx_fp << "# Legend:" << endl;
cpx_fp << "# 1: Genotype ID" << endl;
cpx_fp << "# 2: Entropy given Known Genotypes" << endl;
@@ -2473,10 +2468,10 @@
cpx_fp << "# 4: New Information about Environment" << endl;
cpx_fp << "# 5: Total Complexity" << endl;
cpx_fp << endl;
-
+
/////////////////////////////////////////////////////////////////////////////////
// Loop through all of the genotypes in all batches and build id vs. genotype map
-
+
map<int, cAnalyzeGenotype *> genotype_database;
for (int i = 0; i < MAX_BATCHES; ++ i) {
tListIterator<cAnalyzeGenotype> batch_it(batch[i].List());
@@ -2485,10 +2480,10 @@
genotype_database.insert(make_pair(genotype->GetID(), genotype));
}
}
-
+
////////////////////////////////////////////////
// Check if all the genotypes having same length
-
+
int length_genome;
if (genotype_database.size() > 0) {
length_genome = genotype_database.begin()->second->GetLength();
@@ -2500,32 +2495,31 @@
exit(1);
}
}
-
+
///////////////////////
// Backup test CPU data
bool backupUsage = m_world->GetTestCPU().UseResources();
tArray<double> backupResources(m_world->GetTestCPU().GetResources());
m_world->GetTestCPU().UseResources() = true;
FillResources(update);
-
+
///////////////////////////////////////////////////////////////////////
// Choose the first n most abundant genotypes and put them in community
-
+
vector<cAnalyzeGenotype *> community;
cAnalyzeGenotype * genotype = NULL;
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-
+
while (((genotype = batch_it.Next()) != NULL) && (community.size() < max_genotypes)) {
community.push_back(genotype);
}
-
+
///////////////////////////
// Measure hamming distance
-
+
int size_community = community.size();
if (size_community == 0) {
cerr << "There is no genotype in this community." << endl;
- cpx_fp.close();
exit(1);
}
typedef pair<int,int> gen_pair;
@@ -2534,45 +2528,45 @@
for (int i = 0; i< size_community; ++ i) {
for (int j = i+1; j < size_community; ++ j) {
int dist = cGenomeUtil::FindHammingDistance(community[i]->GetGenome(),
- community[j]->GetGenome());
+ community[j]->GetGenome());
int id1 = community[i]->GetID();
int id2 = community[j]->GetID();
-
+
hamming_dist.insert(make_pair(gen_pair(id1, id2), dist));
hamming_dist.insert(make_pair(gen_pair(id2, id1), dist));
}
}
-
+
//////////////////////////////////
// Get Most Recent Common Ancestor
-
+
map<gen_pair, cAnalyzeGenotype *> mrca;
map<gen_pair, int> raw_dist;
for (int i = 0; i< size_community; ++ i) {
for (int j = i+1; j < size_community; ++ j) {
-
+
cAnalyzeGenotype * lineage1_genotype = community[i];
cAnalyzeGenotype * lineage2_genotype = community[j];
int total_dist = 0;
-
- while (lineage1_genotype->GetID() != lineage2_genotype->GetID()) {
- if (lineage1_genotype->GetID() > lineage2_genotype->GetID()) {
- int parent_id = lineage1_genotype->GetParentID();
- cAnalyzeGenotype * parent = genotype_database.find(parent_id)->second;
-
- total_dist += cGenomeUtil::FindHammingDistance(lineage1_genotype->GetGenome(),
- parent->GetGenome());
- lineage1_genotype = parent;
- } else {
- int parent_id = lineage2_genotype->GetParentID();
- cAnalyzeGenotype * parent = genotype_database.find(parent_id)->second;
- total_dist += cGenomeUtil::FindHammingDistance(lineage2_genotype->GetGenome(),
- parent->GetGenome());
- lineage2_genotype = parent;
- }
+ while (lineage1_genotype->GetID() != lineage2_genotype->GetID()) {
+ if (lineage1_genotype->GetID() > lineage2_genotype->GetID()) {
+ int parent_id = lineage1_genotype->GetParentID();
+ cAnalyzeGenotype * parent = genotype_database.find(parent_id)->second;
+
+ total_dist += cGenomeUtil::FindHammingDistance(lineage1_genotype->GetGenome(),
+ parent->GetGenome());
+ lineage1_genotype = parent;
+ } else {
+ int parent_id = lineage2_genotype->GetParentID();
+ cAnalyzeGenotype * parent = genotype_database.find(parent_id)->second;
+ total_dist += cGenomeUtil::FindHammingDistance(lineage2_genotype->GetGenome(),
+ parent->GetGenome());
+
+ lineage2_genotype = parent;
+ }
}
-
+
int id1 = community[i]->GetID();
int id2 = community[j]->GetID();
mrca.insert(make_pair(gen_pair(id1, id2), lineage1_genotype));
@@ -2581,174 +2575,174 @@
raw_dist.insert(make_pair(gen_pair(id2, id1), total_dist));
}
}
-
+
/*
- ////////////////////////////////////////////////////////////////////////////////////////////
- // Sort the genotype that is next genotype is the most closest one to all previous genotypes
-
- vector<cAnalyzeGenotype *> sorted_community;
- vector<cAnalyzeGenotype *> left_genotypes = community;
-
- // Put the first genotype in left to sorted.
- sorted_community.push_back(*left_genotypes.begin());
- left_genotypes.erase(left_genotypes.begin());
-
- while (left_genotypes.size() > 0) {
- int min_total_hamming = size_community * length_genome;
- int index_next;
-
- for (int next = 0; next < left_genotypes.size(); ++ next) {
- int total_hamming = 0;
- int id1 = left_genotypes[next]->GetID();
-
- for (int given = 0; given < sorted_community.size(); ++ given) {
- int id2 = sorted_community[given]->GetID();
- total_hamming += hamming_dist.find(gen_pair(id1, id2))->second;
- }
-
- if (total_hamming < min_total_hamming) {
- min_total_hamming = total_hamming;
- index_next = next;
- }
- }
-
- sorted_community.push_back(left_genotypes[index_next]);
- left_genotypes.erase(left_genotypes.begin() + index_next);
- }
-
- */
-
+ ////////////////////////////////////////////////////////////////////////////////////////////
+ // Sort the genotype that is next genotype is the most closest one to all previous genotypes
+
+ vector<cAnalyzeGenotype *> sorted_community;
+ vector<cAnalyzeGenotype *> left_genotypes = community;
+
+ // Put the first genotype in left to sorted.
+ sorted_community.push_back(*left_genotypes.begin());
+ left_genotypes.erase(left_genotypes.begin());
+
+ while (left_genotypes.size() > 0) {
+ int min_total_hamming = size_community * length_genome;
+ int index_next;
+
+ for (int next = 0; next < left_genotypes.size(); ++ next) {
+ int total_hamming = 0;
+ int id1 = left_genotypes[next]->GetID();
+
+ for (int given = 0; given < sorted_community.size(); ++ given) {
+ int id2 = sorted_community[given]->GetID();
+ total_hamming += hamming_dist.find(gen_pair(id1, id2))->second;
+ }
+
+ if (total_hamming < min_total_hamming) {
+ min_total_hamming = total_hamming;
+ index_next = next;
+ }
+ }
+
+ sorted_community.push_back(left_genotypes[index_next]);
+ left_genotypes.erase(left_genotypes.begin() + index_next);
+ }
+
+ */
+
vector<cAnalyzeGenotype *> sorted_community = community;
/////////////////////////////////////////////
// Loop through genotypes in sorted community
-
+
double complexity = 0.0;
vector<cAnalyzeGenotype *> given_genotypes;
int num_insts = inst_set.GetSize();
-
+
for (int i = 0; i < size_community; ++ i) {
genotype = sorted_community[i];
-
+
// Skip the dead organisms
genotype->Recalculate();
if (genotype->GetFitness() == 0) {
continue;
}
-
+
vector<double> one_line_prob(num_insts, 0.0);
vector< vector<double> > prob(length_genome, one_line_prob);
-
+
cout << endl << genotype->GetID() << endl;
-
+
/*if (given_genotypes.size() >= 2) {
-
+
///////////////////////////////////////////////////////////////////
// Look for two given genotypes that has minimun depth dist with it
-
+
cAnalyzeGenotype * min_depth_gen = given_genotypes[0];
- cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
- given_genotypes[0]->GetID()))->second;
- int min_depth_dist = genotype->GetDepth() + given_genotypes[0]->GetDepth() - 2 * tmrca->GetDepth();
+ cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
+ given_genotypes[0]->GetID()))->second;
+ int min_depth_dist = genotype->GetDepth() + given_genotypes[0]->GetDepth() - 2 * tmrca->GetDepth();
+
+ cAnalyzeGenotype * second_min_gen = given_genotypes[1];
+ tmrca = mrca.find(gen_pair(genotype->GetID(), given_genotypes[1]->GetID()))->second;
+ int second_min_depth = genotype->GetDepth() + given_genotypes[1]->GetDepth() - 2 * tmrca->GetDepth();
+
+ for (int i = 2; i < given_genotypes.size(); ++ i) {
+ cAnalyzeGenotype * given_genotype = given_genotypes[i];
+ cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
+ given_genotype->GetID()))->second;
+ int dist = genotype->GetDepth() + given_genotype->GetDepth() - 2 * tmrca->GetDepth();
- cAnalyzeGenotype * second_min_gen = given_genotypes[1];
- tmrca = mrca.find(gen_pair(genotype->GetID(), given_genotypes[1]->GetID()))->second;
- int second_min_depth = genotype->GetDepth() + given_genotypes[1]->GetDepth() - 2 * tmrca->GetDepth();
-
- for (int i = 2; i < given_genotypes.size(); ++ i) {
- cAnalyzeGenotype * given_genotype = given_genotypes[i];
- cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
- given_genotype->GetID()))->second;
- int dist = genotype->GetDepth() + given_genotype->GetDepth() - 2 * tmrca->GetDepth();
-
- if (dist < min_depth_dist) {
- second_min_depth = min_depth_dist;
- second_min_gen = min_depth_gen;
- min_depth_dist = dist;
- min_depth_gen = given_genotype;
- } else if (dist >= min_depth_dist && dist < second_min_depth) {
- second_min_depth = dist;
- second_min_gen = given_genotype;
- }
+ if (dist < min_depth_dist) {
+ second_min_depth = min_depth_dist;
+ second_min_gen = min_depth_gen;
+ min_depth_dist = dist;
+ min_depth_gen = given_genotype;
+ } else if (dist >= min_depth_dist && dist < second_min_depth) {
+ second_min_depth = dist;
+ second_min_gen = given_genotype;
}
-
- const cGenome & given_genome1 = min_depth_gen->GetGenome();
- const cGenome & given_genome2 = second_min_gen->GetGenome();
- for (int line = 0; line < length_genome; ++ line) {
- int given_inst = given_genome1[line].GetOp();
- prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
- given_inst = given_genome2[line].GetOp();
- prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
- }
-
- cpx_fp << genotype->GetID() << " " << min_depth_dist << " " << second_min_depth
+ }
+
+ const cGenome & given_genome1 = min_depth_gen->GetGenome();
+ const cGenome & given_genome2 = second_min_gen->GetGenome();
+ for (int line = 0; line < length_genome; ++ line) {
+ int given_inst = given_genome1[line].GetOp();
+ prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
+ given_inst = given_genome2[line].GetOp();
+ prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
+ }
+
+ cpx_fp << genotype->GetID() << " " << min_depth_dist << " " << second_min_depth
<< " " << raw_dist.find(gen_pair(genotype->GetID(), min_depth_gen->GetID()))->second
<< " " << raw_dist.find(gen_pair(genotype->GetID(), second_min_gen->GetID()))->second
<< " ";
-
-
+
+
} else if (given_genotypes.size() == 1) {
//////////////////////////////////////////////////////
// Calculate the probability of each inst at each line
cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
- given_genotypes[0]->GetID()))->second;
+ given_genotypes[0]->GetID()))->second;
int dist = genotype->GetDepth() + given_genotypes[0]->GetDepth() - 2 * tmrca->GetDepth();
const cGenome & given_genome = given_genotypes[0]->GetGenome();
-
+
for (int line = 0; line < length_genome; ++ line) {
- int given_inst = given_genome[line].GetOp();
- prob[line][given_inst] += pow(1 - 1.0/length_genome, dist);
+ int given_inst = given_genome[line].GetOp();
+ prob[line][given_inst] += pow(1 - 1.0/length_genome, dist);
}
cpx_fp << genotype->GetID() << " " << dist << " "
- << raw_dist.find(gen_pair(genotype->GetID(), given_genotypes[0]->GetID()))->second << " ";
+ << raw_dist.find(gen_pair(genotype->GetID(), given_genotypes[0]->GetID()))->second << " ";
} else {
cpx_fp << genotype->GetID() << " ";
- }*/
-
+ }*/
+
if (given_genotypes.size() >= 1) {
//////////////////////////////////////////////////
// Look for a genotype that is closest to this one
cAnalyzeGenotype * min_depth_gen = given_genotypes[0];
cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
- given_genotypes[0]->GetID()))->second;
+ given_genotypes[0]->GetID()))->second;
int min_depth_dist = genotype->GetDepth() + given_genotypes[0]->GetDepth() - 2 * tmrca->GetDepth();
-
+
for (int i = 1; i < given_genotypes.size() ; ++ i) {
- cAnalyzeGenotype * given_genotype = given_genotypes[i];
- cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
- given_genotype->GetID()))->second;
- int dist = genotype->GetDepth() + given_genotype->GetDepth() - 2 * tmrca->GetDepth();
-
- if (dist < min_depth_dist) {
- min_depth_dist = dist;
- min_depth_gen = given_genotype;
- }
+ cAnalyzeGenotype * given_genotype = given_genotypes[i];
+ cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
+ given_genotype->GetID()))->second;
+ int dist = genotype->GetDepth() + given_genotype->GetDepth() - 2 * tmrca->GetDepth();
+
+ if (dist < min_depth_dist) {
+ min_depth_dist = dist;
+ min_depth_gen = given_genotype;
+ }
}
-
+
const cGenome & given_genome = min_depth_gen->GetGenome();
const cGenome & base_genome = genotype->GetGenome();
cGenome mod_genome(base_genome);
for (int line = 0; line < length_genome; ++ line) {
- int given_inst = given_genome[line].GetOp();
- mod_genome = base_genome;
- mod_genome[line].SetOp(given_inst);
- cAnalyzeGenotype test_genotype(m_world, mod_genome, inst_set);
- test_genotype.Recalculate();
-
- // Only when given inst make the genotype alive
- if (test_genotype.GetFitness() > 0) {
- prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
- }
+ int given_inst = given_genome[line].GetOp();
+ mod_genome = base_genome;
+ mod_genome[line].SetOp(given_inst);
+ cAnalyzeGenotype test_genotype(m_world, mod_genome, inst_set);
+ test_genotype.Recalculate();
+
+ // Only when given inst make the genotype alive
+ if (test_genotype.GetFitness() > 0) {
+ prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
+ }
}
cpx_fp << genotype->GetID() << " " << min_depth_dist << " "
- << raw_dist.find(gen_pair(genotype->GetID(), min_depth_gen->GetID()))->second << " "
- << hamming_dist.find(gen_pair(genotype->GetID(), min_depth_gen->GetID()))->second << " ";
+ << raw_dist.find(gen_pair(genotype->GetID(), min_depth_gen->GetID()))->second << " "
+ << hamming_dist.find(gen_pair(genotype->GetID(), min_depth_gen->GetID()))->second << " ";
} else {
cpx_fp << genotype->GetID() << " ";
}
-
+
///////////////////////////////////////////////////////////////////
// Point mutation at all lines of code to look for neutral mutation
// and the mutations that can make organism alive
@@ -2756,81 +2750,81 @@
vector<bool> one_line_neutral(num_insts, false);
vector< vector<bool> > neutral_mut(length_genome, one_line_neutral);
vector< vector<bool> > alive_mut(length_genome, one_line_neutral);
-// if (verbose == true) {
-// PrintTestCPUResources("");
-// }
-
+ // if (verbose == true) {
+ // PrintTestCPUResources("");
+ // }
+
genotype->Recalculate();
double base_fitness = genotype->GetFitness();
cout << base_fitness << endl;
const cGenome & base_genome = genotype->GetGenome();
cGenome mod_genome(base_genome);
-
+
for (int line = 0; line < length_genome; ++ line) {
int cur_inst = base_genome[line].GetOp();
for (int mod_inst = 0; mod_inst < num_insts; ++ mod_inst) {
- mod_genome[line].SetOp(mod_inst);
- cAnalyzeGenotype test_genotype(m_world, mod_genome, inst_set);
- test_genotype.Recalculate();
- if (test_genotype.GetFitness() >= base_fitness) {
- neutral_mut[line][mod_inst] = true;
- }
- if (test_genotype.GetFitness() > 0) {
- alive_mut[line][mod_inst] = true;
- }
+ mod_genome[line].SetOp(mod_inst);
+ cAnalyzeGenotype test_genotype(m_world, mod_genome, inst_set);
+ test_genotype.Recalculate();
+ if (test_genotype.GetFitness() >= base_fitness) {
+ neutral_mut[line][mod_inst] = true;
+ }
+ if (test_genotype.GetFitness() > 0) {
+ alive_mut[line][mod_inst] = true;
+ }
}
mod_genome[line].SetOp(cur_inst);
}
-
+
/////////////////////////////////////////
// Normalize the probability at each line
vector< vector<double> > prob_before_env(length_genome, one_line_prob);
-
+
for (int line = 0; line < length_genome; ++ line) {
double cur_total_prob = 0.0;
int num_alive = 0;
for (int inst = 0; inst < num_insts; ++ inst) {
- if (alive_mut[line][inst] == true) {
- cur_total_prob += prob[line][inst];
- num_alive ++;
- }
+ if (alive_mut[line][inst] == true) {
+ cur_total_prob += prob[line][inst];
+ num_alive ++;
+ }
}
if (cur_total_prob > 1) {
- cout << "Total probability at " << line << " is greater than 0." << endl;
- exit(1);
+ cout << "Total probability at " << line << " is greater than 0." << endl;
+ exit(1);
}
double left_prob = 1 - cur_total_prob;
-
+
for (int inst = 0; inst < num_insts; ++ inst) {
- if (alive_mut[line][inst] == true) {
- prob_before_env[line][inst] = prob[line][inst] + left_prob / num_alive;
- } else {
- prob_before_env[line][inst] = 0;
- }
+ if (alive_mut[line][inst] == true) {
+ prob_before_env[line][inst] = prob[line][inst] + left_prob / num_alive;
+ } else {
+ prob_before_env[line][inst] = 0;
+ }
}
}
-
+
/////////////////////////////////
// Calculate entropy of each line
vector<double> entropy(length_genome, 0.0);
for (int line = 0; line < length_genome; ++ line) {
double sum = 0;
for (int inst = 0; inst < num_insts; ++ inst) {
- sum += prob_before_env[line][inst];
- if (prob_before_env[line][inst] > 0) {
- entropy[line] -= prob_before_env[line][inst] * log(prob_before_env[line][inst]) / log(num_insts*1.0);
- }
+ sum += prob_before_env[line][inst];
+ if (prob_before_env[line][inst] > 0) {
+ entropy[line] -= prob_before_env[line][inst] * log(prob_before_env[line][inst]) / log(num_insts*1.0);
+ }
}
if (sum > 1.001 || sum < 0.999) {
- cout << "Sum of probability is not 1 at line " << line << endl;
- exit(1);
+ cout << "Sum of probability is not 1 at line " << line << endl;
+ exit(1);
}
}
-
-
+
+
/////////////////////////////////////////////////////
// Redistribute the probability of insts at each line
vector< vector<double> > prob_given_env(length_genome, one_line_prob);
@@ -2839,44 +2833,44 @@
double total_prob = 0.0;
int num_neutral = 0;
for (int inst = 0; inst < num_insts; ++ inst) {
- if (neutral_mut[line][inst] == true) {
- num_neutral ++;
- total_prob += prob[line][inst];
- }
+ if (neutral_mut[line][inst] == true) {
+ num_neutral ++;
+ total_prob += prob[line][inst];
+ }
}
-
+
double left = 1 - total_prob;
-
+
for (int inst = 0; inst < num_insts; ++ inst) {
- if (neutral_mut[line][inst] == true) {
- prob_given_env[line][inst] = prob[line][inst] + left / num_neutral;
- } else {
- prob_given_env[line][inst] = 0.0;
- }
+ if (neutral_mut[line][inst] == true) {
+ prob_given_env[line][inst] = prob[line][inst] + left / num_neutral;
+ } else {
+ prob_given_env[line][inst] = 0.0;
+ }
}
}
-
+
////////////////////////////////////////////////
// Calculate the entropy given environment
-
+
vector<double> entropy_given_env(length_genome, 0.0);
for (int line = 0; line < length_genome; ++ line) {
double sum = 0;
for (int inst = 0; inst < num_insts; ++ inst) {
- sum += prob_given_env[line][inst];
- if (prob_given_env[line][inst] > 0) {
- entropy_given_env[line] -= prob_given_env[line][inst] * log(prob_given_env[line][inst]) /
- log(num_insts*1.0);
- }
+ sum += prob_given_env[line][inst];
+ if (prob_given_env[line][inst] > 0) {
+ entropy_given_env[line] -= prob_given_env[line][inst] * log(prob_given_env[line][inst]) /
+ log(num_insts*1.0);
+ }
}
if (sum > 1.001 || sum < 0.999) {
- cout << "Sum of probability is not 1 at line " << line << " " << sum << endl;
- exit(1);
+ cout << "Sum of probability is not 1 at line " << line << " " << sum << endl;
+ exit(1);
}
}
-
-
+
+
///////////////////////////////////////////////////////////////////////////
// Calculate the information between genotype and env given other genotypes
double information = 0.0;
@@ -2885,50 +2879,49 @@
for (int line = 0; line < length_genome; ++ line) {
entropy_before += entropy[line];
entropy_after += entropy_given_env[line];
-
+
if (entropy[line] >= entropy_given_env[line]) {
- information += entropy[line] - entropy_given_env[line];
+ information += entropy[line] - entropy_given_env[line];
} else { // Negative information is because given condition is not related with this genotype ...
-
- // Count the number of insts that can make genotype alive
- int num_inst_alive = 0;
- for (int inst = 0; inst < num_insts; ++ inst) {
- if (alive_mut[line][inst] == true) {
- num_inst_alive ++;
- }
- }
-
- double entropy_before = - log(1.0/num_inst_alive) / log(num_insts*1.0);
- information += entropy_before - entropy_given_env[line];
- if (information < 0) {
- cout << "Negative information at site " << line << endl;
- exit(1);
- }
+
+ // Count the number of insts that can make genotype alive
+ int num_inst_alive = 0;
+ for (int inst = 0; inst < num_insts; ++ inst) {
+ if (alive_mut[line][inst] == true) {
+ num_inst_alive ++;
+ }
+ }
+
+ double entropy_before = - log(1.0/num_inst_alive) / log(num_insts*1.0);
+ information += entropy_before - entropy_given_env[line];
+ if (information < 0) {
+ cout << "Negative information at site " << line << endl;
+ exit(1);
+ }
}
}
complexity += information;
-
+
cpx_fp << entropy_before << " " << entropy_after << " "
- << information << " " << complexity << " ";
-
+ << information << " " << complexity << " ";
+
genotype->PrintTasks(cpx_fp, 0, -1);
cpx_fp << endl;
-
+
/////////////////////////////////////////////////////////////
// This genotype becomes the given condition of next genotype
-
+
given_genotypes.push_back(genotype);
}
-
+
// Set the test CPU back to the state it was
m_world->GetTestCPU().UseResources() = backupUsage;
m_world->GetTestCPU().SetupResourceArray(backupResources);
-
- cpx_fp.close();
+
+ m_world->GetDataFileManager().Remove(filename);
return;
-
}
void cAnalyze::AnalyzeCommunityComplexity(cString cur_string)
@@ -2936,30 +2929,30 @@
/////////////////////////////////////////////////////////////////////
// Calculate the mutual information between community and environment
/////////////////////////////////////////////////////////////////////
-
+
cout << "Analyze community complexity of current population about environment with Charles method ...\n";
-
+
// Get the number of genotypes that are gonna be analyzed.
int max_genotypes = cur_string.PopWord().AsInt(); // If it is 0, we sample
//two genotypes for each task.
-
+
// Get update
int update = cur_string.PopWord().AsInt();
-
+
// Get the directory
cString dir = cur_string.PopWord();
cString defaultDir = "community_cpx/";
cString directory = PopDirectory(dir, defaultDir);
-
+
// Get the file name that saves the result
cString filename = cur_string.PopWord();
if (filename.IsEmpty()) {
filename = "community.complexity.dat";
}
-
+
filename.Set("%s%s", directory(), filename.GetData());
- ofstream cpx_fp(filename());
-
+ ofstream& cpx_fp = m_world->GetDataFileOFStream(filename);
+
cpx_fp << "# Legend:" << endl;
cpx_fp << "# 1: Genotype ID" << endl;
cpx_fp << "# 2: Entropy given Known Genotypes" << endl;
@@ -2972,15 +2965,15 @@
cpx_fp << "# 9: Total Number of Organisms" << endl;
cpx_fp << "# 10 - : Tasks Implemented" << endl;
cpx_fp << endl;
-
+
///////////////////////
// Backup test CPU data
bool backupUsage = m_world->GetTestCPU().UseResources();
tArray<double> backupResources(m_world->GetTestCPU().GetResources());
m_world->GetTestCPU().UseResources() = true;
FillResources(update);
-
+
vector<cAnalyzeGenotype *> community;
cAnalyzeGenotype * genotype = NULL;
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
@@ -3001,7 +2994,7 @@
genotype = batch_it.Next();
if (genotype == NULL) {
- cpx_fp.close();
+ m_world->GetDataFileManager().Remove(filename);
return;
}
genotype->Recalculate();
@@ -3045,7 +3038,7 @@
////////////////////////////////////////////////////
// Test point mutation of each genotype in community
-
+
int num_insts = inst_set.GetSize();
map<int, tMatrix<double> > point_mut;
int size_community = community.size();
@@ -3053,7 +3046,7 @@
if (size_community > 1) {
length_genome = community[0]->GetLength();
}
-
+
for (int i = 0; i < size_community; ++ i) {
genotype = community[i];
@@ -3061,203 +3054,202 @@
// Point mutation at all lines of code to look for neutral mutation
cout << "Test point mutation for genotype " << genotype->GetID() << endl;
tMatrix<double> prob(length_genome, num_insts);
-// if (verbose == true) {
-// PrintTestCPUResources("");
-// }
-
+ // if (verbose == true) {
+ // PrintTestCPUResources("");
+ // }
+
genotype->Recalculate();
double base_fitness = genotype->GetFitness();
const cGenome & base_genome = genotype->GetGenome();
cGenome mod_genome(base_genome);
-
+
for (int line = 0; line < length_genome; ++ line) {
int cur_inst = base_genome[line].GetOp();
int num_neutral = 0;
-
+
for (int mod_inst = 0; mod_inst < num_insts; ++ mod_inst) {
- mod_genome[line].SetOp(mod_inst);
- cAnalyzeGenotype test_genotype(m_world, mod_genome, inst_set);
- test_genotype.Recalculate();
- if (test_genotype.GetFitness() >= base_fitness) {
- prob[line][mod_inst] = 1.0;
- num_neutral ++;
- } else {
- prob[line][mod_inst] = 0.0;
- }
+ mod_genome[line].SetOp(mod_inst);
+ cAnalyzeGenotype test_genotype(m_world, mod_genome, inst_set);
+ test_genotype.Recalculate();
+ if (test_genotype.GetFitness() >= base_fitness) {
+ prob[line][mod_inst] = 1.0;
+ num_neutral ++;
+ } else {
+ prob[line][mod_inst] = 0.0;
+ }
}
-
+
for (int mod_inst = 0; mod_inst < num_insts; ++ mod_inst) {
- prob[line][mod_inst] /= num_neutral;
+ prob[line][mod_inst] /= num_neutral;
}
-
+
mod_genome[line].SetOp(cur_inst);
}
-
+
point_mut.insert(make_pair(genotype->GetID(), prob));
}
-
+
//////////////////////////////////////
// Loop through genotypes in community
-
+
double complexity = 0.0;
int total_dist = 0;
int total_cpus = 0;
vector<cAnalyzeGenotype *> given_genotypes;
-
+
////////////////////////////////////////
// New information in the first gentoype
genotype = community[0];
double oo_initial_entropy = length_genome;
double oo_conditional_entropy = 0.0;
tMatrix<double> this_prob = point_mut.find(genotype->GetID())->second;
-
+
for (int line = 0; line < length_genome; ++ line) {
double oneline_entropy = 0.0;
for (int inst = 0; inst < num_insts; ++ inst) {
if (this_prob[line][inst] > 0) {
- oneline_entropy -= this_prob[line][inst] * (log(this_prob[line][inst]) /
- log(1.0*num_insts));
+ oneline_entropy -= this_prob[line][inst] * (log(this_prob[line][inst]) /
+ log(1.0*num_insts));
}
}
oo_conditional_entropy += oneline_entropy;
}
-
+
double new_info = oo_initial_entropy - oo_conditional_entropy;
complexity += new_info;
given_genotypes.push_back(genotype);
-
+
cpx_fp << genotype->GetID() << " "
- << oo_initial_entropy << " "
- << oo_conditional_entropy << " "
- << new_info << " "
- << complexity << " "
- << "0 0" << " ";
+ << oo_initial_entropy << " "
+ << oo_conditional_entropy << " "
+ << new_info << " "
+ << complexity << " "
+ << "0 0" << " ";
int num_cpus = genotype->GetNumCPUs();
total_cpus += num_cpus;
cpx_fp << num_cpus << " " << total_cpus << " ";
genotype->Recalculate();
genotype->PrintTasks(cpx_fp, 0, -1);
cpx_fp << endl;
-
-
+
+
//////////////////////////////////////////////////////
// New information in other genotypes in community ...
for (int i = 1; i < size_community; ++ i) {
genotype = community[i];
if (genotype->GetLength() != length_genome) {
cerr << "Genotypes in the community do not same genome length.\n";
- cpx_fp.close();
exit(1);
}
-
+
// Skip the dead organisms
genotype->Recalculate();
cout << genotype->GetID() << " " << genotype->GetFitness() << endl;
if (genotype->GetFitness() == 0) {
continue;
}
-
+
double min_new_info = length_genome;
double oo_initial_entropy, oo_conditional_entropy;
cAnalyzeGenotype * used_genotype;
tMatrix<double> this_prob = point_mut.find(genotype->GetID())->second;
-
+
// For any given genotype, calculate the new information in genotype
for (int j = 0; j < given_genotypes.size(); ++ j) {
-
+
tMatrix<double> given_prob = point_mut.find(given_genotypes[j]->GetID())->second;
double new_info = 0.0;
double total_initial_entropy = 0.0;
double total_conditional_entropy = 0.0;
-
+
for (int line = 0; line < length_genome; ++ line) {
-
- // H(genotype|known_genotype)
- double prob_overlap = 0;
- for (int inst = 0; inst < num_insts; ++ inst) {
- if (this_prob[line][inst] < given_prob[line][inst]) {
- prob_overlap += this_prob[line][inst];
- } else {
- prob_overlap += given_prob[line][inst];
- }
- }
-
- double given_site_entropy = 0.0;
- for (int inst = 0; inst < num_insts; ++ inst) {
- if (given_prob[line][inst] > 0) {
- given_site_entropy -= given_prob[line][inst] * (log(given_prob[line][inst]) /
- log(1.0*num_insts));
- }
- }
-
-
- double entropy_overlap = 0.0;
- if (prob_overlap > 0 && (1 - prob_overlap > 0)) {
- entropy_overlap = (- prob_overlap * log(prob_overlap)
- - (1-prob_overlap) * log(1 - prob_overlap)) / log(1.0*num_insts);
- } else {
- entropy_overlap = 0;
- }
-
- double initial_entropy = prob_overlap * given_site_entropy
- + (1 - prob_overlap) * 1 + entropy_overlap;
- total_initial_entropy += initial_entropy;
-
- // H(genotype|E, known_genotype) = H(genotype|Env)
- double conditional_entropy = 0.0;
- for (int inst = 0; inst < num_insts; ++ inst) {
- if (this_prob[line][inst] > 0) {
- conditional_entropy -= this_prob[line][inst] * (log(this_prob[line][inst]) /
- log(1.0*num_insts));
- }
- }
- total_conditional_entropy += conditional_entropy;
-
- if (conditional_entropy > initial_entropy + 0.00001) {
- cerr << "Negative Information.\n";
- cout << line << endl;
- for (int inst = 0; inst < num_insts; ++ inst) {
- cout << this_prob[line][inst] << " ";
- }
- cout << endl;
- for (int inst = 0; inst < num_insts; ++ inst) {
- cout << given_prob[line][inst] << " ";
- }
- cout << endl;
-
- exit(1);
- }
-
- new_info += initial_entropy - conditional_entropy;
+
+ // H(genotype|known_genotype)
+ double prob_overlap = 0;
+ for (int inst = 0; inst < num_insts; ++ inst) {
+ if (this_prob[line][inst] < given_prob[line][inst]) {
+ prob_overlap += this_prob[line][inst];
+ } else {
+ prob_overlap += given_prob[line][inst];
+ }
+ }
+
+ double given_site_entropy = 0.0;
+ for (int inst = 0; inst < num_insts; ++ inst) {
+ if (given_prob[line][inst] > 0) {
+ given_site_entropy -= given_prob[line][inst] * (log(given_prob[line][inst]) /
+ log(1.0*num_insts));
+ }
+ }
+
+
+ double entropy_overlap = 0.0;
+ if (prob_overlap > 0 && (1 - prob_overlap > 0)) {
+ entropy_overlap = (- prob_overlap * log(prob_overlap)
+ - (1-prob_overlap) * log(1 - prob_overlap)) / log(1.0*num_insts);
+ } else {
+ entropy_overlap = 0;
+ }
+
+ double initial_entropy = prob_overlap * given_site_entropy
+ + (1 - prob_overlap) * 1 + entropy_overlap;
+ total_initial_entropy += initial_entropy;
+
+ // H(genotype|E, known_genotype) = H(genotype|Env)
+ double conditional_entropy = 0.0;
+ for (int inst = 0; inst < num_insts; ++ inst) {
+ if (this_prob[line][inst] > 0) {
+ conditional_entropy -= this_prob[line][inst] * (log(this_prob[line][inst]) /
+ log(1.0*num_insts));
+ }
+ }
+ total_conditional_entropy += conditional_entropy;
+
+ if (conditional_entropy > initial_entropy + 0.00001) {
+ cerr << "Negative Information.\n";
+ cout << line << endl;
+ for (int inst = 0; inst < num_insts; ++ inst) {
+ cout << this_prob[line][inst] << " ";
+ }
+ cout << endl;
+ for (int inst = 0; inst < num_insts; ++ inst) {
+ cout << given_prob[line][inst] << " ";
+ }
+ cout << endl;
+
+ exit(1);
+ }
+
+ new_info += initial_entropy - conditional_entropy;
}
-
+
if (new_info < min_new_info) {
- min_new_info = new_info;
- oo_initial_entropy = total_initial_entropy;
- oo_conditional_entropy = total_conditional_entropy;
- used_genotype = given_genotypes[j];
- cout << " " << "New closest genotype " << used_genotype->GetID()
- << " " << new_info << endl;;
+ min_new_info = new_info;
+ oo_initial_entropy = total_initial_entropy;
+ oo_conditional_entropy = total_conditional_entropy;
+ used_genotype = given_genotypes[j];
+ cout << " " << "New closest genotype " << used_genotype->GetID()
+ << " " << new_info << endl;;
}
-
+
}
complexity += min_new_info;
cpx_fp << genotype->GetID() << " "
- << oo_initial_entropy << " "
- << oo_conditional_entropy << " "
- << min_new_info << " " << complexity << " ";
-
+ << oo_initial_entropy << " "
+ << oo_conditional_entropy << " "
+ << min_new_info << " " << complexity << " ";
+
int hamm_dist = cGenomeUtil::FindHammingDistance(genotype->GetGenome(),
- used_genotype->GetGenome());
+ used_genotype->GetGenome());
total_dist += hamm_dist;
cpx_fp << hamm_dist << " " << total_dist << " ";
- int num_cpus = genotype->GetNumCPUs();
- total_cpus += num_cpus;
- cpx_fp << num_cpus << " " << total_cpus << " ";
-
+ int num_cpus = genotype->GetNumCPUs();
+ total_cpus += num_cpus;
+ cpx_fp << num_cpus << " " << total_cpus << " ";
+
genotype->PrintTasks(cpx_fp, 0, -1);
cpx_fp << endl;
given_genotypes.push_back(genotype);
@@ -3267,12 +3259,9 @@
// Set the test CPU back to the state it was
m_world->GetTestCPU().UseResources() = backupUsage;
m_world->GetTestCPU().SetupResourceArray(backupResources);
-
- cpx_fp.close();
- return;
-
-
+ m_world->GetDataFileManager().Remove(filename);
+ return;
}
void cAnalyze::CommandLandscape(cString cur_string)
@@ -3289,7 +3278,7 @@
if (cur_string.GetSize() != 0) num_test=cur_string.PopWord().AsInt();
// If we're given a file, write to it.
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// Loop through all of the genotypes in this batch...
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
@@ -3314,7 +3303,7 @@
if (cur_string.GetSize() != 0) test_num = cur_string.PopWord().AsInt();
// If we're given a file, write to it.
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// Loop through all of the genotypes in this batch...
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
@@ -3340,9 +3329,9 @@
double min_swap_frac = 0.0;
if (cur_string.GetSize() != 0) min_swap_frac=cur_string.PopWord().AsDouble();
double max_swap_frac = 1.0 - min_swap_frac;
-
+
cout << "Analyzing Mate Selection... " << endl;
-
+
// Do some quick tests before moving on...
if (min_swap_frac < 0.0 || min_swap_frac >= 0.5) {
cerr << "ERROR: Minimum swap fraction out of range [0.0, 0.5)." << endl;
@@ -3352,11 +3341,11 @@
// in this batch. Note that we want to select genotypes based on their
// abundance, so they will have one entry in the array per organism. Note
// that we only consider viable genotypes.
-
+
// Start by counting the total number of organisms (and do other such
// data collection...
tHashTable<int, int> mate_id_counts;
-
+
int org_count = 0;
int gen_count = 0;
cAnalyzeGenotype * genotype = NULL;
@@ -3367,7 +3356,7 @@
}
gen_count++;
org_count += genotype->GetNumCPUs();
-
+
// Keep track of how many organisms have each mate id...
int mate_id = genotype->GetMateID();
int count = 0;
@@ -3375,10 +3364,10 @@
count += genotype->GetNumCPUs();
mate_id_counts.SetValue(mate_id, count);
}
-
+
// Create an array of the correct size.
tArray<cAnalyzeGenotype *> genotype_array(org_count);
-
+
// And insert all of the organisms into the array.
int cur_pos = 0;
while ((genotype = list_it.Next()) != NULL) {
@@ -3389,29 +3378,29 @@
}
}
-
+
// Setup some variables to collect statistics.
int total_matches_tested = 0;
int fail_count = 0;
int match_fail_count = 0;
-
+
// Loop through all of the tests, picking random organisms each time and
// performing a random cross test.
cAnalyzeGenotype * genotype2 = NULL;
for (int test_id = 0; test_id < sample_size; test_id++) {
genotype = genotype_array[ m_world->GetRandom().GetUInt(org_count) ];
genotype2 = genotype_array[ m_world->GetRandom().GetUInt(org_count) ];
-
+
// Stop immediately if we're comparing a genotype to itself.
if (genotype == genotype2) {
total_matches_tested++;
continue;
}
-
+
// Setup the random parameters for this test.
cCPUMemory test_genome0 = genotype->GetGenome();
cCPUMemory test_genome1 = genotype2->GetGenome();
-
+
double start_frac = -1.0;
double end_frac = -1.0;
double swap_frac = -1.0;
@@ -3421,38 +3410,38 @@
if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
swap_frac = end_frac - start_frac;
}
-
+
int start0 = (int) (start_frac * (double) test_genome0.GetSize());
int end0 = (int) (end_frac * (double) test_genome0.GetSize());
int size0 = end0 - start0;
-
+
int start1 = (int) (start_frac * (double) test_genome1.GetSize());
int end1 = (int) (end_frac * (double) test_genome1.GetSize());
int size1 = end1 - start1;
-
+
int new_size0 = test_genome0.GetSize() - size0 + size1;
int new_size1 = test_genome1.GetSize() - size1 + size0;
-
+
// Setup some statistics for this particular test.
bool same_mate_id = ( genotype->GetMateID() == genotype2->GetMateID() );
if (same_mate_id == true) total_matches_tested++;
-
+
// Don't Crossover if offspring will be illegal!!!
if (new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE ||
- new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE) {
+ new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE) {
fail_count++;
if (same_mate_id == true) match_fail_count++;
continue;
}
-
+
// Do the replacement... We're only going to test genome0, so we only
// need to modify that one.
cGenome cross1 = cGenomeUtil::Crop(test_genome1, start1, end1);
test_genome0.Replace(start0, size0, cross1);
-
+
// Do the test.
cCPUTestInfo test_info;
-
+
// Run each side, and determine viability...
m_world->GetTestCPU().TestGenome(test_info, test_genome0);
if( test_info.IsViable() == false ) {
@@ -3460,16 +3449,16 @@
if (same_mate_id == true) match_fail_count++;
}
}
-
+
// Do some calculations on the sizes of the mate groups...
const int num_mate_groups = mate_id_counts.GetSize();
-
+
// Collect lists on all of the mate groups for the calculations...
tList<int> key_list;
tList<int> count_list;
mate_id_counts.AsLists(key_list, count_list);
tListIterator<int> count_it(count_list);
-
+
int max_group_size = 0;
double mate_id_entropy = 0.0;
while (count_it.Next() != NULL) {
@@ -3484,10 +3473,10 @@
double match_fail_frac =
(double) match_fail_count / (double) total_matches_tested;
cout << " ave fraction failed = " << fail_frac << endl
- << " ave matches failed = " << match_fail_frac << endl
- << " total mate matches = " << total_matches_tested
- << " / " << sample_size<< endl;
-
+ << " ave matches failed = " << match_fail_frac << endl
+ << " total mate matches = " << total_matches_tested
+ << " / " << sample_size<< endl;
+
if (filename == "none") return;
cDataFile & df = m_world->GetDataFile(filename);
@@ -3506,7 +3495,7 @@
df.Endl();
}
-
+
void cAnalyze::AnalyzeComplexityDelta(cString cur_string)
{
// This command will examine the current population, and sample mutations
@@ -3834,7 +3823,7 @@
cout << output_it.Get()->GetName() << " ";
}
cout << endl;
- }
+ }
///////////////////////////////////////////////////////
@@ -3852,7 +3841,7 @@
} else { // if (file_type == FILE_TYPE_HTML) {
filename.Set("%stasksites.%s.html", directory(), genotype->GetName()());
}
- ofstream fp(filename());
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// Construct linked filenames...
cString next_file("");
@@ -4102,7 +4091,7 @@
cout << endl;
}
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// printing the headers
// not done by default since many dumps may be analyzed at the same time
@@ -4465,7 +4454,7 @@
} else { // if (file_type == FILE_TYPE_HTML) {
filename.Set("%smut_map.%s.html", directory(), genotype->GetName()());
}
- ofstream fp(filename());
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// Calculate the stats for the genotype we're working with...
genotype->Recalculate();
@@ -4586,7 +4575,7 @@
row_fitness += test_fitness;
total_fitness += test_fitness;
col_fitness[mod_inst] += test_fitness;
-
+
// Categorize this mutation...
if (test_fitness == 1.0) { // Neutral Mutation...
row_neut++;
@@ -4716,7 +4705,7 @@
cout << "max_depth = " << max_depth << endl;
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
cout << "Output to " << filename << endl;
tArray<int> depth_array(max_depth+1);
@@ -4946,13 +4935,13 @@
break;
}
- // Swap the components
- cGenome cross0 = cGenomeUtil::Crop(test_genome0, start0, end0);
- cGenome cross1 = cGenomeUtil::Crop(test_genome1, start1, end1);
- test_genome0.Replace(start0, size0, cross1);
- test_genome1.Replace(start1, size1, cross0);
+ // Swap the components
+ cGenome cross0 = cGenomeUtil::Crop(test_genome0, start0, end0);
+ cGenome cross1 = cGenomeUtil::Crop(test_genome1, start1, end1);
+ test_genome0.Replace(start0, size0, cross1);
+ test_genome1.Replace(start1, size1, cross0);
- // Run each side, and determine viability...
+ // Run each side, and determine viability...
cCPUTestInfo test_info;
m_world->GetTestCPU().TestGenome(test_info, test_genome0);
cross1_viable = test_info.IsViable();
@@ -5181,15 +5170,15 @@
///////////////////////////////////////////////////////
// Loop through all of the genotypes in this batch...
- cString newinfo_fn;
- ofstream newinfo_fp;
- if (batch[cur_batch].IsLineage() == true) {
- newinfo_fn.Set("%s%s.newinfo.dat", directory(), "lineage");
- newinfo_fp.open(newinfo_fn);
- } else {
+ if (batch[cur_batch].IsLineage() != true) {
cout << "This command requires the lineage in the batch, skipping.\n";
return;
}
+
+ cString newinfo_fn;
+ newinfo_fn.Set("%s%s.newinfo.dat", directory(), "lineage");
+ ofstream& newinfo_fp = m_world->GetDataFileOFStream(newinfo_fn);
+
newinfo_fp << "# Legend:" << endl;
newinfo_fp << "# 1:Child Genotype ID" << endl;
newinfo_fp << "# 2:Parent Genotype ID" << endl;
@@ -5204,14 +5193,14 @@
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
cAnalyzeGenotype * parent_genotype = batch_it.Next();
if (parent_genotype == NULL) {
- newinfo_fp.close();
+ m_world->GetDataFileManager().Remove(newinfo_fn);
return;
}
cAnalyzeGenotype * child_genotype = NULL;
double I_P_E; // Information of parent about environment
double H_P_E = AnalyzeEntropy(parent_genotype, mu);
I_P_E = parent_genotype->GetLength() - H_P_E;
-
+
while ((child_genotype = batch_it.Next()) != NULL) {
if (verbose == true) {
@@ -5221,10 +5210,10 @@
// Information of parent about its environment should not be zero.
if (I_P_E == 0) {
cerr << "Error: Information between parent and its enviroment is zero."
- << "(cAnalyze::AnalyzeNewInfo)" << endl;
+ << "(cAnalyze::AnalyzeNewInfo)" << endl;
exit(1);
}
-
+
double H_C_E = AnalyzeEntropy(child_genotype, mu);
double I_C_E = child_genotype->GetLength() - H_C_E;
double net_gain = I_C_E - I_P_E;
@@ -5234,7 +5223,7 @@
// Lost information in child compared to parent
double child_lost_info = IncreasedInfo(parent_genotype, child_genotype, mu);
-
+
// Write information to file ...
newinfo_fp << child_genotype->GetID() << " ";
newinfo_fp << parent_genotype->GetID() << " ";
@@ -5249,7 +5238,7 @@
I_P_E = I_C_E;
}
- newinfo_fp.close();
+ m_world->GetDataFileManager().Remove(newinfo_fn);
return;
}
@@ -5264,7 +5253,7 @@
if (cur_string.GetSize() != 0) num_cells = cur_string.PopWord().AsInt();
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// Start up again at update zero...
fp << "0 ";
@@ -5323,7 +5312,7 @@
if (cur_string.GetSize() != 0) start_cell = cur_string.PopWord().AsInt();
if (cur_string.GetSize() != 0) lineage = cur_string.PopWord().AsInt();
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
int org_count = 0;
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
@@ -5376,7 +5365,7 @@
return;
}
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// Count the number of organisms in each batch...
cAnalyzeGenotype * genotype = NULL;
@@ -5496,7 +5485,7 @@
cString & last_seq = sequences[num_sequences - 1];
// Print out the header...
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
fp << "# " << sequences[0] << endl;
fp << "# " << sequences[num_sequences - 1] << endl;
fp << "# ";
@@ -5648,7 +5637,7 @@
const int num_insts = inst_set.GetSize();
// Setup the file...
- ofstream fp(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// Determine the file type...
int file_type = FILE_TYPE_TEXT;
@@ -5788,7 +5777,7 @@
const int num_insts = inst_set.GetSize();
// Setup the file...
- ofstream fp(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
for (int i = 0; i < num_insts; i++) {
cInstruction cur_inst(i);
@@ -5845,7 +5834,7 @@
if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
// Setup the file...
- ofstream fp(filename);
+ //ofstream& fp = m_world->GetDataFileOFStream(filename);
// UNFINISHED!
// const int num_insts = inst_set.GetSize();
@@ -5892,7 +5881,7 @@
prev_inst.SetAll(-1); // -1 indicates never changed.
// Open the output file...
- ofstream fp(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
// Loop through all of the genotypes again, testing mutation reversions.
cAnalyzeGenotype * prev_genotype = batch_it.Next();
@@ -6001,21 +5990,13 @@
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
cAnalyzeGenotype * genotype = NULL;
-
- bool islineage = false;
cString lineage_filename;
- ofstream lineage_fp;
- ofstream non_lineage_fp;
- if (batch[cur_batch].IsLineage() == true) {
+ if (batch[cur_batch].IsLineage()) {
lineage_filename.Set("%s%s.complexity.dat", directory(), "lineage");
- lineage_fp.open(lineage_filename);
- islineage = true;
} else {
- cString non_lineage_file;
- non_lineage_file.Set("%s%s.complexity.dat", directory(), "nonlineage");
- non_lineage_fp.open(non_lineage_file);
- islineage = false;
+ lineage_filename.Set("%s%s.complexity.dat", directory(), "nonlineage");
}
+ ofstream& lineage_fp = m_world->GetDataFileOFStream(lineage_filename);
while ((genotype = batch_it.Next()) != NULL) {
if (verbose == true) {
@@ -6025,13 +6006,10 @@
// Construct this filename...
cString filename;
filename.Set("%s%s.complexity.dat", directory(), genotype->GetName()());
- ofstream fp(filename());
- if (islineage) {
- lineage_fp << genotype->GetID() << " ";
- } else {
- non_lineage_fp << genotype->GetID() << " ";
- }
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
+ lineage_fp << genotype->GetID() << " ";
+
int updateBorn = -1;
if(useResources) {
updateBorn = genotype->GetUpdateBorn();
@@ -6117,22 +6095,16 @@
double complexity = 1 - entropy;
fp << complexity << endl;
- if (islineage) {
- lineage_fp << complexity << " ";
- } else {
- non_lineage_fp << complexity << " ";
- }
+ lineage_fp << complexity << " ";
// Reset the mod_genome back to the original sequence.
mod_genome[line_num].SetOp(cur_inst);
}
- fp.close();
- if (islineage) {
- lineage_fp << endl;
- } else {
- non_lineage_fp << endl;
- }
+ m_world->GetDataFileManager().Remove(filename);
+
+ lineage_fp << endl;
+
// Always grabs the first one
// Skip i-1 times, so that the beginning of the loop will grab the ith one
// where i is the batchFrequency
@@ -6144,12 +6116,9 @@
}
if(genotype == NULL) { break; }
}
- if (islineage) {
- lineage_fp.close();
- } else {
- non_lineage_fp.close();
- }
+ m_world->GetDataFileManager().Remove(lineage_filename);
+
if(useResources) {
// Set the test cpu back to the state it was in before we messed with it
m_world->GetTestCPU().UseResources() = backupUsage;
@@ -6164,37 +6133,13 @@
cout << "Analyzing population complexity ..." << endl;
// Load in the variables...
- //int batch_size = cur_string.PopWord().AsInt();
- //int sample_size = cur_string.PopWord().AsInt();
cString directory = PopDirectory(cur_string, "pop_complexity/");
cString file = cur_string;
- // Get sample index...
- /*if (sample_size > batch_size) {
- cout << " Sample size is greater than batch size." << endl;
- return;
- }
-int *index_array;
-int *flag_array;
-index_array = (int*) malloc (batch_size*sizeof(int));
-flag_array = (int*) malloc (batch_size*sizeof(int));
-for (int i=0; i<batch_size; i++) {
- index_array[i] = i;
- flag_array[i] = 0;
-}
-int max_num = batch_size;
-cRandom random;
-for (int i=0; i<sample_size; i++) {
- int index = random.GetUInt(max_num);
- flag_array[index_array[index]] = 1;
- index_array[index] = index_array[max_num-1];
- max_num--;
-}*/
-
// Construct filename...
cString filename;
filename.Set("%spop%s.complexity.dat", directory(), file());
- ofstream fp(filename());
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
//////////////////////////////////////////////////////////
// Loop through all of the genotypes in this batch ...
@@ -6215,7 +6160,7 @@
for (int line_num = 0; line_num < seq_length; line_num ++)
for (int inst_num = 0; inst_num < num_insts; inst_num ++)
inst_stat(line_num, inst_num) = 0;
-
+
int num_cpus = 0;
int actural_samples = 0;
while (genotype != NULL) {
@@ -6236,32 +6181,27 @@
genotype = batch_it.Next();
}
-
-
-// Calculate complexity
-for (int line_num = 0; line_num < seq_length; line_num ++) {
- double entropy = 0.0;
- for (int inst_num = 0; inst_num < num_insts; inst_num ++) {
- if (inst_stat(line_num, inst_num) == 0) continue;
- float prob = (float) (inst_stat(line_num, inst_num)) / (float) (actural_samples);
- entropy += prob * log((double) 1.0/prob) / log((double) num_insts);
+ // Calculate complexity
+ for (int line_num = 0; line_num < seq_length; line_num ++) {
+ double entropy = 0.0;
+ for (int inst_num = 0; inst_num < num_insts; inst_num ++) {
+ if (inst_stat(line_num, inst_num) == 0) continue;
+ float prob = (float) (inst_stat(line_num, inst_num)) / (float) (actural_samples);
+ entropy += prob * log((double) 1.0/prob) / log((double) num_insts);
+ }
+ double complexity = 1 - entropy;
+ fp << complexity << " ";
}
- double complexity = 1 - entropy;
- fp << complexity << " ";
-};
-fp << endl;
-fp.close();
-//free(index_array);
-//free(flag_array);
-return;
+ fp << endl;
+
+ m_world->GetDataFileManager().Remove(filename);
+ return;
}
void cAnalyze::EnvironmentSetup(cString cur_string)
{
- cout << "Running environment command: " << endl
- << " " << cur_string << endl;
-
+ cout << "Running environment command: " << endl << " " << cur_string << endl;
m_world->GetEnvironment().LoadLine(cur_string);
}
@@ -6439,7 +6379,7 @@
if (useResources && update > -1) {
FillResources(update);
}
-
+
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
cAnalyzeGenotype * genotype = NULL;
cAnalyzeGenotype * last_genotype = NULL;
@@ -6454,9 +6394,9 @@
// If the previous genotype was the parent of this one, pass in a pointer
// to it for improved recalculate (such as distance to parent, etc.)
-// if (verbose == true) {
-// PrintTestCPUResources("");
-// }
+ // if (verbose == true) {
+ // PrintTestCPUResources("");
+ // }
if (last_genotype != NULL &&
genotype->GetParentID() == last_genotype->GetID()) {
genotype->Recalculate(last_genotype);
@@ -7246,7 +7186,7 @@
AddLibraryDef("PRINT_PHENOTYPES", &cAnalyze::CommandPrintPhenotypes);
AddLibraryDef("PRINT_DIVERSITY", &cAnalyze::CommandPrintDiversity);
AddLibraryDef("COMMUNITY_COMPLEXITY", &cAnalyze::AnalyzeCommunityComplexity);
-
+
// Individual organism analysis...
AddLibraryDef("LANDSCAPE", &cAnalyze::CommandLandscape);
AddLibraryDef("FITNESS_MATRIX", &cAnalyze::CommandFitnessMatrix);
Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/analyze/cAnalyze.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -101,17 +101,17 @@
int BatchUtil_GetMaxLength(int batch_id=-1);
// Comamnd helpers...
- void CommandDetail_Header(std::ostream & fp, int format_type,
+ void CommandDetail_Header(std::ostream& fp, int format_type,
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
int time_step=-1);
- void CommandDetail_Body(std::ostream & fp, int format_type,
+ void CommandDetail_Body(std::ostream& fp, int format_type,
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
int time_step=-1, int max_time=1);
- void CommandDetailAverage_Body(std::ostream & fp, int num_arguments,
+ void CommandDetailAverage_Body(std::ostream& fp, int num_arguments,
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
- void CommandHistogram_Header(std::ostream & fp, int format_type,
+ void CommandHistogram_Header(std::ostream& fp, int format_type,
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
- void CommandHistogram_Body(std::ostream & fp, int format_type,
+ void CommandHistogram_Body(std::ostream& fp, int format_type,
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
private:
Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/analyze/cAnalyzeGenotype.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -210,7 +210,7 @@
}
-void cAnalyzeGenotype::PrintTasks(ofstream & fp, int min_task, int max_task)
+void cAnalyzeGenotype::PrintTasks(ofstream& fp, int min_task, int max_task)
{
if (max_task == -1) max_task = task_counts.GetSize();
Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/analyze/cAnalyzeGenotype.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -121,7 +121,7 @@
void SetSpecialArgs(const cStringList & _args) { special_args = _args; }
void Recalculate(cAnalyzeGenotype * parent_genotype=NULL);
- void PrintTasks(std::ofstream & fp, int min_task=0, int max_task=-1);
+ void PrintTasks(std::ofstream& fp, int min_task=0, int max_task=-1);
// Set...
void SetSequence(cString _sequence);
Modified: development/source/analyze/cAnalyzeUtil.cc
===================================================================
--- development/source/analyze/cAnalyzeUtil.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/analyze/cAnalyzeUtil.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -35,36 +35,36 @@
using namespace std;
void cAnalyzeUtil::TestGenome(cWorld* world, const cGenome & genome, cInstSet & inst_set,
- ofstream & fp, int update)
+ ofstream& fp, int update)
{
cCPUTestInfo test_info;
world->GetTestCPU().TestGenome(test_info, genome);
-
+
cPhenotype &colony_phenotype = test_info.GetColonyOrganism()->GetPhenotype();
fp << update << " " // 1
- << colony_phenotype.GetMerit().GetDouble() << " " // 2
- << colony_phenotype.GetGestationTime() << " " // 3
- << colony_phenotype.GetFitness() << " " // 4
- << 1.0 / (0.1 + colony_phenotype.GetGestationTime()) << " " // 5
- << genome.GetSize() << " " // 6
- << colony_phenotype.GetCopiedSize() << " " // 7
- << colony_phenotype.GetExecutedSize() << endl; // 8
+ << colony_phenotype.GetMerit().GetDouble() << " " // 2
+ << colony_phenotype.GetGestationTime() << " " // 3
+ << colony_phenotype.GetFitness() << " " // 4
+ << 1.0 / (0.1 + colony_phenotype.GetGestationTime()) << " " // 5
+ << genome.GetSize() << " " // 6
+ << colony_phenotype.GetCopiedSize() << " " // 7
+ << colony_phenotype.GetExecutedSize() << endl; // 8
}
-void cAnalyzeUtil::TestInsSizeChangeRobustness(cWorld* world, ofstream & fp,
- const cInstSet & inst_set, const cGenome & in_genome,
- int num_trials, int update)
+void cAnalyzeUtil::TestInsSizeChangeRobustness(cWorld* world, ofstream& fp,
+ const cInstSet & inst_set, const cGenome & in_genome,
+ int num_trials, int update)
{
cCPUTestInfo test_info;
const cInstruction inst_none = inst_set.GetInst("instruction_none");
-
+
// Stats
int num_viable = 0;
int num_new_size = 0;
int num_parent_size = 0;
-
+
for (int i = 0; i < num_trials; i++) {
cCPUMemory genome(in_genome);
// Should check to only insert infront of an instruction (not a Nop)
@@ -73,85 +73,75 @@
ins_pos = world->GetRandom().GetUInt(genome.GetSize());
if( inst_set.IsNop(genome[ins_pos]) ) ins_pos = -1;
}
-
+
// Insert some "instruction_none" into the genome
const int num_nops = world->GetRandom().GetUInt(5) + 5;
for (int j = 0; j < num_nops; j++) genome.Insert(ins_pos, inst_none);
-
+
// Test the genome and output stats
if (world->GetTestCPU().TestGenome(test_info, genome)){ // Daughter viable...
num_viable++;
const double child_size =
- test_info.GetColonyOrganism()->GetGenome().GetSize();
-
+ test_info.GetColonyOrganism()->GetGenome().GetSize();
+
if (child_size == (double) in_genome.GetSize()) num_parent_size++;
else if (child_size == (double) genome.GetSize()) num_new_size++;
}
} // for num_trials
-
+
fp << update << " "
- << (double) num_viable / num_trials << " "
- << (double) num_new_size / num_trials << " "
- << (double) num_parent_size / num_trials << " "
- << endl;
+ << (double) num_viable / num_trials << " "
+ << (double) num_new_size / num_trials << " "
+ << (double) num_parent_size / num_trials << " "
+ << endl;
}
// Returns the genome of maximal fitness.
cGenome cAnalyzeUtil::CalcLandscape(cWorld* world, int dist, const cGenome & genome,
- cInstSet & inst_set)
+ cInstSet & inst_set)
{
cLandscape landscape(world, genome, inst_set);
landscape.Process(dist);
double peak_fitness = landscape.GetPeakFitness();
cGenome peak_genome = landscape.GetPeakGenome();
-
+
// Print the results.
-
- static ofstream fp("landscape.dat");
- static ofstream fp_entropy("land-entropy.dat");
- static ofstream fp_count("land-sitecount.dat");
-
- landscape.PrintStats(fp);
- landscape.PrintEntropy(fp_entropy);
- landscape.PrintSiteCount(fp_count);
-
+ landscape.PrintStats(world->GetDataFileOFStream("landscape.dat"));
+ landscape.PrintEntropy(world->GetDataFileOFStream("land-entropy.dat"));
+ landscape.PrintSiteCount(world->GetDataFileOFStream("land-sitecount.dat"));
+
// Repeat for Insertions...
landscape.Reset(genome);
landscape.ProcessInsert();
- static ofstream fp_ins("landscape-ins.dat");
- static ofstream fp_ins_count("land-ins-sitecount.dat");
- landscape.PrintStats(fp_ins);
- landscape.PrintSiteCount(fp_ins_count);
+ landscape.PrintStats(world->GetDataFileOFStream("landscape-ins.dat"));
+ landscape.PrintSiteCount(world->GetDataFileOFStream("land-ins-sitecount.dat"));
if (landscape.GetPeakFitness() > peak_fitness) {
peak_fitness = landscape.GetPeakFitness();
peak_genome = landscape.GetPeakGenome();
}
-
+
// And Deletions...
landscape.Reset(genome);
landscape.ProcessDelete();
- static ofstream fp_del("landscape-del.dat");
- static ofstream fp_del_count("land-del-sitecount.dat");
- landscape.PrintStats(fp_del);
- landscape.PrintSiteCount(fp_del_count);
+ landscape.PrintStats(world->GetDataFileOFStream("landscape-del.dat"));
+ landscape.PrintSiteCount(world->GetDataFileOFStream("land-del-sitecount.dat"));
if (landscape.GetPeakFitness() > peak_fitness) {
peak_fitness = landscape.GetPeakFitness();
peak_genome = landscape.GetPeakGenome();
}
-
+
return peak_genome;
}
void cAnalyzeUtil::AnalyzeLandscape(cWorld* world, const cGenome & genome, cInstSet &inst_set,
- int sample_size, int min_found, int max_sample_size, int update)
+ int sample_size, int min_found, int max_sample_size, int update)
{
cLandscape landscape(world, genome, inst_set);
-
- static ofstream fp("land_analyze.dat");
-
+ ofstream& fp = world->GetDataFileOFStream("land_analyze.dat");
+
int num_found = 0;
for (int dist = 1; dist <= 10; dist++) {
landscape.Reset(genome);
@@ -159,38 +149,39 @@
landscape.Process(dist);
num_found = genome.GetSize() * (inst_set.GetSize() - 1);
} else {
- num_found =
- landscape.RandomProcess(sample_size, dist, min_found, max_sample_size);
+ num_found = landscape.RandomProcess(sample_size, dist, min_found, max_sample_size);
}
-
+
fp << update << " " // 1
- << dist << " " // 2
- << landscape.GetProbDead() << " " // 3
- << landscape.GetProbNeg() << " " // 4
- << landscape.GetProbNeut() << " " // 5
- << landscape.GetProbPos() << " " // 6
- << landscape.GetNumTrials() << " " // 7
- << num_found << " " // 8
- << landscape.GetAveFitness() << " " // 9
- << landscape.GetAveSqrFitness() << " " // 10
- << endl;
-
+ << dist << " " // 2
+ << landscape.GetProbDead() << " " // 3
+ << landscape.GetProbNeg() << " " // 4
+ << landscape.GetProbNeut() << " " // 5
+ << landscape.GetProbPos() << " " // 6
+ << landscape.GetNumTrials() << " " // 7
+ << num_found << " " // 8
+ << landscape.GetAveFitness() << " " // 9
+ << landscape.GetAveSqrFitness() << " " // 10
+ << endl;
+
if ((dist > 1) && (num_found < min_found)) break;
}
}
void cAnalyzeUtil::PairTestLandscape(cWorld* world, const cGenome &genome, cInstSet &inst_set,
- int sample_size, int update)
+ int sample_size, int update)
{
cLandscape landscape(world, genome, inst_set);
-
+
cString filename;
filename.Set("pairtest.%d.dat", update);
- ofstream fp(filename());
-
+ ofstream& fp = world->GetDataFileOFStream(filename);
+
if (sample_size != 0) landscape.TestPairs(sample_size, fp);
else landscape.TestAllPairs(fp);
+
+ world->GetDataFileManager().Remove(filename);
}
@@ -200,45 +191,45 @@
const int num_inst = world->GetHardwareManager().GetInstSet().GetSize();
const int update = world->GetStats().GetUpdate();
cGenebank & genebank = population->GetGenebank();
-
+
// Setup the histogtams...
cHistogram * inst_hist = new cHistogram[MAX_CREATURE_SIZE];
for (int i = 0; i < MAX_CREATURE_SIZE; i++) inst_hist[i].Resize(num_inst,-1);
-
+
// Loop through all of the genotypes adding them to the histograms.
cGenotype * cur_genotype = genebank.GetBestGenotype();
for (int i = 0; i < genebank.GetSize(); i++) {
const int num_organisms = cur_genotype->GetNumOrganisms();
const int length = cur_genotype->GetLength();
const cGenome & genome = cur_genotype->GetGenome();
-
+
// Place this genotype into the histograms.
for (int j = 0; j < length; j++) {
assert(genome[j].GetOp() < num_inst);
inst_hist[j].Insert(genome[j].GetOp(), num_organisms);
}
-
+
// Mark all instructions beyond the length as -1 in histogram...
for (int j = length; j < MAX_CREATURE_SIZE; j++) {
inst_hist[j].Insert(-1, num_organisms);
}
-
+
// ...and advance to the next genotype...
cur_genotype = cur_genotype->GetNext();
}
-
+
// Now, lets print something!
- static ofstream fp("consensus.dat");
- static ofstream fp_abundance("con-abundance.dat");
- static ofstream fp_var("con-var.dat");
- static ofstream fp_entropy("con-entropy.dat");
-
+ ofstream& fp = world->GetDataFileOFStream("consensus.dat");
+ ofstream& fp_abundance = world->GetDataFileOFStream("con-abundance.dat");
+ ofstream& fp_var = world->GetDataFileOFStream("con-var.dat");
+ ofstream& fp_entropy = world->GetDataFileOFStream("con-entropy.dat");
+
// Determine the length of the concensus genome
int con_length;
for (con_length = 0; con_length < MAX_CREATURE_SIZE; con_length++) {
if (inst_hist[con_length].GetMode() == -1) break;
}
-
+
// Build the concensus genotype...
cGenome con_genome(con_length);
double total_entropy = 0.0;
@@ -248,14 +239,14 @@
const int total = inst_hist[i].GetCount();
const double entropy = inst_hist[i].GetNormEntropy();
if (i < con_length) total_entropy += entropy;
-
+
// Break out if ALL creatures have a -1 in this area, and we've
// finished printing all of the files.
if (mode == -1 && count == total) break;
-
+
if ( i < con_length )
con_genome[i].SetOp(mode);
-
+
// Print all needed files.
if (i < lines_saved) {
fp_abundance << count << " ";
@@ -263,16 +254,16 @@
fp_entropy << entropy << " ";
}
}
-
+
// Put end-of-lines on the files.
if (lines_saved > 0) {
fp_abundance << endl;
fp_var << endl;
fp_entropy << endl;
}
-
+
// --- Study the consensus genome ---
-
+
// Loop through genotypes again, and determine the average genetic distance.
cur_genotype = genebank.GetBestGenotype();
cDoubleSum distance_sum;
@@ -281,47 +272,47 @@
const int cur_dist =
cGenomeUtil::FindEditDistance(con_genome, cur_genotype->GetGenome());
distance_sum.Add(cur_dist, num_organisms);
-
+
// ...and advance to the next genotype...
cur_genotype = cur_genotype->GetNext();
}
-
+
// Finally, gather last bits of data and print the results.
cGenotype * con_genotype = genebank.FindGenotype(con_genome, -1);
const int best_dist = cGenomeUtil::FindEditDistance(con_genome,
- genebank.GetBestGenotype()->GetGenome());
-
+ genebank.GetBestGenotype()->GetGenome());
+
const double ave_dist = distance_sum.Average();
const double var_dist = distance_sum.Variance();
const double complexity_base = (double) con_genome.GetSize() - total_entropy;
-
+
cString con_name;
con_name.Set("genebank/%03d-consensus-u%i.gen", con_genome.GetSize(),update);
cTestUtil::PrintGenome(world, con_genome, con_name());
-
-
+
+
if (con_genotype) {
fp << update << " " // 1
- << con_genotype->GetMerit() << " " // 2
- << con_genotype->GetGestationTime() << " " // 3
- << con_genotype->GetFitness() << " " // 4
- << con_genotype->GetReproRate() << " " // 5
- << con_genotype->GetLength() << " " // 6
- << con_genotype->GetCopiedSize() << " " // 7
- << con_genotype->GetExecutedSize() << " " // 8
- << con_genotype->GetBirths() << " " // 9
- << con_genotype->GetBreedTrue() << " " // 10
- << con_genotype->GetBreedIn() << " " // 11
- << con_genotype->GetNumOrganisms() << " " // 12
- << con_genotype->GetDepth() << " " // 13
- << con_genotype->GetID() << " " // 14
- << update - con_genotype->GetUpdateBorn() << " " // 15
- << best_dist << " " // 16
- << ave_dist << " " // 17
- << var_dist << " " // 18
- << total_entropy << " " // 19
- << complexity_base << " " // 20
- << endl;
+ << con_genotype->GetMerit() << " " // 2
+ << con_genotype->GetGestationTime() << " " // 3
+ << con_genotype->GetFitness() << " " // 4
+ << con_genotype->GetReproRate() << " " // 5
+ << con_genotype->GetLength() << " " // 6
+ << con_genotype->GetCopiedSize() << " " // 7
+ << con_genotype->GetExecutedSize() << " " // 8
+ << con_genotype->GetBirths() << " " // 9
+ << con_genotype->GetBreedTrue() << " " // 10
+ << con_genotype->GetBreedIn() << " " // 11
+ << con_genotype->GetNumOrganisms() << " " // 12
+ << con_genotype->GetDepth() << " " // 13
+ << con_genotype->GetID() << " " // 14
+ << update - con_genotype->GetUpdateBorn() << " " // 15
+ << best_dist << " " // 16
+ << ave_dist << " " // 17
+ << var_dist << " " // 18
+ << total_entropy << " " // 19
+ << complexity_base << " " // 20
+ << endl;
}
else {
cCPUTestInfo test_info;
@@ -329,28 +320,28 @@
cPhenotype & colony_phenotype =
test_info.GetColonyOrganism()->GetPhenotype();
fp << update << " " // 1
- << colony_phenotype.GetMerit() << " " // 2
- << colony_phenotype.GetGestationTime() << " " // 3
- << colony_phenotype.GetFitness() << " " // 4
- << 1.0 / (0.1 + colony_phenotype.GetGestationTime()) << " " // 5
- << con_genome.GetSize() << " " // 6
- << colony_phenotype.GetCopiedSize() << " " // 7
- << colony_phenotype.GetExecutedSize() << " " // 8
- << 0 << " " // Births // 9
- << 0 << " " // Breed True // 10
- << 0 << " " // Breed In // 11
- << 0 << " " // Num CPUs // 12
- << -1 << " " // Depth // 13
- << -1 << " " // ID // 14
- << 0 << " " // Age // 15
- << best_dist << " " // 16
- << ave_dist << " " // 17
- << var_dist << " " // 18
- << total_entropy << " " // 19
- << complexity_base << " " // 20
- << endl;
+ << colony_phenotype.GetMerit() << " " // 2
+ << colony_phenotype.GetGestationTime() << " " // 3
+ << colony_phenotype.GetFitness() << " " // 4
+ << 1.0 / (0.1 + colony_phenotype.GetGestationTime()) << " " // 5
+ << con_genome.GetSize() << " " // 6
+ << colony_phenotype.GetCopiedSize() << " " // 7
+ << colony_phenotype.GetExecutedSize() << " " // 8
+ << 0 << " " // Births // 9
+ << 0 << " " // Breed True // 10
+ << 0 << " " // Breed In // 11
+ << 0 << " " // Num CPUs // 12
+ << -1 << " " // Depth // 13
+ << -1 << " " // ID // 14
+ << 0 << " " // Age // 15
+ << best_dist << " " // 16
+ << ave_dist << " " // 17
+ << var_dist << " " // 18
+ << total_entropy << " " // 19
+ << complexity_base << " " // 20
+ << endl;
}
-
+
// Flush the file...
fp.flush();
@@ -360,14 +351,14 @@
/**
- * This function goes through all creatures in the soup, and saves the
+* This function goes through all creatures in the soup, and saves the
* basic landscape data (neutrality, fitness, and so on) into a stream.
*
* @param fp The stream into which the data should be saved.
*
* @param sample_prob The probability with which a particular creature should
* be analyzed (a value of 1 analyzes all creatures, a value of 0.1 analyzes
- * 10%, and so on).
+ * 10%, and so on).
*
* @param landscape A bool that indicates whether the creatures should be
* landscaped (calc. neutrality and so on) or not.
@@ -376,36 +367,36 @@
* be saved or not.
**/
-void cAnalyzeUtil::AnalyzePopulation(cWorld* world, ofstream & fp,
- double sample_prob, bool landscape, bool save_genotype)
+void cAnalyzeUtil::AnalyzePopulation(cWorld* world, ofstream& fp,
+ double sample_prob, bool landscape, bool save_genotype)
{
cPopulation* pop = &world->GetPopulation();
fp << "# (1) cell number (2) genotype name (3) length (4) fitness [test-cpu] (5) fitness (actual) (6) merit (7) no of breed trues occurred (8) lineage label (9) neutral metric (10) -... landscape data" << endl;
-
+
const double skip_prob = 1.0 - sample_prob;
for (int i = 0; i < pop->GetSize(); i++) {
if (pop->GetCell(i).IsOccupied() == false) continue; // No organism...
if (world->GetRandom().P(skip_prob)) continue; // Not sampled...
-
+
cOrganism * organism = pop->GetCell(i).GetOrganism();
cGenotype * genotype = organism->GetGenotype();
const cGenome & genome = organism->GetGenome();
-
+
cString creature_name;
if ( genotype->GetThreshold() ) creature_name = genotype->GetName();
else creature_name.Set("%03d-no_name-u%i-c%i", genotype->GetLength(),
- world->GetStats().GetUpdate(), i );
-
+ world->GetStats().GetUpdate(), i );
+
fp << i << " " // 1 cell ID
- << creature_name() << " " // 2 name
- << genotype->GetLength() << " " // 3 length
- << genotype->GetTestFitness() << " " // 4 fitness (test-cpu)
- << organism->GetPhenotype().GetFitness() << " " // 5 fitness (actual)
- << organism->GetPhenotype().GetMerit() << " " // 6 merit
- << genotype->GetBreedTrue() << " " // 7 breed true?
- << organism->GetLineageLabel() << " " // 8 lineage label
- << organism->GetPhenotype().GetNeutralMetric() << " "; // 9 neut metric
-
+ << creature_name() << " " // 2 name
+ << genotype->GetLength() << " " // 3 length
+ << genotype->GetTestFitness() << " " // 4 fitness (test-cpu)
+ << organism->GetPhenotype().GetFitness() << " " // 5 fitness (actual)
+ << organism->GetPhenotype().GetMerit() << " " // 6 merit
+ << genotype->GetBreedTrue() << " " // 7 breed true?
+ << organism->GetLineageLabel() << " " // 8 lineage label
+ << organism->GetPhenotype().GetNeutralMetric() << " "; // 9 neut metric
+
// create landscape object for this creature
if (landscape && genotype->GetTestFitness() > 0) {
cLandscape landscape(world, genome, world->GetHardwareManager().GetInstSet());
@@ -423,7 +414,7 @@
/**
- * This function prints out fitness data. The main point is that it
+* This function prints out fitness data. The main point is that it
* calculates the average fitness from info from the testCPU + the actual
* merit of the organisms, and assigns zero fitness to those organisms
* that will never reproduce.
@@ -447,24 +438,24 @@
**/
void cAnalyzeUtil::PrintDetailedFitnessData(cWorld* world, cString& datafn,
- cString& hist_fn, cString& histo_testCPU_fn, bool save_max_f_genotype,
- bool print_fitness_histo, double hist_fmax, double hist_fstep)
+ cString& hist_fn, cString& histo_testCPU_fn, bool save_max_f_genotype,
+ bool print_fitness_histo, double hist_fmax, double hist_fstep)
{
cPopulation* pop = &world->GetPopulation();
const int update = world->GetStats().GetUpdate();
const double generation = world->GetStats().SumGeneration().Average();
-
+
// the histogram variables
vector<int> histo;
vector<int> histo_testCPU;
int bins;
-
+
if ( print_fitness_histo ){
bins = (int) (hist_fmax / hist_fstep) + 1;
histo.resize( bins, 0 ); // resize and clear
histo_testCPU.resize( bins, 0 );
}
-
+
int n = 0;
int nhist_tot = 0;
int nhist_tot_testCPU = 0;
@@ -472,13 +463,13 @@
double fave_testCPU = 0;
double max_fitness = -1; // we set this to -1, so that even 0 is larger...
cGenotype * max_f_genotype = NULL;
-
+
for (int i = 0; i < pop->GetSize(); i++) {
if (pop->GetCell(i).IsOccupied() == false) continue; // One use organisms.
-
+
cOrganism * organism = pop->GetCell(i).GetOrganism();
cGenotype * genotype = organism->GetGenotype();
-
+
cCPUTestInfo test_info;
world->GetTestCPU().TestGenome( test_info, genotype->GetGenome() );
// We calculate the fitness based on the current merit,
@@ -486,41 +477,41 @@
// to zero if the creature is not viable.
const double f = ( test_info.IsViable() ) ? organism->GetPhenotype().GetMerit().CalcFitness(test_info.GetTestOrganism()->GetPhenotype().GetGestationTime()) : 0;
const double f_testCPU = test_info.GetColonyFitness();
-
+
// Get the maximum fitness in the population
// Here, we want to count only organisms that can truly replicate,
// to avoid complications
if ( f_testCPU > max_fitness &&
- test_info.GetTestOrganism()->GetPhenotype().CopyTrue() ){
+ test_info.GetTestOrganism()->GetPhenotype().CopyTrue() ){
max_fitness = f_testCPU;
max_f_genotype = genotype;
}
-
+
fave += f;
fave_testCPU += f_testCPU;
n += 1;
-
-
+
+
// histogram
if ( print_fitness_histo && f < hist_fmax ){
histo[(int) (f / hist_fstep)] += 1;
nhist_tot += 1;
}
-
+
if ( print_fitness_histo && f_testCPU < hist_fmax ){
histo_testCPU[(int) (f_testCPU / hist_fstep)] += 1;
nhist_tot_testCPU += 1;
}
}
-
+
// determine the name of the maximum fitness genotype
cString max_f_name;
if ( max_f_genotype->GetThreshold() )
max_f_name = max_f_genotype->GetName();
else // we put the current update into the name, so that it becomes unique.
- max_f_name.Set("%03d-no_name-u%i", max_f_genotype->GetLength(),
- update );
-
+ max_f_name.Set("%03d-no_name-u%i", max_f_genotype->GetLength(),
+ update );
+
world->GetDataFileOFStream(datafn)
<< update << " " // 1 update
<< generation << " " // 2 generation
@@ -530,31 +521,31 @@
<< max_fitness << " " // 6 maximum fitness
<< max_f_name() << " " // 7 maxfit genotype name
<< endl;
-
+
if (save_max_f_genotype) {
char filename[40];
sprintf( filename, "genebank/%s", max_f_name() );
cTestUtil::PrintGenome(world, max_f_genotype->GetGenome(), filename);
}
-
+
if (print_fitness_histo) {
ofstream& hist_fp = world->GetDataFileOFStream(hist_fn);
hist_fp
<< update << " " // 1 update
<< generation << " " // 2 generation
<< fave/ (double) n << " "; // 3 average fitness
-
+
// now output the fitness histo
vector<int>::const_iterator it = histo.begin();
for ( ; it != histo.end(); it++ ) hist_fp << (double) (*it) / (double) nhist_tot << " ";
hist_fp << endl;
-
+
ofstream& histo_testCPU_fp = world->GetDataFileOFStream(histo_testCPU_fn);
histo_testCPU_fp
<< update << " " // 1 update
<< generation << " " // 2 generation
<< fave_testCPU/ (double) n << " "; // 3 average fitness
-
+
// now output the fitness histo
it = histo_testCPU.begin();
for (; it != histo_testCPU.end(); it++) histo_testCPU_fp << (double) (*it) / (double) nhist_tot_testCPU << " ";
@@ -564,7 +555,7 @@
/**
- * This function goes through all genotypes currently present in the soup,
+* This function goes through all genotypes currently present in the soup,
* and writes into an output file the average Hamming distance between the
* creatures in the population and a given reference genome.
*
@@ -574,18 +565,18 @@
* saved into the genebank or not.
**/
-void cAnalyzeUtil::PrintGeneticDistanceData(cWorld* world, ofstream & fp,
- const char * creature_name)
+void cAnalyzeUtil::PrintGeneticDistanceData(cWorld* world, ofstream& fp,
+ const char * creature_name)
{
cPopulation* pop = &world->GetPopulation();
double hamming_m1 = 0;
double hamming_m2 = 0;
int count = 0;
int dom_dist = 0;
-
+
// load the reference genome
cGenome reference_genome(cInstUtil::LoadGenome(creature_name, world->GetHardwareManager().GetInstSet()));
-
+
// get the info for the dominant genotype
cGenotype * cur_genotype = pop->GetGenebank().GetBestGenotype();
cGenome genome = cur_genotype->GetGenome();
@@ -597,28 +588,28 @@
for (int i = 1; i < pop->GetGenebank().GetSize(); i++) {
cur_genotype = cur_genotype->GetNext();
cGenome genome = cur_genotype->GetGenome();
-
+
int dist = cGenomeUtil::FindHammingDistance( reference_genome, genome );
hamming_m1 += dist;
hamming_m2 += dist*dist;
count += cur_genotype->GetNumOrganisms();
}
-
+
hamming_m1 /= (double) count;
hamming_m2 /= (double) count;
-
+
fp << world->GetStats().GetUpdate() << " " // 1 update
- << hamming_m1 << " " // ave. Hamming dist
- << sqrt( ( hamming_m2 - hamming_m1*hamming_m1 ) / (double) count )
- << " " // std. error
- << cGenomeUtil::FindHammingDistance( reference_genome,
- pop->GetGenebank().GetBestGenotype()->GetGenome() ) << " "
- << endl;
+ << hamming_m1 << " " // ave. Hamming dist
+ << sqrt( ( hamming_m2 - hamming_m1*hamming_m1 ) / (double) count )
+ << " " // std. error
+ << cGenomeUtil::FindHammingDistance( reference_genome,
+ pop->GetGenebank().GetBestGenotype()->GetGenome() ) << " "
+ << endl;
}
/**
- * This function goes through all genotypes currently present in the soup,
+* 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.
@@ -629,56 +620,56 @@
* saved into the genebank or not.
**/
-void cAnalyzeUtil::GeneticDistancePopDump(cWorld* world, ofstream & fp,
- const char * creature_name, bool save_creatures)
+void cAnalyzeUtil::GeneticDistancePopDump(cWorld* world, ofstream& fp,
+ const char * creature_name, bool save_creatures)
{
cPopulation* pop = &world->GetPopulation();
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 = pop->GetGenebank().GetBestGenotype();
for (int i = 0; i < pop->GetGenebank().GetSize(); 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;
-
+ << 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 genebank
if (save_creatures) {
char filename[40];
sprintf( filename, "genebank/%s", 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;
+ << sum_fitness/sum_num_organisms << endl;
}
/**
- * This function goes through all creatures in the soup, and writes out
+* 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
* will increase its count only by one.
@@ -686,21 +677,21 @@
* @param fp The file into which the result should be written.
**/
-void cAnalyzeUtil::TaskSnapshot(cWorld* world, ofstream & fp)
+void cAnalyzeUtil::TaskSnapshot(cWorld* world, ofstream& fp)
{
cPopulation* pop = &world->GetPopulation();
fp << "# (1) cell number\n# (2) number of rewarded tasks done so far\n# (3) total number of tasks done so far\n# (4) same as 2, but right before divide\n# (5) same as 3, but right before divide\n# (6) same as 2, but for parent\n# (7) same as 3, but for parent\n# (8) genotype fitness\n# (9) genotype name" << endl;
-
+
for (int i = 0; i < pop->GetSize(); i++) {
if (pop->GetCell(i).IsOccupied() == false) continue;
cOrganism * organism = pop->GetCell(i).GetOrganism();
-
+
// create a test-cpu for the current creature
cCPUTestInfo test_info;
world->GetTestCPU().TestGenome( test_info, organism->GetGenome() );
cPhenotype & test_phenotype = test_info.GetTestOrganism()->GetPhenotype();
cPhenotype & phenotype = organism->GetPhenotype();
-
+
int num_tasks = world->GetEnvironment().GetTaskLib().GetSize();
int sum_tasks_all = 0;
int sum_tasks_rewarded = 0;
@@ -708,39 +699,39 @@
int divide_sum_tasks_rewarded = 0;
int parent_sum_tasks_all = 0;
int parent_sum_tasks_rewarded = 0;
-
+
for (int j = 0; j < num_tasks; j++) {
// get the number of bonuses for this task
int bonuses = 1; //phenotype.GetTaskLib().GetTaskNumBonus(j);
int task_count = ( phenotype.GetCurTaskCount()[j] == 0 ) ? 0 : 1;
int divide_tasks_count = (test_phenotype.GetLastTaskCount()[j] == 0)?0:1;
int parent_task_count = (phenotype.GetLastTaskCount()[j] == 0) ? 0 : 1;
-
+
// If only one bonus, this task is not rewarded, as last bonus is + 0.
if (bonuses > 1) {
- sum_tasks_rewarded += task_count;
- divide_sum_tasks_rewarded += divide_tasks_count;
- parent_sum_tasks_rewarded += parent_task_count;
+ sum_tasks_rewarded += task_count;
+ divide_sum_tasks_rewarded += divide_tasks_count;
+ parent_sum_tasks_rewarded += parent_task_count;
}
sum_tasks_all += task_count;
divide_sum_tasks_all += divide_tasks_count;
parent_sum_tasks_all += parent_task_count;
}
-
+
fp << i << " " // 1 cell number
- << sum_tasks_rewarded << " " // 2 number of tasks rewarded
- << sum_tasks_all << " " // 3 total number of tasks done
- << divide_sum_tasks_rewarded << " " // 4 num rewarded tasks on divide
- << divide_sum_tasks_all << " " // 5 num total tasks on divide
- << parent_sum_tasks_rewarded << " " // 6 parent number of tasks rewared
- << parent_sum_tasks_all << " " // 7 parent total num tasks done
- << test_info.GetColonyFitness() << " " // 8 genotype fitness
- << organism->GetGenotype()->GetName()() << " " // 9 genotype name
- << endl;
+ << sum_tasks_rewarded << " " // 2 number of tasks rewarded
+ << sum_tasks_all << " " // 3 total number of tasks done
+ << divide_sum_tasks_rewarded << " " // 4 num rewarded tasks on divide
+ << divide_sum_tasks_all << " " // 5 num total tasks on divide
+ << parent_sum_tasks_rewarded << " " // 6 parent number of tasks rewared
+ << parent_sum_tasks_all << " " // 7 parent total num tasks done
+ << test_info.GetColonyFitness() << " " // 8 genotype fitness
+ << organism->GetGenotype()->GetName()() << " " // 9 genotype name
+ << endl;
}
}
-void cAnalyzeUtil::TaskGrid(cWorld* world, ofstream & fp)
+void cAnalyzeUtil::TaskGrid(cWorld* world, ofstream& fp)
{
cPopulation* pop = &world->GetPopulation();
for (int i = 0; i < pop->GetWorldX(); i++) {
@@ -755,7 +746,7 @@
int num_tasks = world->GetEnvironment().GetTaskLib().GetSize();
for (int k = 0; k < num_tasks; k++) {
if (test_phenotype.GetLastTaskCount()[k]>0) {
- task_sum = task_sum + (int) pow(2.0,k);
+ task_sum = task_sum + (int) pow(2.0,k);
}
}
}
@@ -766,64 +757,64 @@
}
/**
- * This function prints all the tasks that viable creatures have performed
+* This function prints all the tasks that viable creatures have performed
* so far (compare with the event 'print_task_data', which prints all tasks.
- **/
+ **/
-void cAnalyzeUtil::PrintViableTasksData(cWorld* world, ofstream & fp)
+void cAnalyzeUtil::PrintViableTasksData(cWorld* world, ofstream& fp)
{
const int num_tasks = world->GetNumTasks();
cPopulation* pop = &world->GetPopulation();
-
+
static vector<int> tasks(num_tasks);
vector<int>::iterator it;
-
+
// clear task vector
for (it = tasks.begin(); it != tasks.end(); it++) (*it) = 0;
-
+
for (int i = 0; i < pop->GetSize(); i++) {
if (pop->GetCell(i).IsOccupied() == false) continue;
if (pop->GetCell(i).GetOrganism()->GetGenotype()->GetTestFitness() > 0.0) {
cPhenotype & phenotype = pop->GetCell(i).GetOrganism()->GetPhenotype();
for (int j = 0; j < num_tasks; j++) {
- if (phenotype.GetCurTaskCount()[j] > 0) tasks[j] += 1;
+ if (phenotype.GetCurTaskCount()[j] > 0) tasks[j] += 1;
}
}
}
-
+
fp << world->GetStats().GetUpdate();
for (it = tasks.begin(); it != tasks.end(); it++) fp << " " << (*it);
fp<<endl;
}
-void cAnalyzeUtil::PrintTreeDepths(cPopulation * pop, ofstream & fp)
+void cAnalyzeUtil::PrintTreeDepths(cPopulation * pop, ofstream& fp)
{
// cycle over all genotypes
cGenotype * genotype = pop->GetGenebank().GetBestGenotype();
for (int i = 0; i < pop->GetGenebank().GetSize(); i++) {
fp << genotype->GetID() << " " // 1
- << genotype->GetTestFitness() << " " // 2
- << genotype->GetNumOrganisms() << " " // 3
- << genotype->GetDepth() << " " // 4
- << endl;
-
+ << genotype->GetTestFitness() << " " // 2
+ << genotype->GetNumOrganisms() << " " // 3
+ << genotype->GetDepth() << " " // 4
+ << endl;
+
// ...and advance to the next genotype...
genotype = genotype->GetNext();
}
}
-void cAnalyzeUtil::PrintDepthHistogram(cWorld* world, ofstream & fp)
+void cAnalyzeUtil::PrintDepthHistogram(cWorld* world, ofstream& fp)
{
cPopulation* pop = &world->GetPopulation();
// Output format: update min max histogram_values...
int min = INT_MAX;
int max = 0;
assert(fp.good());
-
+
// Two pass method
-
+
// Loop through all genotypes getting min and max values
cGenebank & genebank = pop->GetGenebank();
cGenotype * cur_genotype = genebank.GetBestGenotype();
@@ -833,23 +824,23 @@
cur_genotype = cur_genotype->GetNext();
}
assert(max >= min);
-
+
// Allocate the array for the bins (& zero)
int * n = new int[max - min + 1];
for (int i = 0; i < max - min + 1; i++) n[i] = 0;
-
+
// Loop through all genotypes binning the values
cur_genotype = genebank.GetBestGenotype();
for (int i = 0; i < genebank.GetSize(); i++) {
n[cur_genotype->GetDepth() - min] += cur_genotype->GetNumOrganisms();
cur_genotype = cur_genotype->GetNext();
}
-
+
// Actual output
fp << world->GetStats().GetUpdate() << " "
- << min << " "
- << max;
-
+ << min << " "
+ << max;
+
for (int i = 0; i < max - min + 1; i++) fp << " " << n[i];
fp<<endl;
}
@@ -859,11 +850,11 @@
{
cPopulation* pop = &world->GetPopulation();
assert(fp.good());
-
+
// Allocate array for the histogram & zero it
tArray <int> hist(pop->GetGenebank().GetBestGenotype()->GetNumOrganisms());
for (int i = 0; i < hist.GetSize(); i++) hist[i] = 0;
-
+
// Loop through all genotypes binning the values
cGenotype * cur_genotype = pop->GetGenebank().GetBestGenotype();
for (int i = 0; i < pop->GetGenebank().GetSize(); i++) {
@@ -872,7 +863,7 @@
hist[cur_genotype->GetNumOrganisms() - 1]++;
cur_genotype = cur_genotype->GetNext();
}
-
+
// Actual output
fp << world->GetStats().GetUpdate() << " ";
for (int i = 0; i < hist.GetSize(); i++) fp<<hist[i]<<" ";
@@ -880,12 +871,12 @@
}
-void cAnalyzeUtil::PrintSpeciesAbundanceHistogram(cWorld* world, ofstream &fp)
+void cAnalyzeUtil::PrintSpeciesAbundanceHistogram(cWorld* world, ofstream& fp)
{
cPopulation* pop = &world->GetPopulation();
int max = 0;
assert(fp.good());
-
+
// Find max species abundance...
cGenebank & genebank = pop->GetGenebank();
cSpecies * cur_species = genebank.GetFirstSpecies();
@@ -895,11 +886,11 @@
}
cur_species = cur_species->GetNext();
}
-
+
// Allocate array for the histogram & zero it
tArray <int> hist(max);
for (int i = 0; i < hist.GetSize(); i++) hist[i] = 0;
-
+
// Loop through all species binning the values
cur_species = genebank.GetFirstSpecies();
for (int i = 0; i < genebank.GetNumSpecies(); i++) {
@@ -908,7 +899,7 @@
hist[cur_species->GetNumOrganisms() -1]++;
cur_species = cur_species->GetNext();
}
-
+
// Actual output
fp << world->GetStats().GetUpdate() << " ";
for (int i = 0; i < hist.GetSize(); i++) fp<<hist[i]<<" ";
@@ -918,10 +909,10 @@
// this adds support for evan dorn's InstructionHistogramEvent. -- kgn
/**
- * Count the number of each instruction present in the population. Output
+* Count the number of each instruction present in the population. Output
* this info to a log file
**/
-void cAnalyzeUtil::PrintInstructionAbundanceHistogram(cWorld* world, ofstream & fp)
+void cAnalyzeUtil::PrintInstructionAbundanceHistogram(cWorld* world, ofstream& fp)
{
cPopulation* pop = &world->GetPopulation();
int i,x,y;
@@ -930,36 +921,36 @@
int * inst_counts;
cCPUMemory cpu_mem; // cCPUMemory is a subclass of cGenome
assert(fp.good());
-
+
// ----- number of instructions available?
num_inst = world->GetNumInstructions();
inst_counts= new int[num_inst];
-
+
// ----- create and initialize counting array
inst_counts = new int[num_inst];
for (i=0;i<num_inst;i++)
- { inst_counts[i]=0;
- }
+ { inst_counts[i]=0;
+ }
int num_cells = pop->GetSize();
//looping through all CPUs counting up instructions
for( x=0; x<num_cells; x++ )
- { cPopulationCell & cell=pop->GetCell(x);
- if (cell.IsOccupied())
- {
+ { cPopulationCell & cell=pop->GetCell(x);
+ if (cell.IsOccupied())
+ {
// access this CPU's code block
- cpu_mem=cell.GetOrganism()->GetHardware().GetMemory();
- mem_size=cpu_mem.GetSize();
- for (y=0; y<mem_size ; y++)
- { inst_counts[(cpu_mem[y]).GetOp()]++;
- }
- }
+ cpu_mem=cell.GetOrganism()->GetHardware().GetMemory();
+ mem_size=cpu_mem.GetSize();
+ for (y=0; y<mem_size ; y++)
+ { inst_counts[(cpu_mem[y]).GetOp()]++;
+ }
}
+ }
// ----- output instruction counts
for(i=0; i<num_inst; i++)
- { fp<<inst_counts[i]<<" ";
- }
+ { fp<<inst_counts[i]<<" ";
+ }
fp<<endl;
}
Modified: development/source/analyze/cAnalyzeUtil.h
===================================================================
--- development/source/analyze/cAnalyzeUtil.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/analyze/cAnalyzeUtil.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -24,9 +24,9 @@
public:
// Generic test-CPU analysis
static void TestGenome(cWorld* world, const cGenome & genome, cInstSet & inst_set,
- std::ofstream & fp, int update);
+ std::ofstream& fp, int update);
- static void TestInsSizeChangeRobustness(cWorld* world, std::ofstream & fp,
+ static void TestInsSizeChangeRobustness(cWorld* world, std::ofstream& fp,
const cInstSet & inst_set, const cGenome & in_genome,
int num_trials, int update);
@@ -44,7 +44,7 @@
// Population-wide analysis
static void CalcConsensus(cWorld* world, int lines_saved);
- static void AnalyzePopulation(cWorld* world, std::ofstream & fp,
+ static void AnalyzePopulation(cWorld* world, std::ofstream& fp,
double sample_prob=1, bool landscape=false,
bool save_genotype=false);
@@ -52,22 +52,22 @@
cString& histofn, cString& histo_testCPU_fn, bool save_max_f_genotype,
bool print_fitness_histo, double hist_fmax, double hist_fstep);
- static void PrintGeneticDistanceData(cWorld* world, std::ofstream & fp,
+ static void PrintGeneticDistanceData(cWorld* world, std::ofstream& fp,
const char *creature_name );
- static void GeneticDistancePopDump(cWorld* world, std::ofstream & fp,
+ 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);
- static void PrintTreeDepths(cPopulation * pop, std::ofstream & fp);
+ static void TaskSnapshot(cWorld* world, std::ofstream& fp);
+ static void TaskGrid(cWorld* world, std::ofstream& fp);
+ static void PrintViableTasksData(cWorld* world, std::ofstream& fp);
+ static void PrintTreeDepths(cPopulation * pop, std::ofstream& fp);
static void PrintDepthHistogram(cWorld* world, std::ofstream& fp);
static void PrintGenotypeAbundanceHistogram(cWorld* world, std::ofstream& fp);
static void PrintSpeciesAbundanceHistogram(cWorld* world, std::ofstream& fp);
// this adds support for evan dorn's InstructionHistogramEvent. -- kgn
- static void PrintInstructionAbundanceHistogram(cWorld* world, std::ofstream &fp);
+ static void PrintInstructionAbundanceHistogram(cWorld* world, std::ofstream& fp);
// -- kgn
};
#endif
Modified: development/source/cpu/cCPUStack.cc
===================================================================
--- development/source/cpu/cCPUStack.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cCPUStack.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -52,7 +52,7 @@
return true;
}
-void cCPUStack::SaveState(ostream & fp)
+void cCPUStack::SaveState(ostream& fp)
{
assert(fp.good());
fp<<"cCPUStack"<<" ";
Modified: development/source/cpu/cCPUStack.h
===================================================================
--- development/source/cpu/cCPUStack.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cCPUStack.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -40,7 +40,7 @@
bool OK();
- void SaveState(std::ostream & fp);
+ void SaveState(std::ostream& fp);
void LoadState(std::istream & fp);
};
Modified: development/source/cpu/cCodeLabel.cc
===================================================================
--- development/source/cpu/cCodeLabel.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cCodeLabel.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -74,7 +74,7 @@
return -1;
}
-void cCodeLabel::SaveState(ostream & fp)
+void cCodeLabel::SaveState(ostream& fp)
{
// assert(fp.good());
// fp<<"cCodeLabel"<<" ";
Modified: development/source/cpu/cCodeLabel.h
===================================================================
--- development/source/cpu/cCodeLabel.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cCodeLabel.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -60,7 +60,7 @@
int AsIntFib(const int base) const;
int AsIntPolynomialCoefficent(const int base) const;
- void SaveState(std::ostream & fp);
+ void SaveState(std::ostream& fp);
void LoadState(std::istream & fp);
};
Modified: development/source/cpu/cHardware4Stack.cc
===================================================================
--- development/source/cpu/cHardware4Stack.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardware4Stack.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -492,7 +492,7 @@
return result;
}
-void cHardware4Stack::PrintStatus(ostream & fp)
+void cHardware4Stack::PrintStatus(ostream& fp)
{
fp << organism->GetPhenotype().GetTimeUsed() << " "
<< "IP:(" << IP().GetMemSpace() << ", " << IP().GetPosition() << ") "
@@ -1251,7 +1251,7 @@
}
-void cHardware4Stack::SaveState(ostream & fp)
+void cHardware4Stack::SaveState(ostream& fp)
{
// note, memory & child_memory handled by cpu (@CAO Not any more!)
assert(fp.good());
Modified: development/source/cpu/cHardware4Stack.h
===================================================================
--- development/source/cpu/cHardware4Stack.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardware4Stack.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -123,7 +123,7 @@
// -------- Helper methods --------
bool OK();
- void PrintStatus(std::ostream & fp);
+ void PrintStatus(std::ostream& fp);
// -------- Flag Accessors --------
@@ -253,7 +253,7 @@
void ReadInst(const int in_inst);
- void SaveState(std::ostream & fp);
+ void SaveState(std::ostream& fp);
void LoadState(std::istream & fp);
//void InitInstSet(const cString & filename, cInstSet & inst_set);
Modified: development/source/cpu/cHardware4Stack_Thread.cc
===================================================================
--- development/source/cpu/cHardware4Stack_Thread.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardware4Stack_Thread.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -60,7 +60,7 @@
owner = NULL;
}
-void cHardware4Stack_Thread::SaveState(ostream & fp){
+void cHardware4Stack_Thread::SaveState(ostream& fp){
assert(fp.good());
fp << "cHardware4Stack_Thread" << endl;
Modified: development/source/cpu/cHardware4Stack_Thread.h
===================================================================
--- development/source/cpu/cHardware4Stack_Thread.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardware4Stack_Thread.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -64,7 +64,7 @@
int GetID() const { return id; }
void SetID(int _id) { id = _id; }
- void SaveState(std::ostream & fp);
+ void SaveState(std::ostream& fp);
void LoadState(std::istream & fp);
};
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardwareBase.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -70,8 +70,8 @@
const cGenome & injection) = 0;
// -------- Input and Output --------
- virtual void PrintStatus(std::ostream & fp) = 0;
- virtual void SaveState(std::ostream & fp) = 0;
+ virtual void PrintStatus(std::ostream& fp) = 0;
+ virtual void SaveState(std::ostream& fp) = 0;
virtual void LoadState(std::istream & fp) = 0;
void SetTrace(cHardwareTracer * tracer) { m_tracer = tracer; }
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardwareCPU.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -605,7 +605,7 @@
return result;
}
-void cHardwareCPU::PrintStatus(ostream & fp)
+void cHardwareCPU::PrintStatus(ostream& fp)
{
fp << organism->GetPhenotype().GetTimeUsed() << " "
<< "IP:" << IP().GetPosition() << " "
@@ -1321,7 +1321,7 @@
}
-void cHardwareCPU::SaveState(ostream & fp)
+void cHardwareCPU::SaveState(ostream& fp)
{
// note, memory & child_memory handled by cpu (@CAO Not any more!)
assert(fp.good());
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardwareCPU.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -123,7 +123,7 @@
// -------- Helper methods --------
bool OK();
- void PrintStatus(std::ostream & fp);
+ void PrintStatus(std::ostream& fp);
// -------- Flag Accessors --------
@@ -234,7 +234,7 @@
void ReadInst(const int in_inst);
- void SaveState(std::ostream & fp);
+ void SaveState(std::ostream& fp);
void LoadState(std::istream & fp);
//void InitInstSet(const cString & filename, cInstSet & inst_set);
Modified: development/source/cpu/cHardwareCPU_Thread.cc
===================================================================
--- development/source/cpu/cHardwareCPU_Thread.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardwareCPU_Thread.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -64,7 +64,7 @@
-void cHardwareCPU_Thread::SaveState(ostream & fp){
+void cHardwareCPU_Thread::SaveState(ostream& fp){
assert(fp.good());
fp << "cHardwareCPU_Thread" << endl;
Modified: development/source/cpu/cHardwareCPU_Thread.h
===================================================================
--- development/source/cpu/cHardwareCPU_Thread.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardwareCPU_Thread.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -64,7 +64,7 @@
int GetID() const { return id; }
void SetID(int _id) { id = _id; }
- void SaveState(std::ostream & fp);
+ void SaveState(std::ostream& fp);
void LoadState(std::istream & fp);
};
Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardwareSMT.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -325,7 +325,7 @@
return true;
}
-void cHardwareSMT::PrintStatus(ostream & fp)
+void cHardwareSMT::PrintStatus(ostream& fp)
{
fp << organism->GetPhenotype().GetTimeUsed() << " "
<< "IP:(" << IP().GetMemSpace() << ", " << IP().GetPosition() << ") "
@@ -1073,7 +1073,7 @@
}
-void cHardwareSMT::SaveState(ostream & fp)
+void cHardwareSMT::SaveState(ostream& fp)
{
// note, memory & child_memory handled by cpu (@CAO Not any more!)
assert(fp.good());
Modified: development/source/cpu/cHardwareSMT.h
===================================================================
--- development/source/cpu/cHardwareSMT.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardwareSMT.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -110,7 +110,7 @@
// -------- Helper methods --------
bool OK();
- void PrintStatus(std::ostream & fp);
+ void PrintStatus(std::ostream& fp);
// -------- Stack Manipulation... --------
@@ -232,7 +232,7 @@
void ReadInst(const int in_inst);
- void SaveState(std::ostream & fp);
+ void SaveState(std::ostream& fp);
void LoadState(std::istream & fp);
private:
Modified: development/source/cpu/cHardwareSMT_Thread.cc
===================================================================
--- development/source/cpu/cHardwareSMT_Thread.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardwareSMT_Thread.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -60,7 +60,7 @@
owner = NULL;
}
-void cHardwareSMT_Thread::SaveState(ostream & fp){
+void cHardwareSMT_Thread::SaveState(ostream& fp){
assert(fp.good());
fp << "cHardwareSMT_Thread" << endl;
Modified: development/source/cpu/cHardwareSMT_Thread.h
===================================================================
--- development/source/cpu/cHardwareSMT_Thread.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardwareSMT_Thread.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -66,7 +66,7 @@
int GetID() const { return id; }
void SetID(int _id) { id = _id; }
- void SaveState(std::ostream & fp);
+ void SaveState(std::ostream& fp);
void LoadState(std::istream & fp);
};
Modified: development/source/cpu/cHardwareStatusPrinter.h
===================================================================
--- development/source/cpu/cHardwareStatusPrinter.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cHardwareStatusPrinter.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -43,7 +43,7 @@
public cHardwareTracer_TestCPU
{
protected:
- ostream &m_trace_fp;
+ ostream& m_trace_fp;
protected:
const cString & GetNextInstName(cHardwareCPU& hardware);
const cString & GetNextInstName(cHardware4Stack& hardware);
Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cTestCPU.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -143,7 +143,7 @@
}
bool cTestCPU::TestGenome(cCPUTestInfo & test_info, const cGenome & genome,
- ofstream & out_fp)
+ ofstream& out_fp)
{
test_info.Clear();
TestGenome_Body(test_info, genome, 0);
@@ -262,13 +262,9 @@
void cTestCPU::TestThreads(const cGenome & genome)
{
- static ofstream fp("threads.dat");
-
cCPUTestInfo test_info;
test_info.TestThreads();
cTestCPU::TestGenome(test_info, genome);
-
- fp << endl;
}
Modified: development/source/cpu/cTestCPU.h
===================================================================
--- development/source/cpu/cTestCPU.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cTestCPU.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -51,7 +51,7 @@
~cTestCPU() { ; }
bool TestGenome(cCPUTestInfo & test_info, const cGenome & genome);
- bool TestGenome(cCPUTestInfo & test_info, const cGenome & genome, std::ofstream & out_fp);
+ bool TestGenome(cCPUTestInfo & test_info, const cGenome & genome, std::ofstream& out_fp);
void TestThreads(const cGenome & genome);
void PrintThreads(const cGenome & genome);
Modified: development/source/cpu/cTestUtil.cc
===================================================================
--- development/source/cpu/cTestUtil.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/cpu/cTestUtil.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -8,6 +8,7 @@
#include "cTestUtil.h"
#include "cCPUTestInfo.h"
+#include "cDataFileManager.h"
#include "cEnvironment.h"
#include "cGenome.h"
#include "cGenotype.h"
@@ -39,13 +40,11 @@
world->GetTestCPU().TestGenome(test_info, genome);
// Open the file...
+ ofstream& fp = world->GetDataFileOFStream(filename);
- ofstream fp(filename());
-
// @CAO Fix!!!!!!
if( fp.good() == false ) {
- cerr << "Unable to open output file '" << filename() << "'" <<
- endl;
+ cerr << "Unable to open output file '" << filename() << "'" << endl;
return;
}
@@ -53,12 +52,10 @@
fp << "# Filename........: " << filename << endl;
- if (update_out >= 0) fp << "# Update Output...: " << update_out <<
- endl;
+ if (update_out >= 0) fp << "# Update Output...: " << update_out << endl;
else fp << "# Update Output...: N/A" << endl;
- fp << "# Is Viable.......: " << test_info.IsViable()
- << endl
+ fp << "# Is Viable.......: " << test_info.IsViable() << endl
<< "# Repro Cycle Size: " << test_info.GetMaxCycle()
<< endl
<< "# Depth to Viable.: " << test_info.GetDepthFound()
@@ -128,6 +125,8 @@
const cInstSet & inst_set =
test_info.GetTestOrganism()->GetHardware().GetInstSet();
cInstUtil::SaveGenome(fp, inst_set, genome);
+
+ world->GetDataFileManager().Remove(filename);
}
void cTestUtil::PrintGenome(cWorld* world, cInjectGenotype * inject_genotype,
@@ -141,9 +140,8 @@
world->GetTestCPU().TestGenome(test_info, genome);
// Open the file...
+ ofstream& fp = world->GetDataFileOFStream(filename);
- ofstream fp(filename());
-
// @CAO Fix!!!!!!
if( fp.good() == false ) {
cerr << "Unable to open output file '" << filename() << "'" <<
@@ -230,4 +228,6 @@
const cInstSet & inst_set =
test_info.GetTestOrganism()->GetHardware().GetInstSet();
cInstUtil::SaveGenome(fp, inst_set, genome);
+
+ world->GetDataFileManager().Remove(filename);
}
Modified: development/source/event/cEventList.cc
===================================================================
--- development/source/event/cEventList.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/event/cEventList.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -225,7 +225,7 @@
}
-void cEventList::PrintEventList( ostream & os ){
+void cEventList::PrintEventList( ostream& os ){
cEventListEntry * entry = m_head;
cEventListEntry * next_entry;
while( entry != NULL ){
@@ -235,7 +235,7 @@
}
}
-void cEventList::PrintEvent(cEventListEntry * entry, ostream & os){
+void cEventList::PrintEvent(cEventListEntry * entry, ostream& os){
assert( entry != NULL );
switch ( entry->GetTrigger() ){
case cEventTriggers::UPDATE:
Modified: development/source/event/cEventList.h
===================================================================
--- development/source/event/cEventList.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/event/cEventList.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -137,11 +137,11 @@
**/
void SyncEvent(cEventListEntry *event);
- void PrintEventList(std::ostream & os = std::cout);
+ void PrintEventList(std::ostream& os = std::cout);
// kaben changed this member function to static for easy access by
// cEventListIterator.
- static void PrintEvent(cEventListEntry * event, std::ostream & os = std::cout);
+ static void PrintEvent(cEventListEntry * event, std::ostream& os = std::cout);
};
#endif
Modified: development/source/event/cEventListIterator.cc
===================================================================
--- development/source/event/cEventListIterator.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/event/cEventListIterator.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -21,7 +21,7 @@
/////////////////
void
-cEventListIterator::PrintEvent(ostream & os){
+cEventListIterator::PrintEvent(ostream& os){
cEventList::PrintEvent(m_node, os);
}
Modified: development/source/event/cEventListIterator.h
===================================================================
--- development/source/event/cEventListIterator.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/event/cEventListIterator.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -31,7 +31,7 @@
cEventListIterator(cEventListEntry *node) : m_node(node) {}
cEventListIterator(const cEventListIterator &it) : m_node(it.m_node) {}
- void PrintEvent(std::ostream & os = std::cout);
+ void PrintEvent(std::ostream& os = std::cout);
bool operator==(const cEventListIterator &it) const {
return m_node == it.m_node;
Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/event/cEventManager.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -752,7 +752,7 @@
}
///// print_instruction_abundance_histogram /////
void Process(){
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
cAnalyzeUtil::PrintInstructionAbundanceHistogram(m_world, fp);
}
};
@@ -779,7 +779,7 @@
}
///// print_depth_histogram /////
void Process(){
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
cAnalyzeUtil::PrintDepthHistogram(m_world, fp);
}
};
@@ -811,7 +811,7 @@
}
///// print_genotype_abundance_histogram /////
void Process(){
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
cAnalyzeUtil::PrintGenotypeAbundanceHistogram(m_world, fp);
}
};
@@ -843,7 +843,7 @@
}
///// print_species_abundance_histogram /////
void Process(){
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
cAnalyzeUtil::PrintSpeciesAbundanceHistogram(m_world, fp);
}
};
@@ -872,13 +872,8 @@
}
///// print_lineage_totals /////
void Process(){
- static bool msg_printed = false;
if (m_world->GetPopulation().GetLineageControl() == NULL) {
- if ( msg_printed == false ){
- ofstream & fp = m_world->GetDataFileOFStream(fname);
- fp << "No lineage data available!" << endl;
- msg_printed = true;
- }
+ m_world->GetDataFileOFStream(fname) << "No lineage data available!" << endl;
return;
}
m_world->GetPopulation().GetLineageControl()->PrintLineageTotals(fname, verbose);
@@ -909,13 +904,8 @@
}
///// print_lineage_counts /////
void Process(){
- static bool msg_printed = false;
if (m_world->GetPopulation().GetLineageControl() == NULL) {
- if ( msg_printed == false ){
- ofstream & fp = m_world->GetDataFileOFStream(fname);
- fp << "No lineage data available!" << endl;
- msg_printed = true;
- }
+ m_world->GetDataFileOFStream(fname) << "No lineage data available!" << endl;
return;
}
if (verbose) { // verbose mode is the same in both methods
@@ -1143,8 +1133,8 @@
if( fname == "" ){
filename.Set("save_pop.%d", m_world->GetStats().GetUpdate());
}
- ofstream fp(filename());
- m_world->GetPopulation().SavePopulation(fp);
+ m_world->GetPopulation().SavePopulation(m_world->GetDataFileOFStream(filename));
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -1206,8 +1196,8 @@
if( fname == "" ){
filename.Set("clone.%d", m_world->GetStats().GetUpdate());
}
- ofstream fp(filename());
- m_world->GetPopulation().SaveClone(fp);
+ m_world->GetPopulation().SaveClone(m_world->GetDataFileOFStream(filename));
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -1302,8 +1292,8 @@
if( fname == "" ){
filename.Set("dump.%d", m_world->GetStats().GetUpdate());
}
- ofstream fp(filename());
- m_world->GetPopulation().GetGenebank().DumpTextSummary(fp);
+ m_world->GetPopulation().GetGenebank().DumpTextSummary(m_world->GetDataFileOFStream(filename));
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -1351,8 +1341,9 @@
if (filename == "") {
filename.Set("genotypes-%d.dat", m_world->GetStats().GetUpdate());
}
- ofstream fp(filename());
- m_world->GetPopulation().GetGenebank().PrintGenotypes(fp, data_fields, historic);
+ m_world->GetPopulation().GetGenebank().PrintGenotypes(m_world->GetDataFileOFStream(filename),
+ data_fields, historic);
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -1387,8 +1378,8 @@
if( fname == "" ){
filename.Set("detail_pop.%d", m_world->GetStats().GetUpdate());
}
- ofstream fp(filename());
- m_world->GetPopulation().GetGenebank().DumpDetailedSummary(fp);
+ m_world->GetPopulation().GetGenebank().DumpDetailedSummary(m_world->GetDataFileOFStream(filename));
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -1424,8 +1415,8 @@
if( fname == "" ){
filename.Set("detail_pop.%d", m_world->GetStats().GetUpdate());
}
- ofstream fp(filename());
- m_world->GetPopulation().GetGenebank().DumpDetailedSexSummary(fp);
+ m_world->GetPopulation().GetGenebank().DumpDetailedSexSummary(m_world->GetDataFileOFStream(filename));
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -1460,7 +1451,6 @@
if( fname == "" ){
filename.Set("detail_parasite_pop.%d", m_world->GetStats().GetUpdate());
}
- //ofstream fp(filename());
m_world->GetPopulation().GetInjectGenebank().DumpDetailedSummary(filename, m_world->GetStats().GetUpdate());
}
};
@@ -1504,8 +1494,8 @@
if( fname == "" ){
filename.Set("historic_dump.%d", m_world->GetStats().GetUpdate());
}
- ofstream fp(filename());
- m_world->GetPopulation().GetGenebank().DumpHistoricSummary(fp, back_dist);
+ m_world->GetPopulation().GetGenebank().DumpHistoricSummary(m_world->GetDataFileOFStream(filename), back_dist);
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -1541,8 +1531,8 @@
if( fname == "" ){
filename.Set("historic_dump.%d", m_world->GetStats().GetUpdate());
}
- ofstream fp(filename());
- m_world->GetPopulation().GetGenebank().DumpHistoricSexSummary(fp);
+ m_world->GetPopulation().GetGenebank().DumpHistoricSexSummary(m_world->GetDataFileOFStream(filename));
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -1573,8 +1563,8 @@
if (fname == "") {
filename.Set("memory_dump.%d", m_world->GetStats().GetUpdate());
}
- ofstream fp(filename());
- m_world->GetPopulation().DumpMemorySummary(fp);
+ m_world->GetPopulation().DumpMemorySummary(m_world->GetDataFileOFStream(filename));
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -2289,8 +2279,7 @@
void Process(){
cGenome & genome = m_world->GetPopulation().GetGenebank().GetBestGenotype()->GetGenome();
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
- static ofstream fp(datafile);
- landscape.PredictWProcess(fp);
+ landscape.PredictWProcess(m_world->GetDataFileOFStream(datafile));
}
};
@@ -2318,8 +2307,7 @@
void Process(){
cGenome & genome = m_world->GetPopulation().GetGenebank().GetBestGenotype()->GetGenome();
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
- static ofstream fp(datafile);
- landscape.PredictNuProcess(fp);
+ landscape.PredictNuProcess(m_world->GetDataFileOFStream(datafile));
}
};
@@ -2349,8 +2337,7 @@
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
if (sample_size == 0) sample_size = m_world->GetHardwareManager().GetInstSet().GetSize() - 1;
landscape.SampleProcess(sample_size);
- static ofstream fp("land-sample.dat");
- landscape.PrintStats(fp, m_world->GetStats().GetUpdate());
+ landscape.PrintStats(m_world->GetDataFileOFStream("land-sample.dat"), m_world->GetStats().GetUpdate());
}
};
@@ -2388,8 +2375,7 @@
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
landscape.RandomProcess(sample_size, landscape_dist, min_found,
max_sample_size, print_if_found);
- static ofstream fp("land-random.dat");
- landscape.PrintStats(fp, m_world->GetStats().GetUpdate());
+ landscape.PrintStats(m_world->GetDataFileOFStream("land-random.dat"), m_world->GetStats().GetUpdate());
}
};
@@ -2450,7 +2436,8 @@
///// pairtest_landscape /////
void Process(){
cGenome & genome = m_world->GetPopulation().GetGenebank().GetBestGenotype()->GetGenome();
- cAnalyzeUtil::PairTestLandscape(m_world, genome, m_world->GetHardwareManager().GetInstSet(), sample_size, m_world->GetStats().GetUpdate());
+ cAnalyzeUtil::PairTestLandscape(m_world, genome, m_world->GetHardwareManager().GetInstSet(),
+ sample_size, m_world->GetStats().GetUpdate());
}
};
@@ -2473,8 +2460,8 @@
///// test_dom /////
void Process(){
cGenome & genome = m_world->GetPopulation().GetGenebank().GetBestGenotype()->GetGenome();
- static ofstream fp("dom-test.dat");
- cAnalyzeUtil::TestGenome(m_world, genome, m_world->GetHardwareManager().GetInstSet(), fp, m_world->GetStats().GetUpdate());
+ cAnalyzeUtil::TestGenome(m_world, genome, m_world->GetHardwareManager().GetInstSet(),
+ m_world->GetDataFileOFStream("dom-test.dat"), m_world->GetStats().GetUpdate());
}
};
@@ -2506,13 +2493,10 @@
}
///// analyze_population /////
void Process(){
- static bool auto_filename = false;
- if( filename == "" )
- auto_filename = true;
- if ( auto_filename )
- filename.Set("population_info_%d.dat",m_world->GetStats().GetUpdate());
- ofstream population_info(filename());
- cAnalyzeUtil::AnalyzePopulation(m_world, population_info, sample_prob, landscape, save_genotype);
+ if (filename == "") filename.Set("population_info_%d.dat",m_world->GetStats().GetUpdate());
+ cAnalyzeUtil::AnalyzePopulation(m_world, m_world->GetDataFileOFStream(filename), sample_prob,
+ landscape, save_genotype);
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -2578,10 +2562,9 @@
}
///// print_genetic_distance_data /////
void Process(){
- static ofstream popdump(filename());
- if( creature_name == "" || creature_name == "START_CREATURE" ){
- creature_name = m_world->GetConfig().START_CREATURE.Get(); }
- cAnalyzeUtil::PrintGeneticDistanceData(m_world, popdump, creature_name() );
+ if( creature_name == "" || creature_name == "START_CREATURE" )
+ creature_name = m_world->GetConfig().START_CREATURE.Get();
+ cAnalyzeUtil::PrintGeneticDistanceData(m_world, m_world->GetDataFileOFStream(filename), creature_name);
}
};
@@ -2610,16 +2593,14 @@
if (args == "") save_genotype=0; else save_genotype=args.PopWord().AsInt();
}
///// genetic_distance_pop_dump /////
- void Process(){
- static bool auto_filename = false;
- if( creature_name == "" || creature_name == "START_CREATURE" ){
- creature_name = m_world->GetConfig().START_CREATURE.Get(); }
- if( filename == "" || filename == "AUTO" )
- auto_filename = true;
- if ( auto_filename )
+ 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());
- ofstream popdump(filename());
- cAnalyzeUtil::GeneticDistancePopDump(m_world, popdump, creature_name(), save_genotype );
+ cAnalyzeUtil::GeneticDistancePopDump(m_world, m_world->GetDataFileOFStream(filename),
+ creature_name, save_genotype);
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -2641,17 +2622,14 @@
m_world = world;
m_args = in_args;
cString args(in_args);
- if (args == "") filename=""; else filename=args.PopWord();
+ if (args == "") filename = "";
+ else filename = args.PopWord();
}
///// task_snapshot /////
void Process(){
- static bool auto_filename = false;
- if( filename == "" )
- auto_filename = true;
- if ( auto_filename )
- filename.Set("tasks_%d.dat",m_world->GetStats().GetUpdate());
- ofstream snapshot_file(filename());
- cAnalyzeUtil::TaskSnapshot(m_world, snapshot_file);
+ if (filename == "") filename.Set("tasks_%d.dat",m_world->GetStats().GetUpdate());
+ cAnalyzeUtil::TaskSnapshot(m_world, m_world->GetDataFileOFStream(filename));
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -2677,8 +2655,7 @@
}
///// print_viable_tasks_data /////
void Process(){
- static ofstream datafile(filename());
- cAnalyzeUtil::PrintViableTasksData(m_world, datafile);
+ cAnalyzeUtil::PrintViableTasksData(m_world, m_world->GetDataFileOFStream(filename));
}
};
@@ -2900,9 +2877,9 @@
///// hillclimb /////
void Process(){
cGenome & genome = m_world->GetPopulation().GetGenebank().GetBestGenotype()->GetGenome();
- ofstream fp("hillclimb.dat");
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
- landscape.HillClimb(fp);
+ landscape.HillClimb(m_world->GetDataFileOFStream("hillclimb.dat"));
+ m_world->GetDataFileManager().Remove("hillclimb.dat");
}
};
@@ -2925,9 +2902,9 @@
///// hillclimb_neut /////
void Process(){
cGenome & genome = m_world->GetPopulation().GetGenebank().GetBestGenotype()->GetGenome();
- ofstream fp("hillclimb.dat");
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
- landscape.HillClimb_Neut(fp);
+ landscape.HillClimb_Neut(m_world->GetDataFileOFStream("hillclimb.dat"));
+ m_world->GetDataFileManager().Remove("hillclimb.dat");
}
};
@@ -2950,9 +2927,9 @@
///// hillclimb_rand /////
void Process(){
cGenome & genome = m_world->GetPopulation().GetGenebank().GetBestGenotype()->GetGenome();
- ofstream fp("hillclimb.dat");
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
- landscape.HillClimb_Rand(fp);
+ landscape.HillClimb_Rand(m_world->GetDataFileOFStream("hillclimb.dat"));
+ m_world->GetDataFileManager().Remove("hillclimb.dat");
}
};
@@ -3123,7 +3100,7 @@
}
///// test_size_change_robustness /////
void Process(){
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
cAnalyzeUtil::TestInsSizeChangeRobustness(m_world, fp,
m_world->GetHardwareManager().GetInstSet(),
m_world->GetPopulation().GetGenebank().GetBestGenotype()->GetGenome(),
@@ -3204,7 +3181,7 @@
void Process(){
cString filename;
filename.Set("fgrid.%05d.out", m_world->GetStats().GetUpdate());
- ofstream fp(filename());
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
for (int i = 0; i < m_world->GetPopulation().GetWorldX(); i++) {
for (int j = 0; j < m_world->GetPopulation().GetWorldY(); j++) {
cPopulationCell & cell = m_world->GetPopulation().GetCell(j*m_world->GetPopulation().GetWorldX()+i);
@@ -3214,6 +3191,7 @@
}
fp << endl;
}
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -3243,7 +3221,7 @@
void Process(){
cString filename;
filename.Set("idgrid.%05d.out", m_world->GetStats().GetUpdate());
- ofstream fp(filename());
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
for (int i = 0; i < m_world->GetPopulation().GetWorldX(); i++) {
for (int j = 0; j < m_world->GetPopulation().GetWorldY(); j++) {
cPopulationCell & cell = m_world->GetPopulation().GetCell(j*m_world->GetPopulation().GetWorldX()+i);
@@ -3253,6 +3231,7 @@
}
fp << endl;
}
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -3279,9 +3258,9 @@
///// dump_task_grid /////
void Process(){
cString filename;
- filename.Set("task_grid_%d.dat",m_world->GetStats().GetUpdate());
- ofstream fp(filename());
- cAnalyzeUtil::TaskGrid(m_world, fp );
+ filename.Set("task_grid_%d.dat", m_world->GetStats().GetUpdate());
+ cAnalyzeUtil::TaskGrid(m_world, m_world->GetDataFileOFStream(filename));
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -3311,7 +3290,7 @@
void Process(){
cString filename;
filename.Set("donor_grid.%05d.out", m_world->GetStats().GetUpdate());
- ofstream fp(filename());
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
for (int i = 0; i < m_world->GetPopulation().GetWorldX(); i++) {
for (int j = 0; j < m_world->GetPopulation().GetWorldY(); j++) {
cPopulationCell & cell = m_world->GetPopulation().GetCell(j*m_world->GetPopulation().GetWorldX()+i);
@@ -3321,6 +3300,7 @@
}
fp << endl;
}
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -3349,7 +3329,7 @@
void Process(){
cString filename;
filename.Set("receiver_grid.%05d.out", m_world->GetStats().GetUpdate());
- ofstream fp(filename());
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
for (int i = 0; i < m_world->GetPopulation().GetWorldX(); i++) {
for (int j = 0; j < m_world->GetPopulation().GetWorldY(); j++) {
cPopulationCell & cell = m_world->GetPopulation().GetCell(j*m_world->GetPopulation().GetWorldX()+i);
@@ -3359,6 +3339,7 @@
}
fp << endl;
}
+ m_world->GetDataFileManager().Remove(filename);
}
};
@@ -3386,8 +3367,8 @@
///// print_tree_depths /////
void Process(){
if (filename == "") filename.Set("tree_depth.%d.dat", m_world->GetStats().GetUpdate());
- ofstream fp(filename);
- cAnalyzeUtil::PrintTreeDepths(&m_world->GetPopulation(), fp);
+ cAnalyzeUtil::PrintTreeDepths(&m_world->GetPopulation(), m_world->GetDataFileOFStream(filename));
+ m_world->GetDataFileManager().Remove(filename);
}
};
Modified: development/source/main/cAvidaDriver_Analyze.cc
===================================================================
--- development/source/main/cAvidaDriver_Analyze.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cAvidaDriver_Analyze.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -30,10 +30,6 @@
{
}
-cAvidaDriver_Analyze::~cAvidaDriver_Analyze()
-{
-}
-
void cAvidaDriver_Analyze::Run()
{
cout << "In analyze mode!!" << endl;
Modified: development/source/main/cAvidaDriver_Analyze.h
===================================================================
--- development/source/main/cAvidaDriver_Analyze.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cAvidaDriver_Analyze.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -22,7 +22,8 @@
cWorld* m_world;
public:
cAvidaDriver_Analyze(cWorld* world, bool _interactive=false);
- virtual ~cAvidaDriver_Analyze();
+ ~cAvidaDriver_Analyze() { delete m_world; }
+
virtual void Run();
};
Modified: development/source/main/cAvidaDriver_Population.h
===================================================================
--- development/source/main/cAvidaDriver_Population.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cAvidaDriver_Population.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -24,7 +24,7 @@
protected:
cWorld* m_world;
-public:
+public:
cWorld& GetWorld() { return *m_world; }
/**
Modified: development/source/main/cFitnessMatrix.cc
===================================================================
--- development/source/main/cFitnessMatrix.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cFitnessMatrix.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -347,7 +347,7 @@
}
-void cFitnessMatrix::PrintGenotypes(ostream &fp)
+void cFitnessMatrix::PrintGenotypes(ostream& fp)
{
int totNumDead=0, totNumBelowThresh=0, totNumOK=0;
int totNumNew=0, totNumVisited=0, totDepth=0;
@@ -465,7 +465,7 @@
*/
-void cFitnessMatrix::PrintTransitionMatrix(ostream &fp, int hamDistThresh, double errorRate, double avg_fitness, bool printMatrix)
+void cFitnessMatrix::PrintTransitionMatrix(ostream& fp, int hamDistThresh, double errorRate, double avg_fitness, bool printMatrix)
{
fp << endl << endl;
Modified: development/source/main/cFitnessMatrix.h
===================================================================
--- development/source/main/cFitnessMatrix.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cFitnessMatrix.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -100,7 +100,7 @@
/* Data Output */
- void PrintGenotypes(std::ostream &fp);
+ void PrintGenotypes(std::ostream& fp);
void PrintTransitionMatrix(std::ostream& fp, int hamDistThresh, double errorRate, double avg_fitness, bool printMatrix=false);
void PrintHammingVector(std::ostream& fp,const std::vector<double>& dataVect, double errProb, double avgFit);
void PrintFitnessVector(std::ostream& fp,const std::vector<double>& dataVect, double errProb, double avgFit, double maxFit, double step);
Modified: development/source/main/cGenebank.cc
===================================================================
--- development/source/main/cGenebank.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cGenebank.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -429,7 +429,7 @@
return true;
}
-bool cGenebank::SaveClone(ofstream & fp)
+bool cGenebank::SaveClone(ofstream& fp)
{
// This method just save the counts at each size-class of genotypes.
// The rest is reconstructable.
@@ -459,7 +459,7 @@
return true;
}
-bool cGenebank::DumpTextSummary(ofstream & fp)
+bool cGenebank::DumpTextSummary(ofstream& fp)
{
genotype_control->Reset(0);
for (int i = 0; i < genotype_control->GetSize(); i++) {
@@ -473,7 +473,7 @@
return true;
}
-bool cGenebank::PrintGenotypes(ofstream & fp, cString & data_fields,
+bool cGenebank::PrintGenotypes(ofstream& fp, cString & data_fields,
int historic)
{
bool print_id = false;
@@ -628,7 +628,7 @@
return true;
}
-bool cGenebank::DumpDetailedSummary(ofstream & fp)
+bool cGenebank::DumpDetailedSummary(ofstream& fp)
{
genotype_control->Reset(0);
DumpDetailHeading(fp);
@@ -640,7 +640,7 @@
return true;
}
-bool cGenebank::DumpHistoricSummary(ofstream & fp, int back_dist)
+bool cGenebank::DumpHistoricSummary(ofstream& fp, int back_dist)
{
// Calculate the update we should start printing from...
int start_update = 0;
@@ -665,7 +665,7 @@
return true;
}
-bool cGenebank::DumpDetailedSexSummary(ofstream & fp)
+bool cGenebank::DumpDetailedSexSummary(ofstream& fp)
{
genotype_control->Reset(0);
DumpDetailSexHeading(fp);
@@ -677,7 +677,7 @@
return true;
}
-bool cGenebank::DumpHistoricSexSummary(ofstream & fp)
+bool cGenebank::DumpHistoricSexSummary(ofstream& fp)
{
genotype_control->ResetHistoric(0);
DumpDetailSexHeading(fp);
@@ -689,7 +689,7 @@
return true;
}
-void cGenebank::DumpDetailHeading (ofstream & fp)
+void cGenebank::DumpDetailHeading (ofstream& fp)
{
fp << "#filetype genotype_data" << endl
<< "#format id parent_id parent_dist num_cpus total_cpus length merit gest_time fitness update_born update_dead depth sequence" << endl
@@ -709,7 +709,7 @@
<< "# 13: genome of organism" << endl << endl;
}
-void cGenebank::DumpDetailSexHeading (ofstream & fp)
+void cGenebank::DumpDetailSexHeading (ofstream& fp)
{
fp << "#filetype genotype_data" << endl
<< "#format id parent_id parent2_id parent_dist num_cpus total_cpus length merit gest_time fitness update_born update_dead depth sequence" << endl
@@ -730,7 +730,7 @@
<< "# 14: genome of organism" << endl << endl;
}
-void cGenebank::DumpDetailedEntry(cGenotype * genotype, ofstream & fp)
+void cGenebank::DumpDetailedEntry(cGenotype * genotype, ofstream& fp)
{
fp << genotype->GetID() << " " // 1
<< genotype->GetParentID() << " " // 2
@@ -749,7 +749,7 @@
<< endl;
}
-void cGenebank::DumpDetailedSexEntry(cGenotype * genotype, ofstream & fp)
+void cGenebank::DumpDetailedSexEntry(cGenotype * genotype, ofstream& fp)
{
fp << genotype->GetID() << " " // 1
<< genotype->GetAncestorID(0) << " " // 2
Modified: development/source/main/cGenebank.h
===================================================================
--- development/source/main/cGenebank.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cGenebank.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -76,18 +76,18 @@
void ThresholdGenotype(cGenotype & in_genotype);
bool AdjustGenotype(cGenotype & in_genotype);
- bool SaveClone(std::ofstream & fp);
+ bool SaveClone(std::ofstream& fp);
bool LoadClone(std::ifstream & fp);
- bool DumpTextSummary(std::ofstream & fp);
- bool PrintGenotypes(std::ofstream & fp, cString & data_fields, int historic);
- bool DumpDetailedSummary(std::ofstream & fp);
- bool DumpDetailedSexSummary(std::ofstream & fp);
- bool DumpHistoricSummary(std::ofstream & fp, int back_dist);
- bool DumpHistoricSexSummary(std::ofstream & fp);
- void DumpDetailHeading (std::ofstream & fp);
- void DumpDetailSexHeading (std::ofstream & fp);
- void DumpDetailedEntry(cGenotype * genotype, std::ofstream & fp);
- void DumpDetailedSexEntry(cGenotype * genotype, std::ofstream & fp);
+ bool DumpTextSummary(std::ofstream& fp);
+ bool PrintGenotypes(std::ofstream& fp, cString & data_fields, int historic);
+ bool DumpDetailedSummary(std::ofstream& fp);
+ bool DumpDetailedSexSummary(std::ofstream& fp);
+ bool DumpHistoricSummary(std::ofstream& fp, int back_dist);
+ bool DumpHistoricSexSummary(std::ofstream& fp);
+ void DumpDetailHeading (std::ofstream& fp);
+ void DumpDetailSexHeading (std::ofstream& fp);
+ void DumpDetailedEntry(cGenotype * genotype, std::ofstream& fp);
+ void DumpDetailedSexEntry(cGenotype * genotype, std::ofstream& fp);
bool OK();
inline int GetSize() const { return genotype_control->GetSize(); }
Modified: development/source/main/cGenotype.cc
===================================================================
--- development/source/main/cGenotype.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cGenotype.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -63,7 +63,7 @@
prev = NULL;
}
-bool cGenotype::SaveClone(ofstream & fp)
+bool cGenotype::SaveClone(ofstream& fp)
{
fp << id_num << " ";
fp << genome.GetSize() << " ";
Modified: development/source/main/cGenotype.h
===================================================================
--- development/source/main/cGenotype.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cGenotype.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -95,7 +95,7 @@
cGenotype(cWorld* world, int in_update_born = 0, int in_id = -1);
~cGenotype();
- bool SaveClone(std::ofstream & fp);
+ bool SaveClone(std::ofstream& fp);
bool LoadClone(std::ifstream & fp);
bool OK();
void Mutate();
Modified: development/source/main/cInjectGenebank.cc
===================================================================
--- development/source/main/cInjectGenebank.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cInjectGenebank.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -202,7 +202,7 @@
return true;
}
-bool cInjectGenebank::SaveClone(ofstream & fp)
+bool cInjectGenebank::SaveClone(ofstream& fp)
{
// This method just save the counts at each size-class of genotypes.
// The rest is reconstructable.
@@ -232,7 +232,7 @@
return true;
}
-bool cInjectGenebank::DumpTextSummary(ofstream & fp)
+bool cInjectGenebank::DumpTextSummary(ofstream& fp)
{
inject_genotype_control->Reset(0);
for (int i = 0; i < inject_genotype_control->GetSize(); i++) {
@@ -256,7 +256,7 @@
return true;
}
-/*bool cInjectGenebank::DumpHistoricSummary(ofstream & fp)
+/*bool cInjectGenebank::DumpHistoricSummary(ofstream& fp)
{
inject_genotype_control->ResetHistoric(0);
for (int i = 0; i < inject_genotype_control->GetHistoricCount(); i++) {
Modified: development/source/main/cInjectGenebank.h
===================================================================
--- development/source/main/cInjectGenebank.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cInjectGenebank.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -69,15 +69,15 @@
void ThresholdInjectGenotype(cInjectGenotype & in_inject_genotype);
bool AdjustInjectGenotype(cInjectGenotype & in_inject_genotype);
- bool SaveClone(std::ofstream & fp);
+ bool SaveClone(std::ofstream& fp);
bool LoadClone(std::ifstream & fp);
- bool DumpTextSummary(std::ofstream & fp);
- //bool DumpDetailedSummary(std::ofstream & fp);
+ bool DumpTextSummary(std::ofstream& fp);
+ //bool DumpDetailedSummary(std::ofstream& fp);
bool DumpDetailedSummary(const cString & file, int update);
/*
- bool DumpHistoricSummary(std::ofstream & fp);
+ bool DumpHistoricSummary(std::ofstream& fp);
*/
- //void DumpDetailedEntry(cInjectGenotype * inject_genotype, std::ofstream & fp);
+ //void DumpDetailedEntry(cInjectGenotype * inject_genotype, std::ofstream& fp);
void DumpDetailedEntry(cInjectGenotype * inject_genotype, const cString & file, int update);
bool OK();
Modified: development/source/main/cInjectGenotype.cc
===================================================================
--- development/source/main/cInjectGenotype.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cInjectGenotype.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -49,7 +49,7 @@
prev = NULL;
}
-bool cInjectGenotype::SaveClone(ofstream & fp)
+bool cInjectGenotype::SaveClone(ofstream& fp)
{
fp << id_num << " ";
fp << genome.GetSize() << " ";
Modified: development/source/main/cInjectGenotype.h
===================================================================
--- development/source/main/cInjectGenotype.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cInjectGenotype.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -107,7 +107,7 @@
cInjectGenotype(cWorld* world, int in_update_born = 0, int in_id = -1);
~cInjectGenotype();
- bool SaveClone(std::ofstream & fp);
+ bool SaveClone(std::ofstream& fp);
bool LoadClone(std::ifstream & fp);
bool OK();
void Mutate();
Modified: development/source/main/cInstUtil.cc
===================================================================
--- development/source/main/cInstUtil.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cInstUtil.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -82,7 +82,7 @@
return new_genome;
}
-void cInstUtil::SaveGenome(ostream & fp, const cInstSet & inst_set,
+void cInstUtil::SaveGenome(ostream& fp, const cInstSet & inst_set,
const cGenome & gen)
{
for (int i = 0; i < gen.GetSize(); i++) {
@@ -90,7 +90,7 @@
}
}
-void cInstUtil::SaveInternalGenome(ostream & fp, const cInstSet & inst_set,
+void cInstUtil::SaveInternalGenome(ostream& fp, const cInstSet & inst_set,
const cGenome & gen)
{
fp << gen.GetSize() << endl;
Modified: development/source/main/cInstUtil.h
===================================================================
--- development/source/main/cInstUtil.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cInstUtil.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -27,9 +27,9 @@
static cGenome LoadGenome(const cString &filename, const cInstSet &inst_set);
static cGenome LoadInternalGenome(std::istream & fp, const cInstSet &inst_set);
- static void SaveGenome(std::ostream &fp, const cInstSet & inst_set,
+ static void SaveGenome(std::ostream& fp, const cInstSet & inst_set,
const cGenome &gen);
- static void SaveInternalGenome(std::ostream &fp, const cInstSet &inst_set,
+ static void SaveInternalGenome(std::ostream& fp, const cInstSet &inst_set,
const cGenome &gen);
// ========= Genome Construction =========
Modified: development/source/main/cLandscape.cc
===================================================================
--- development/source/main/cLandscape.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cLandscape.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -224,7 +224,7 @@
}
// Prediction for a landscape where n sites are _randomized_.
-void cLandscape::PredictWProcess(ostream & fp, int update)
+void cLandscape::PredictWProcess(ostream& fp, int update)
{
distance = 1;
@@ -340,7 +340,7 @@
// Prediction for a landscape where n sites are _mutated_.
-void cLandscape::PredictNuProcess(ostream & fp, int update)
+void cLandscape::PredictNuProcess(ostream& fp, int update)
{
distance = 1;
@@ -587,7 +587,7 @@
}
-void cLandscape::TestPairs(int in_trials, ostream & fp)
+void cLandscape::TestPairs(int in_trials, ostream& fp)
{
trials = in_trials;
@@ -627,7 +627,7 @@
}
-void cLandscape::TestAllPairs(ostream & fp)
+void cLandscape::TestAllPairs(ostream& fp)
{
ProcessBase();
if (base_fitness == 0.0) return;
@@ -660,14 +660,14 @@
}
-void cLandscape::HillClimb(ofstream & fp)
+void cLandscape::HillClimb(ofstream& fp)
{
cGenome cur_genome(base_genome);
int gen = 0;
HillClimb_Body(fp, cur_genome, gen);
}
-void cLandscape::HillClimb_Body(ofstream & fp, cGenome & cur_genome,
+void cLandscape::HillClimb_Body(ofstream& fp, cGenome & cur_genome,
int & gen)
{
cCPUMemory mod_genome(base_genome);
@@ -719,15 +719,15 @@
}
}
-void cLandscape::HillClimb_Neut(ofstream & fp)
+void cLandscape::HillClimb_Neut(ofstream& fp)
{
}
-void cLandscape::HillClimb_Rand(ofstream & fp)
+void cLandscape::HillClimb_Rand(ofstream& fp)
{
}
-void cLandscape::HillClimb_Print(ofstream & fp, const cGenome & _genome, const int gen) const
+void cLandscape::HillClimb_Print(ofstream& fp, const cGenome & _genome, const int gen) const
{
cCPUTestInfo test_info;
m_world->GetTestCPU().TestGenome(test_info, _genome);
@@ -745,7 +745,7 @@
}
double cLandscape::TestMutPair(cGenome & mod_genome, int line1, int line2,
- const cInstruction & mut1, const cInstruction & mut2, ostream & fp)
+ const cInstruction & mut1, const cInstruction & mut2, ostream& fp)
{
mod_genome[line1] = mut1;
mod_genome[line2] = mut2;
@@ -788,7 +788,7 @@
}
-void cLandscape::PrintStats(ofstream & fp, int update)
+void cLandscape::PrintStats(ofstream& fp, int update)
{
fp << update << " " // 1
<< GetProbDead() << " " // 2
@@ -824,7 +824,7 @@
fp.flush();
}
-void cLandscape::PrintEntropy(ofstream & fp)
+void cLandscape::PrintEntropy(ofstream& fp)
{
double max_ent = log((double) inst_set.GetSize());
for (int j = 0; j < base_genome.GetSize(); j++) {
@@ -834,7 +834,7 @@
fp.flush();
}
-void cLandscape::PrintSiteCount(ofstream & fp)
+void cLandscape::PrintSiteCount(ofstream& fp)
{
for (int j = 0; j < base_genome.GetSize(); j++) {
fp << site_count[j] << " ";
Modified: development/source/main/cLandscape.h
===================================================================
--- development/source/main/cLandscape.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cLandscape.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -88,12 +88,12 @@
void ProcessBase();
void Process_Body(cGenome & cur_genome, int cur_distance, int start_line);
- void HillClimb_Body(std::ofstream & fp, cGenome & cur_genome, int & gen);
- void HillClimb_Print(std::ofstream & fp, const cGenome & _genome,
+ void HillClimb_Body(std::ofstream& fp, cGenome & cur_genome, int & gen);
+ void HillClimb_Print(std::ofstream& fp, const cGenome & _genome,
const int gen) const;
double TestMutPair(cGenome & mod_genome, int line1, int line2,
- const cInstruction & mut1, const cInstruction & mut2, std::ostream & fp);
+ const cInstruction & mut1, const cInstruction & mut2, std::ostream& fp);
private:
// disabled copy constructor.
cLandscape(const cLandscape &);
@@ -106,23 +106,23 @@
void Process(int in_distance=1);
void ProcessDelete();
void ProcessInsert();
- void PredictWProcess(std::ostream & fp, int update=-1);
- void PredictNuProcess(std::ostream & fp, int update=-1);
+ void PredictWProcess(std::ostream& fp, int update=-1);
+ void PredictNuProcess(std::ostream& fp, int update=-1);
void SampleProcess(int in_trials);
int RandomProcess(int in_trials, int in_distance=1, int min_found=0,
int max_trials=0, bool print_if_found=false);
- void TestPairs(int in_trials, std::ostream & fp);
- void TestAllPairs(std::ostream & fp);
+ void TestPairs(int in_trials, std::ostream& fp);
+ void TestAllPairs(std::ostream& fp);
- void HillClimb(std::ofstream & fp);
- void HillClimb_Neut(std::ofstream & fp);
- void HillClimb_Rand(std::ofstream & fp);
+ void HillClimb(std::ofstream& fp);
+ void HillClimb_Neut(std::ofstream& fp);
+ void HillClimb_Rand(std::ofstream& fp);
- void PrintStats(std::ofstream & fp, int update=-1);
- void PrintEntropy(std::ofstream & fp);
- void PrintSiteCount(std::ofstream & fp);
+ void PrintStats(std::ofstream& fp, int update=-1);
+ void PrintEntropy(std::ofstream& fp);
+ void PrintSiteCount(std::ofstream& fp);
void PrintBase(cString filename);
void PrintPeak(cString filename);
Modified: development/source/main/cLineageControl.cc
===================================================================
--- development/source/main/cLineageControl.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cLineageControl.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -312,7 +312,7 @@
void cLineageControl::PrintLineageTotals(const cString &filename, bool verbose)
{
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
assert(fp.good());
fp << m_stats.GetUpdate();
@@ -371,7 +371,7 @@
void cLineageControl::PrintLineageCurCounts(const cString & filename)
{
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
assert(fp.good());
fp << m_stats.GetUpdate() << " ";
Modified: development/source/main/cMxCodeArray.cc
===================================================================
--- development/source/main/cMxCodeArray.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cMxCodeArray.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -416,7 +416,7 @@
Used in testing the diagonalization.
*/
-void cMxCodeArray::PrintTransitionList(ostream &fp, int size) const
+void cMxCodeArray::PrintTransitionList(ostream& fp, int size) const
{
fp.setf(ios::fixed);
Modified: development/source/main/cMxCodeArray.h
===================================================================
--- development/source/main/cMxCodeArray.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cMxCodeArray.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -107,7 +107,7 @@
const std::map<int, double, std::less<int> >& GetTransitionList() const;
int HammingDistance(const cMxCodeArray &other_gene) const;
double TransitionProbability(const cMxCodeArray &other_gene, double errorRate) const;
- void PrintTransitionList(std::ostream &fp, int size) const;
+ void PrintTransitionList(std::ostream& fp, int size) const;
};
cInstruction & cMxCodeArray::operator[](int index)
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cOrganism.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -227,7 +227,7 @@
bool cOrganism::GetSterilizePos() const { return m_world->GetConfig().STERILIZE_BENEFICIAL.Get(); }
-void cOrganism::PrintStatus(ostream & fp, const cString & next_name)
+void cOrganism::PrintStatus(ostream& fp, const cString & next_name)
{
fp << "---------------------------" << endl;
hardware->PrintStatus(fp);
@@ -305,7 +305,7 @@
//// Save and Load ////
-void cOrganism::SaveState(ofstream & fp)
+void cOrganism::SaveState(ofstream& fp)
{
assert(fp.good());
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cOrganism.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -102,7 +102,7 @@
static int instance_count;
public:
- void PrintStatus(std::ostream & fp, const cString & next_name);
+ void PrintStatus(std::ostream& fp, const cString & next_name);
// Divide functions
bool Divide_CheckViable();
@@ -216,7 +216,7 @@
const cPhenotype & GetPhenotype() const { return phenotype; }
cPhenotype & GetPhenotype() { return phenotype; }
- void SaveState(std::ofstream & fp);
+ void SaveState(std::ofstream& fp);
void LoadState(std::ifstream & fp);
// -------- DEBUG ---------
Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cPhenotype.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -552,7 +552,7 @@
///// For Loading and Saving State: /////
-bool cPhenotype::SaveState(ofstream & fp)
+bool cPhenotype::SaveState(ofstream& fp)
{
assert(fp.good());
fp << "cPhenotype" << endl;
@@ -699,7 +699,7 @@
return true;
}
-void cPhenotype::PrintStatus(ostream & fp)
+void cPhenotype::PrintStatus(ostream& fp)
{
fp << " MeritBase:"
<< CalcSizeMerit()
Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cPhenotype.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -157,9 +157,9 @@
tList<tBuffer<int> > & other_outputs);
// State saving and loading, and printing...
- bool SaveState(std::ofstream & fp);
+ bool SaveState(std::ofstream& fp);
bool LoadState(std::ifstream & fp);
- void PrintStatus(std::ostream & fp);
+ void PrintStatus(std::ostream& fp);
// Some useful methods...
int CalcSizeMerit() const;
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cPopulation.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -1445,7 +1445,7 @@
}
-bool cPopulation::SaveClone(ofstream & fp)
+bool cPopulation::SaveClone(ofstream& fp)
{
if (fp.good() == false) return false;
@@ -1678,7 +1678,7 @@
}
//// Save And Load Populations ////
-bool cPopulation::SavePopulation(ofstream & fp)
+bool cPopulation::SavePopulation(ofstream& fp)
{
if (fp.good() == false) return false;
@@ -1713,7 +1713,7 @@
}
-bool cPopulation::DumpMemorySummary(ofstream & fp)
+bool cPopulation::DumpMemorySummary(ofstream& fp)
{
if (fp.good() == false) return false;
@@ -2024,8 +2024,7 @@
void cPopulation::ParasiteDebug()
{
- ofstream outfile;
- outfile.open("debug.out", ofstream::app);
+ ofstream& outfile = m_world->GetDataFileOFStream("debug.out");
outfile << m_world->GetStats().GetUpdate() << endl;
int total=0;
cInjectGenotype * temp;
@@ -2048,7 +2047,6 @@
}
}
outfile << total << endl;
- outfile.close();
}
void cPopulation::PrintPhenotypeData(const cString & filename)
@@ -2070,10 +2068,8 @@
}
ids.insert(id);
}
- ofstream outfile;
- outfile.open(filename, ofstream::app);
- outfile << m_world->GetStats().GetUpdate() << "\t" << ids.size() << endl;
- outfile.close();
+ m_world->GetDataFileOFStream(filename)
+ << m_world->GetStats().GetUpdate() << "\t" << ids.size() << endl;
}
void cPopulation::PrintPhenotypeStatus(const cString & filename)
Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cPopulation.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -155,12 +155,12 @@
void SerialTransfer( int transfer_size, bool ignore_deads );
// Saving and loading...
- bool SaveClone(std::ofstream & fp);
+ bool SaveClone(std::ofstream& fp);
bool LoadClone(std::ifstream & fp);
bool LoadDumpFile(cString filename, int update);
- bool SavePopulation(std::ofstream & fp);
+ bool SavePopulation(std::ofstream& fp);
bool LoadPopulation(std::ifstream & fp);
- bool DumpMemorySummary(std::ofstream & fp);
+ bool DumpMemorySummary(std::ofstream& fp);
bool OK();
Modified: development/source/main/cPopulationCell.cc
===================================================================
--- development/source/main/cPopulationCell.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cPopulationCell.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -130,7 +130,7 @@
return true;
}
-bool cPopulationCell::SaveState(ofstream & fp)
+bool cPopulationCell::SaveState(ofstream& fp)
{
// Nothing for the moment...
return false;
Modified: development/source/main/cPopulationCell.h
===================================================================
--- development/source/main/cPopulationCell.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cPopulationCell.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -69,7 +69,7 @@
bool OK();
- bool SaveState(std::ofstream & fp);
+ bool SaveState(std::ofstream& fp);
bool LoadState(std::ifstream & fp);
};
Modified: development/source/main/cSpecies.h
===================================================================
--- development/source/main/cSpecies.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cSpecies.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -43,6 +43,7 @@
cSpecies * next;
cSpecies * prev;
+
public:
cSpecies(cWorld* world, const cGenome & in_genome, int update);
~cSpecies();
Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cStats.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -82,6 +82,7 @@
, tot_thresh_species(0)
, tot_lineages(0)
, tot_executed(0)
+ , last_update(0)
{
task_cur_count.Resize( m_world->GetNumTasks() );
task_last_count.Resize( m_world->GetNumTasks() );
@@ -340,8 +341,6 @@
void cStats::ProcessUpdate()
{
- static int last_update = 0;
-
// Increment the "avida_time"
if (sum_merit.Count() > 0 && sum_merit.Average() > 0) {
double delta = ((double)(current_update-last_update))/sum_merit.Average();
@@ -440,7 +439,7 @@
void cStats::PrintErrorData(const cString & filename)
{
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
assert(fp.good());
fp<< GetUpdate() << " " // 1
<< sum_merit.StdError() << " " // 2
@@ -462,7 +461,7 @@
void cStats::PrintVarianceData(const cString & filename)
{
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
assert(fp.good());
fp<<GetUpdate() << " " // 1
<< sum_merit.Variance() << " " // 2
@@ -579,7 +578,7 @@
void cStats::PrintTotalsData(const cString & filename)
{
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
assert(fp.good());
fp << GetUpdate() << " " // 1
<< (tot_executed+num_executed) << " " // 2
@@ -706,7 +705,7 @@
void cStats::PrintMutationData(const cString & filename)
{
- ofstream & fp = m_world->GetDataFileOFStream(filename);
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
assert(fp.good());
fp << GetUpdate() << " " // 1
<< isum_parent_dist.Ave() << " " // 2
Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/main/cStats.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -220,6 +220,9 @@
tArray<cString> inst_names;
tArray<cString> reaction_names;
tArray<cString> resource_names;
+
+ // State variables
+ int last_update;
public:
cStats(cWorld* world);
Modified: development/source/testsuites/unit_testsuites/level_1/code_label.t.cc
===================================================================
--- development/source/testsuites/unit_testsuites/level_1/code_label.t.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/testsuites/unit_testsuites/level_1/code_label.t.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -75,7 +75,7 @@
class cTestSaveState : public cTestCase {
public: virtual void test() {
cout << __PRETTY_FUNCTION__ << " is not implemented," << endl <<
- "because void cCodeLabel::SaveState(ostream &) is not implemented."
+ "because void cCodeLabel::SaveState(ostream&) is not implemented."
<< endl;
} };
class cTestLoadState : public cTestCase {
Modified: development/source/tools/cDataEntry.cc
===================================================================
--- development/source/tools/cDataEntry.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/cDataEntry.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -10,7 +10,7 @@
#endif
-std::ostream & operator << (std::ostream & out, cDataEntry & entry)
+std::ostream& operator << (std::ostream& out, cDataEntry & entry)
{
entry.Print(out);
return out;
Modified: development/source/tools/cDataEntry.h
===================================================================
--- development/source/tools/cDataEntry.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/cDataEntry.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -35,9 +35,9 @@
const cString & GetNull() const { return null_value; }
const cString & GetHtmlCellFlags() const { return html_table_flags; }
- virtual bool Print(std::ostream & fp) const { (void) fp; return false; }
+ virtual bool Print(std::ostream& fp) const { (void) fp; return false; }
};
-std::ostream & operator << (std::ostream & out, cDataEntry & entry);
+std::ostream& operator << (std::ostream& out, cDataEntry & entry);
#endif
Modified: development/source/tools/cDataFile.h
===================================================================
--- development/source/tools/cDataFile.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/cDataFile.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -82,7 +82,7 @@
*
* @return The output stream corresponding to the file.
**/
- std::ofstream & GetOFStream() { return m_fp; }
+ std::ofstream& GetOFStream() { return m_fp; }
/**
* Outputs a value into the data file.
Modified: development/source/tools/cDataManager_Base.cc
===================================================================
--- development/source/tools/cDataManager_Base.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/cDataManager_Base.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -53,7 +53,7 @@
}
- ofstream & fp = data_file.GetOFStream();
+ ofstream& fp = data_file.GetOFStream();
while (row_entries.GetSize() > 0) {
cString cur_entry( row_entries.Pop(sep) );
if ( Print(cur_entry, fp) == false ) {
Modified: development/source/tools/cInitFile.cc
===================================================================
--- development/source/tools/cInitFile.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/cInitFile.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -102,7 +102,7 @@
cString save_filename(GetFilename());
if (in_filename != "") save_filename = in_filename;
- ofstream fp_save(save_filename());
+ ofstream fp_save(save_filename);
// Go through the lines saving them...
for (int i = 0; i < line_array.GetSize(); i++) {
Modified: development/source/tools/cMerit.cc
===================================================================
--- development/source/tools/cMerit.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/cMerit.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -7,10 +7,8 @@
#include "cMerit.h"
-
using namespace std;
-
void cMerit::UpdateValue(double in_value){
const int max_bits = sizeof(unsigned int)*8;
static double mult[max_bits];
@@ -29,7 +27,6 @@
}
}
-
value = in_value;
double mant = frexp (value , &bits);
@@ -49,7 +46,7 @@
}
-ostream & cMerit::BinaryPrint(ostream & os) const {
+ostream& cMerit::BinaryPrint(ostream& os) const {
for( int i=GetNumBits()-1; i>=0; --i ){
os<<GetBit(i);
}
@@ -82,7 +79,7 @@
-ostream & operator<<(ostream & os, const cMerit & merit){
+ostream& operator<<(ostream& os, const cMerit & merit){
os<<merit.GetDouble();
return os;
}
Modified: development/source/tools/cMerit.h
===================================================================
--- development/source/tools/cMerit.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/cMerit.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -75,9 +75,9 @@
double CalcFitness(int gestation_time) const {
return ( gestation_time != 0 ) ? value / ((double) gestation_time) : 0; }
- std::ostream & BinaryPrint(std::ostream & os = std::cout) const ;
+ std::ostream& BinaryPrint(std::ostream& os = std::cout) const ;
};
-std::ostream & operator<<(std::ostream & os, const cMerit & merit);
+std::ostream& operator<<(std::ostream& os, const cMerit & merit);
#endif
Modified: development/source/tools/cString.cc
===================================================================
--- development/source/tools/cString.cc 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/cString.cc 2005-11-10 21:12:24 UTC (rev 387)
@@ -633,7 +633,7 @@
return in;
}
-ostream & operator << (ostream & out, const cString & string)
+ostream& operator << (ostream& out, const cString & string)
{
out << string.GetData();
return out;
Modified: development/source/tools/cString.h
===================================================================
--- development/source/tools/cString.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/cString.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -564,7 +564,7 @@
// iostream input
std::istream & operator >> (std::istream & in, cString & string);
-std::ostream & operator << (std::ostream & out, const cString & string);
+std::ostream& operator << (std::ostream& out, const cString & string);
// }}}
Modified: development/source/tools/tArgDataEntry.h
===================================================================
--- development/source/tools/tArgDataEntry.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/tArgDataEntry.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -33,7 +33,7 @@
: tDataEntryBase<T>(_name, _desc, _null, _html_cell),
DataRetrieval(_funR), DataCompare(_funC), arg(_arg) { ; }
- bool Print(std::ostream & fp) const {
+ bool Print(std::ostream& fp) const {
if (this->target == NULL) return false;
fp << (this->target->*DataRetrieval)(arg);
return true;
Modified: development/source/tools/tBuffer.h
===================================================================
--- development/source/tools/tBuffer.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/tBuffer.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -66,7 +66,7 @@
{ return (total <= data.GetSize()) ? total : data.GetSize(); }
int GetNum() const { return total - last_total; }
- void SaveState(std::ostream & fp) {
+ void SaveState(std::ostream& fp) {
assert(fp.good());
fp << "tBuffer" << " ";
fp << data.GetSize() << " ";
Modified: development/source/tools/tDataEntry.h
===================================================================
--- development/source/tools/tDataEntry.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/tDataEntry.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -41,7 +41,7 @@
: tDataEntryBase<T>(_name, _desc, _null, _html_cell), DataRetrieval(_funR),
DataSet(_funS), DataCompare(_funC) { ; }
- bool Print(std::ostream & fp) const {
+ bool Print(std::ostream& fp) const {
if (this->target == NULL) return false;
fp << (this->target->*DataRetrieval)();
return true;
Modified: development/source/tools/tDataEntryBase.h
===================================================================
--- development/source/tools/tDataEntryBase.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/tDataEntryBase.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -30,11 +30,11 @@
void SetTarget(T * _target) { target = _target; }
- virtual bool Print(std::ostream & fp) const { (void) fp; return false; }
+ virtual bool Print(std::ostream& fp) const { (void) fp; return false; }
virtual int Compare(T * other) const { (void) other; return 0; }
virtual bool Set(const cString & value) { (void) value; return false; }
- void HTMLPrint(std::ostream & fp, int compare=0, bool print_text=true) {
+ void HTMLPrint(std::ostream& fp, int compare=0, bool print_text=true) {
fp << "<td " << GetHtmlCellFlags() << " ";
if (compare == -2) {
fp << "bgcolor=\"#FF0000\">";
Modified: development/source/tools/tDataEntryCommand.h
===================================================================
--- development/source/tools/tDataEntryCommand.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/tDataEntryCommand.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -40,10 +40,10 @@
{ return data_entry->GetHtmlCellFlags(); }
void SetTarget(T * _target) { data_entry->SetTarget(_target); }
- bool Print(std::ostream & fp) const { return data_entry->Print(fp); }
+ bool Print(std::ostream& fp) const { return data_entry->Print(fp); }
int Compare(T * other) const { return data_entry->Compare(other); }
bool SetValue(const cString & value) { return data_entry->Set(value); }
- void HTMLPrint(std::ostream & fp, int compare=0, bool print_text=true)
+ void HTMLPrint(std::ostream& fp, int compare=0, bool print_text=true)
{ data_entry->HTMLPrint(fp, compare, print_text); }
};
Modified: development/source/tools/tDataManager.h
===================================================================
--- development/source/tools/tDataManager.h 2005-11-10 02:28:28 UTC (rev 386)
+++ development/source/tools/tDataManager.h 2005-11-10 21:12:24 UTC (rev 387)
@@ -52,7 +52,7 @@
return true;
}
- bool Print(const cString & name, std::ostream & fp) {
+ bool Print(const cString & name, std::ostream& fp) {
tDataEntryBase<T> * cur_entry = NULL;
if (entry_dict.Find(name, cur_entry) == false) return false;
cur_entry->Print(fp);
More information about the Avida-cvs
mailing list