[Avida-cvs] [avida-svn] r927 - in development/source: actions analyze main tools
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Tue Sep 5 15:21:54 PDT 2006
Author: brysonda
Date: 2006-09-05 18:21:54 -0400 (Tue, 05 Sep 2006)
New Revision: 927
Modified:
development/source/actions/LandscapeActions.cc
development/source/actions/PrintActions.cc
development/source/analyze/cAnalyze.cc
development/source/main/cLandscape.cc
development/source/main/cLandscape.h
development/source/tools/cDataFile.cc
development/source/tools/cDataFile.h
Log:
Update various cLandscape related output files to use the new cDataFile based PrintStats method. Added anonymous column support to cDataFile, for use with histogram type output, etc.
Modified: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc 2006-09-05 13:51:40 UTC (rev 926)
+++ development/source/actions/LandscapeActions.cc 2006-09-05 22:21:54 UTC (rev 927)
@@ -243,11 +243,11 @@
update = m_world->GetStats().GetUpdate();
}
- std::ofstream& sfile = m_world->GetDataFileOFStream(m_sfilename);
+ cDataFile& df = m_world->GetDataFile(m_sfilename);
while (land = m_batch.Pop()) {
- land->PrintStats(sfile, update);
- if (m_efilename.GetSize()) land->PrintEntropy(m_world->GetDataFileOFStream(m_efilename));
- if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFileOFStream(m_cfilename));
+ land->PrintStats(df, update);
+ if (m_efilename.GetSize()) land->PrintEntropy(m_world->GetDataFile(m_efilename));
+ if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFile(m_cfilename));
delete land;
}
}
@@ -315,10 +315,10 @@
update = m_world->GetStats().GetUpdate();
}
- std::ofstream& sfile = m_world->GetDataFileOFStream(m_sfilename);
+ cDataFile& df = m_world->GetDataFile(m_sfilename);
while (land = m_batch.Pop()) {
- land->PrintStats(sfile, update);
- if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFileOFStream(m_cfilename));
+ land->PrintStats(df, update);
+ if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFile(m_cfilename));
delete land;
}
}
@@ -386,10 +386,10 @@
update = m_world->GetStats().GetUpdate();
}
- std::ofstream& sfile = m_world->GetDataFileOFStream(m_sfilename);
+ cDataFile& df = m_world->GetDataFile(m_sfilename);
while (land = m_batch.Pop()) {
- land->PrintStats(sfile, update);
- if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFileOFStream(m_cfilename));
+ land->PrintStats(df, update);
+ if (m_cfilename.GetSize()) land->PrintSiteCount(m_world->GetDataFile(m_cfilename));
delete land;
}
}
@@ -559,9 +559,9 @@
update = m_world->GetStats().GetUpdate();
}
- std::ofstream& outfile = m_world->GetDataFileOFStream(m_filename);
+ cDataFile& df = m_world->GetDataFile(m_filename);
while (land = m_batch.Pop()) {
- land->PrintStats(outfile, update);
+ land->PrintStats(df, update);
delete land;
}
}
@@ -628,9 +628,9 @@
update = m_world->GetStats().GetUpdate();
}
- std::ofstream& outfile = m_world->GetDataFileOFStream(m_filename);
+ cDataFile& df = m_world->GetDataFile(m_filename);
while (land = m_batch.Pop()) {
- land->PrintStats(outfile, update);
+ land->PrintStats(df, update);
delete land;
}
}
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2006-09-05 13:51:40 UTC (rev 926)
+++ development/source/actions/PrintActions.cc 2006-09-05 22:21:54 UTC (rev 927)
@@ -195,7 +195,7 @@
df.Write(m_world->GetStats().GetUpdate(), "Update");
df.Write(min, "Minimum");
df.Write(max, "Maximum");
- for (int i = 0; i < n.GetSize(); i++) df.Write(n[i], "");
+ for (int i = 0; i < n.GetSize(); i++) df.WriteAnonymous(n[i]);
df.Endl();
}
};
@@ -301,7 +301,7 @@
// Actual output
cDataFile& df = m_world->GetDataFile(m_filename);
df.Write(m_world->GetStats().GetUpdate(), "Update");
- for (int i = 0; i < hist.GetSize(); i++) df.Write(hist[i], "");
+ for (int i = 0; i < hist.GetSize(); i++) df.WriteAnonymous(hist[i]);
df.Endl();
}
};
@@ -638,7 +638,7 @@
// now output the fitness histo
for (int i = 0; i < histo.GetSize(); i++)
- hdf.Write(static_cast<double>(histo[i]) / static_cast<double>(nhist_tot), "");
+ hdf.WriteAnonymous(static_cast<double>(histo[i]) / static_cast<double>(nhist_tot));
hdf.Endl();
@@ -649,7 +649,7 @@
// now output the fitness histo
for (int i = 0; i < histo_testCPU.GetSize(); i++)
- tdf.Write(static_cast<double>(histo_testCPU[i]) / static_cast<double>(nhist_tot_testCPU), "");
+ tdf.WriteAnonymous(static_cast<double>(histo_testCPU[i]) / static_cast<double>(nhist_tot_testCPU));
tdf.Endl();
}
}
@@ -975,7 +975,7 @@
df.Write(m_world->GetStats().GetUpdate(), "Update");
for(int i = 0; i < tasks.GetSize(); i++) {
- df.Write(tasks[i], "");
+ df.WriteAnonymous(tasks[i]);
}
df.Endl();
}
@@ -1096,9 +1096,9 @@
// Print all needed files.
if (i < m_lines_saved) {
- df_abundance.Write(count, "");
- df_var.Write(inst_hist[i].GetCountVariance(), "");
- df_entropy.Write(entropy, "");
+ df_abundance.WriteAnonymous(count);
+ df_var.WriteAnonymous(inst_hist[i].GetCountVariance());
+ df_entropy.WriteAnonymous(entropy);
}
}
Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc 2006-09-05 13:51:40 UTC (rev 926)
+++ development/source/analyze/cAnalyze.cc 2006-09-05 22:21:54 UTC (rev 927)
@@ -3509,16 +3509,16 @@
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);
+ cDataFile& df = m_world->GetDataFile(filename);
// Loop through all of the genotypes in this batch...
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
cAnalyzeGenotype * genotype = NULL;
while ((genotype = batch_it.Next()) != NULL) {
cLandscape landscape(m_world, genotype->GetGenome(), inst_set);
- if (test_num == 1) landscape.TestAllPairs(m_ctx, fp);
- else landscape.TestPairs(m_ctx, test_num,fp);
- landscape.PrintStats(fp);
+ if (test_num == 1) landscape.TestAllPairs(m_ctx, df.GetOFStream());
+ else landscape.TestPairs(m_ctx, test_num, df.GetOFStream());
+ landscape.PrintStats(df);
}
}
Modified: development/source/main/cLandscape.cc
===================================================================
--- development/source/main/cLandscape.cc 2006-09-05 13:51:40 UTC (rev 926)
+++ development/source/main/cLandscape.cc 2006-09-05 22:21:54 UTC (rev 927)
@@ -815,42 +815,6 @@
}
-void cLandscape::PrintStats(ofstream& fp, int update)
-{
- fp << update << " " // 1
- << GetProbDead() << " " // 2
- << GetProbNeg() << " " // 3
- << GetProbNeut() << " " // 4
- << GetProbPos() << " " // 5
- // << pos_size << " " // 6
- // << pos_count << " " // 6
- << GetAvPosSize() << " " // 6
- << GetAvNegSize() << " " // 7
- << total_count << " " // 8
- << distance << " " // 9
- // << neut_min << " " // 10
- // << neut_max << " " // 10
- // << nHardware::FITNESS_NEUTRAL_MIN << " " // 10
- // << nHardware::FITNESS_NEUTRAL_MAX << " " // 10
- << base_fitness << " " // 10
- << base_merit << " " // 11
- << base_gestation << " " // 12
- << peak_fitness << " " // 13
- << GetAveFitness() << " " // 14
- << GetAveSqrFitness() << " " // 15
- << total_entropy << " " // 16
- << complexity << " " // 17
- << GetProbEpiDead() << " " // 18
- << GetProbEpiPos() << " " // 19
- << GetProbEpiNeg() << " " // 20
- << GetProbNoEpi() << " " // 21
- << GetAvPosEpiSize() << " " // 22
- << GetAvNegEpiSize() << " " // 23
- << GetAvNoEpiSize() << " " // 24
- << total_epi_count << endl; // 25
- fp.flush();
-}
-
void cLandscape::PrintStats(cDataFile& df, int update)
{
df.Write(update, "Update");
@@ -881,23 +845,19 @@
df.Endl();
}
-void cLandscape::PrintEntropy(ofstream& fp)
+void cLandscape::PrintEntropy(cDataFile& df)
{
- double max_ent = log((double) inst_set.GetSize());
- for (int j = 0; j < base_genome.GetSize(); j++) {
- fp << (log((double) site_count[j] + 1) / max_ent) << " ";
- }
- fp << endl;
- fp.flush();
+ df.WriteComment("Entropy Data");
+ double max_ent = log(static_cast<double>(inst_set.GetSize()));
+ for (int j = 0; j < base_genome.GetSize(); j++) df.WriteAnonymous(log(static_cast<double>(site_count[j] + 1)) / max_ent);
+ df.Endl();
}
-void cLandscape::PrintSiteCount(ofstream& fp)
+void cLandscape::PrintSiteCount(cDataFile& df)
{
- for (int j = 0; j < base_genome.GetSize(); j++) {
- fp << site_count[j] << " ";
- }
- fp << endl;
- fp.flush();
+ df.WriteComment("Site Counts");
+ for (int j = 0; j < base_genome.GetSize(); j++) df.WriteAnonymous(site_count[j]);
+ df.Endl();
}
void cLandscape::PrintBase(cString filename)
Modified: development/source/main/cLandscape.h
===================================================================
--- development/source/main/cLandscape.h 2006-09-05 13:51:40 UTC (rev 926)
+++ development/source/main/cLandscape.h 2006-09-05 22:21:54 UTC (rev 927)
@@ -131,10 +131,9 @@
void HillClimb_Neut(cAvidaContext& ctx, std::ofstream& fp);
void HillClimb_Rand(cAvidaContext& ctx, std::ofstream& fp);
- void PrintStats(std::ofstream& fp, int update = -1);
void PrintStats(cDataFile& df, int update = -1);
- void PrintEntropy(std::ofstream& fp);
- void PrintSiteCount(std::ofstream& fp);
+ void PrintEntropy(cDataFile& fp);
+ void PrintSiteCount(cDataFile& fp);
void PrintBase(cString filename);
void PrintPeak(cString filename);
Modified: development/source/tools/cDataFile.cc
===================================================================
--- development/source/tools/cDataFile.cc 2006-09-05 13:51:40 UTC (rev 926)
+++ development/source/tools/cDataFile.cc 2006-09-05 22:21:54 UTC (rev 927)
@@ -28,33 +28,33 @@
}
-void cDataFile::Write( double x, const char * descr )
+void cDataFile::Write( double x, const char* descr )
{
- if ( !m_descr_written ){
- m_data += cStringUtil::Stringf( "%f ", x );
+ if (!m_descr_written) {
+ m_data += cStringUtil::Stringf("%f ", x);
WriteColumnDesc(descr);
- }
- else m_fp << x << " ";
+ } else
+ m_fp << x << " ";
}
-void cDataFile::Write( int i, const char * descr )
+void cDataFile::Write(int i, const char* descr)
{
- if ( !m_descr_written ){
- m_data += cStringUtil::Stringf( "%i ", i );
+ if (!m_descr_written) {
+ m_data += cStringUtil::Stringf("%i ", i);
WriteColumnDesc(descr);
- }
- else m_fp << i << " ";
+ } else
+ m_fp << i << " ";
}
-void cDataFile::Write( const char * data_str, const char * descr )
+void cDataFile::Write(const char* data_str, const char* descr)
{
- if ( !m_descr_written ) {
- m_data += cStringUtil::Stringf( "%s ", data_str );
+ if (!m_descr_written) {
+ m_data += cStringUtil::Stringf("%s ", data_str);
WriteColumnDesc(descr);
- }
- else m_fp << data_str << " ";
+ } else
+ m_fp << data_str << " ";
}
Modified: development/source/tools/cDataFile.h
===================================================================
--- development/source/tools/cDataFile.h 2006-09-05 13:51:40 UTC (rev 926)
+++ development/source/tools/cDataFile.h 2006-09-05 22:21:54 UTC (rev 927)
@@ -90,11 +90,14 @@
* will be written only once, before the first data line has been finished.
**/
- void Write( double x, const char* descr );
- void Write( int i, const char* descr );
- void Write( const char* data_str, const char* descr );
- void WriteBlockElement (double x, int element, int x_size );
- void WriteBlockElement (int i, int element, int x_size );
+ void Write(double x, const char* descr);
+ void Write(int i, const char* descr);
+ void Write(const char* data_str, const char* descr);
+ inline void WriteAnonymous(double x) { m_fp << x << " "; }
+ inline void WriteAnonymous(int i) { m_fp << i << " "; }
+ inline void WriteAnonymous(const char* data_str) { m_fp << data_str << " "; }
+ void WriteBlockElement(double x, int element, int x_size);
+ void WriteBlockElement(int i, int element, int x_size);
/**
* Writes a descriptive string into a data file. The string is only
More information about the Avida-cvs
mailing list