[Avida-SVN] r3444 - in development/source: actions main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Sun Oct 4 11:52:02 PDT 2009


Author: brysonda
Date: 2009-10-04 14:52:02 -0400 (Sun, 04 Oct 2009)
New Revision: 3444

Modified:
   development/source/actions/PrintActions.cc
   development/source/main/cStats.cc
Log:
Correct PrintGenotypeColorGrid so that it performs the same coloring mechanics of the viewer.  This means that colors stability is preserved and only given to defined color threshold genotypes (top 10 by default, like the viewer).

Also add support for printing out min_fitness in the PrintData action (cStats data manager).

Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc	2009-10-04 02:23:55 UTC (rev 3443)
+++ development/source/actions/PrintActions.cc	2009-10-04 18:52:02 UTC (rev 3444)
@@ -2642,29 +2642,50 @@
 {
 private:
   int m_num_colors;
+  int m_threshold;
   cString m_filename;
+  tArray<cGenotype*> m_genotype_chart;
   
 public:
-  cActionDumpGenotypeColorGrid(cWorld* world, const cString& args) : cAction(world, args), m_num_colors(12), m_filename("")
+  cActionDumpGenotypeColorGrid(cWorld* world, const cString& args)
+    : cAction(world, args), m_num_colors(12), m_threshold(10), m_filename(""), m_genotype_chart(0)
   {
     cString largs(args);
     if (largs.GetSize()) m_num_colors = largs.PopWord().AsInt();
-    if (largs.GetSize()) m_filename = largs.PopWord();  
+    if (largs.GetSize()) m_threshold = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_filename = largs.PopWord();
+    
+    m_genotype_chart.Resize(m_num_colors, NULL);
   }
+  
   static const cString GetDescription() { return "Arguments: [int num_colors=12] [string fname='']"; }
+  
+  
   void Process(cAvidaContext& ctx)
   {
-    cGenotype** genotype_chart = new cGenotype*[m_num_colors];
-    cGenotype* temp_gen = m_world->GetClassificationManager().GetBestGenotype();
+    // Update current entries in the color chart
+    int pos = -1;
     for (int i = 0; i < m_num_colors; i++) {
-      if (temp_gen) {
-        genotype_chart[i] = temp_gen;
-        temp_gen = temp_gen->GetNext();
-      } else {
-        genotype_chart[i] = NULL;
+      if (m_genotype_chart[i]) {
+        pos = m_world->GetClassificationManager().FindPos(*(m_genotype_chart[i]), m_num_colors);
+        if (pos < 0 || pos >= m_num_colors) m_genotype_chart[i] = NULL;
       }
     }
     
+    // Add new entries where possible
+    cGenotype* temp_gen = m_world->GetClassificationManager().GetBestGenotype();
+    for (int i = 0; i < m_threshold && temp_gen; i++, temp_gen = temp_gen->GetNext()) {
+      if (!isInChart(temp_gen)) {
+        // Add to the genotype chart
+        for (int j = 0; j < m_num_colors; j++) {
+          if (m_genotype_chart[j] == NULL) {
+            m_genotype_chart[j] = temp_gen;
+            break;
+          }
+        }
+      }
+    }
+    
     cString filename(m_filename);
     if (filename == "") filename.Set("grid_genotype_color-%d.dat", m_world->GetStats().GetUpdate());
     ofstream& fp = m_world->GetDataFileOFStream(filename);
@@ -2675,19 +2696,26 @@
         temp_gen = (cell.IsOccupied()) ? cell.GetOrganism()->GetGenotype() : NULL;
         if (temp_gen) {
           int color = 0;
-          for (; color < m_num_colors; color++) if (genotype_chart[color] == temp_gen) break;
+          for (; color < m_num_colors; color++) if (m_genotype_chart[color] == temp_gen) break;
           if (color == m_num_colors && temp_gen->GetThreshold()) color++;
-          fp << (color) << " ";
+          fp << color << " ";
         } else {
           fp << "-1 ";
         }
       }
       fp << endl;
     }
-    m_world->GetDataFileManager().Remove(filename);
-   
-    delete genotype_chart;
+    m_world->GetDataFileManager().Remove(filename);   
   }
+  
+private:
+  inline bool isInChart(cGenotype* gen)
+  {
+    for (int i = 0; i < m_num_colors; i++) {
+      if (m_genotype_chart[i] == gen) return true;
+    }
+    return false;    
+  }
 };
 
 

Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc	2009-10-04 02:23:55 UTC (rev 3443)
+++ development/source/main/cStats.cc	2009-10-04 18:52:02 UTC (rev 3444)
@@ -372,6 +372,8 @@
   // And a couple of Maximums
   data_manager.Add("max_fitness", "Maximum Fitness in Population", &cStats::GetMaxFitness);
   data_manager.Add("max_merit",   "Maximum Merit in Population",   &cStats::GetMaxMerit);
+
+  data_manager.Add("min_fitness", "Minimum Fitness in Population", &cStats::GetMinFitness);
 }
 
 void cStats::ZeroTasks()




More information about the Avida-cvs mailing list