[avida-cvs] avida CVS commits: /current/source/main analyze.cc analyze.hh

mercere99 avida-cvs at alife.org
Thu Oct 30 21:42:29 PST 2003


mercere99		Thu Oct 30 13:42:29 2003 EDT

  Modified files:              
    /avida/current/source/main	analyze.cc analyze.hh 
  Log:
  Added a new analyze mode command "DETAIL_TIMELINE" which works identically
  to the detail command except that it shows per-update results instead of per
  genotype.
  
  The format is:
    DETAIL_TIMELINE <filename> <update step> <max update> <settings>  [...]
  
  So, for example:
  
    DETAIL_TIMELINE lineage.dat 100 100000 depth fitness length
  
  would have one line for every 100 updates from 0 to 100,000 displaying which
  member of the lineage was active at that point along with its statistics
  (depth, fitness and length in this case).  Update number will always be the
  first column (you do not explicitly list this.)
  
  
Index: avida/current/source/main/analyze.cc
diff -u avida/current/source/main/analyze.cc:1.80 avida/current/source/main/analyze.cc:1.81
--- avida/current/source/main/analyze.cc:1.80	Wed Oct 15 12:57:24 2003
+++ avida/current/source/main/analyze.cc	Thu Oct 30 13:42:28 2003
@@ -995,13 +995,60 @@
 }
 
 
+void cAnalyze::CommandDetailTimeline(cString cur_string)
+{
+  if (verbose == true) cout << "Detailing batch "
+			    << cur_batch << " based on time" << endl;
+  else cout << "Detailing..." << endl;
+
+  // Load in the variables...
+  cString filename("detail_timeline.dat");
+  int time_step = 100;
+  int max_time = 100000;
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  if (cur_string.GetSize() != 0) time_step = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) max_time = cur_string.PopWord().AsInt();
+
+  if (verbose == true) {
+    cout << "  Time step = " << time_step << endl
+	 << "  Max time = " << max_time << endl;
+  }
+
+  // Construct a linked list of details needed...
+  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
+  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
+  LoadGenotypeDataList(cur_string, output_list);
+
+  // Determine the file type...
+  int file_type = FILE_TYPE_TEXT;
+  cString file_extension(filename);
+  while (file_extension.Find('.') != -1) file_extension.Pop('.');
+  if (file_extension == "html") file_type = FILE_TYPE_HTML;
+
+  // Setup the file...
+  if (filename == "cout") {
+    CommandDetail_Header(cout, file_type, output_it, time_step);
+    CommandDetail_Body(cout, file_type, output_it, time_step, max_time);
+  } else {
+    ofstream & fp = data_file_manager.GetOFStream(filename);
+    CommandDetail_Header(fp, file_type, output_it, time_step);
+    CommandDetail_Body(fp, file_type, output_it, time_step, max_time);
+  }
+
+  // And clean up...
+  while (output_list.GetSize() != 0) delete output_list.Pop();
+}
+
+
 void cAnalyze::CommandDetail_Header(ostream & fp, int format_type,
-	    tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
+	    tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
+	    int time_step)
 {
   // Write out the header on the file
   if (format_type == FILE_TYPE_TEXT) {
     fp << "#filetype genotype_data" << endl;
     fp << "#format ";
+    if (time_step > 0) fp << "update ";
     while (output_it.Next() != NULL) {
       const cString & entry_name = output_it.Get()->GetName();
       fp << entry_name << " ";
@@ -1011,6 +1058,7 @@
     // Give the more human-readable legend.
     fp << "# Legend:" << endl;
     int count = 0;
+    if (time_step > 0) fp << "# " << ++count << ": Update" << endl;
     while (output_it.Next() != NULL) {
       const cString & entry_desc = output_it.Get()->GetDesc();
       fp << "# " << ++count << ": " << entry_desc << endl;
@@ -1029,6 +1077,7 @@
        << "<center>" << endl
        << "<table border=1 cellpadding=2><tr>" << endl;
 
+    if (time_step > 0) fp << "<th bgcolor=\"#AAAAFF\">Update ";
     while (output_it.Next() != NULL) {
       const cString & entry_desc = output_it.Get()->GetDesc();
       fp << "<th bgcolor=\"#AAAAFF\">" << entry_desc << " ";
@@ -1041,24 +1090,35 @@
 
 
 void cAnalyze::CommandDetail_Body(ostream & fp, int format_type,
-	    tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
+	    tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
+	    int time_step, int max_time)
 {
   // Loop through all of the genotypes in this batch...
   tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  cAnalyzeGenotype * last_genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
+  cAnalyzeGenotype * cur_genotype = batch_it.Next();
+  cAnalyzeGenotype * next_genotype = batch_it.Next();
+  cAnalyzeGenotype * prev_genotype = NULL;
+
+  int cur_time = 0;
+  while (cur_genotype != NULL && cur_time <= max_time) {
     output_it.Reset();
     tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
-    if (format_type == FILE_TYPE_HTML) fp << "<tr>";
+    if (format_type == FILE_TYPE_HTML) {
+      fp << "<tr>";
+      if (time_step > 0) fp << "<td>" << cur_time << " ";
+    }
+    else if (time_step > 0) {  // TEXT file, printing times...
+      fp << cur_time << " ";
+    }
+
     while ((data_command = output_it.Next()) != NULL) {
-      data_command->SetTarget(genotype);
-      genotype->SetSpecialArgs(data_command->GetArgs());
+      data_command->SetTarget(cur_genotype);
+      cur_genotype->SetSpecialArgs(data_command->GetArgs());
       if (format_type == FILE_TYPE_HTML) {
 	int compare = 0;
-	if (last_genotype) {
-	  last_genotype->SetSpecialArgs(data_command->GetArgs());
-	  compare = data_command->Compare(last_genotype);
+	if (prev_genotype) {
+	  prev_genotype->SetSpecialArgs(data_command->GetArgs());
+	  compare = data_command->Compare(prev_genotype);
 	}
 	data_command->HTMLPrint(fp, compare);
       }
@@ -1068,7 +1128,23 @@
     }
     if (format_type == FILE_TYPE_HTML) fp << "</tr>";
     fp << endl;
-    last_genotype = genotype;
+
+    cur_time += time_step;
+    if (time_step > 0) {
+      while (next_genotype && next_genotype->GetUpdateBorn() < cur_time) {
+	prev_genotype = cur_genotype;
+	cur_genotype = next_genotype;
+	next_genotype = batch_it.Next();
+      }
+    }
+    else {
+      // Always moveon if we're not basing this on time, or if we've run out
+      // of genotypes.
+      prev_genotype = cur_genotype;
+      cur_genotype = next_genotype;
+      next_genotype = batch_it.Next();
+    }
+
   }
 
   // If in HTML mode, we need to end the file...
@@ -4378,6 +4454,7 @@
   AddLibraryDef("TRACE", &cAnalyze::CommandTrace);
   AddLibraryDef("PRINT_TASKS", &cAnalyze::CommandPrintTasks);
   AddLibraryDef("DETAIL", &cAnalyze::CommandDetail);
+  AddLibraryDef("DETAIL_TIMELINE", &cAnalyze::CommandDetailTimeline);
   AddLibraryDef("DETAIL_BATCHES", &cAnalyze::CommandDetailBatches);
   AddLibraryDef("DETAIL_INDEX", &cAnalyze::CommandDetailIndex);
 
Index: avida/current/source/main/analyze.hh
diff -u avida/current/source/main/analyze.hh:1.47 avida/current/source/main/analyze.hh:1.48
--- avida/current/source/main/analyze.hh:1.47	Wed Oct 15 12:57:25 2003
+++ avida/current/source/main/analyze.hh	Thu Oct 30 13:42:28 2003
@@ -412,9 +412,11 @@
 
   // Comamnd helpers...
   void CommandDetail_Header(std::ostream & fp, int format_type,
-	    tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
+	    tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
+	    int time_step=-1);
   void CommandDetail_Body(std::ostream & fp, int format_type,
-	    tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
+	    tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
+	    int time_step=-1, int max_time=1);
 private:
   // Loading methods...
   void LoadOrganism(cString cur_string);
@@ -437,6 +439,7 @@
   void CommandTrace(cString cur_string);
   void CommandPrintTasks(cString cur_string);
   void CommandDetail(cString cur_string);
+  void CommandDetailTimeline(cString cur_string);
   void CommandDetailBatches(cString cur_string);
   void CommandDetailIndex(cString cur_string);
 






More information about the Avida-cvs mailing list