[Avida-SVN] r1745 - in branches/vo: Avida.xcodeproj source/drivers source/targets/avida source/targets/avida-viewer

michaelvo at myxo.css.msu.edu michaelvo at myxo.css.msu.edu
Tue Jul 3 10:53:13 PDT 2007


Author: michaelvo
Date: 2007-07-03 13:53:13 -0400 (Tue, 03 Jul 2007)
New Revision: 1745

Modified:
   branches/vo/Avida.xcodeproj/project.pbxproj
   branches/vo/source/drivers/cDefaultRunDriver.cc
   branches/vo/source/drivers/cDefaultRunDriver.h
   branches/vo/source/targets/avida-viewer/cTextViewerAnalyzeDriver.cc
   branches/vo/source/targets/avida-viewer/cTextViewerAnalyzeDriver.h
   branches/vo/source/targets/avida-viewer/cTextViewerDriver.cc
   branches/vo/source/targets/avida-viewer/cTextViewerDriver.h
   branches/vo/source/targets/avida-viewer/cTextViewerDriver_Base.cc
   branches/vo/source/targets/avida-viewer/cTextViewerDriver_Base.h
   branches/vo/source/targets/avida/primitive.cc
Log:
Commit driver structure changes to newly created branch.

Modified: branches/vo/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/vo/Avida.xcodeproj/project.pbxproj	2007-07-03 17:44:48 UTC (rev 1744)
+++ branches/vo/Avida.xcodeproj/project.pbxproj	2007-07-03 17:53:13 UTC (rev 1745)
@@ -185,6 +185,7 @@
 		70B6514F0BEA6FCC002472ED /* main.cc in Sources */ = {isa = PBXBuildFile; fileRef = 701EF27E0BEA5D2300DAE168 /* main.cc */; };
 		70B651B70BEA9AEC002472ED /* unit-tests in CopyFiles */ = {isa = PBXBuildFile; fileRef = 70B6514C0BEA6FAD002472ED /* unit-tests */; };
 		70DCAC9C097AF7C0002F8733 /* primitive.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCAC9B097AF7C0002F8733 /* primitive.cc */; };
+		EACF11C10C35DDB300E6B02F /* cConsoleRunDriver.cc in Sources */ = {isa = PBXBuildFile; fileRef = EACF10E80C35A91A00E6B02F /* cConsoleRunDriver.cc */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXBuildRule section */
@@ -790,6 +791,8 @@
 		DCC315D0076253A5008F7A48 /* task_event_gen.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.cc; sourceTree = "<group>"; };
 		DCC315D1076253A5008F7A48 /* task_event_gen.old.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.old.cc; sourceTree = "<group>"; };
 		DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
+		EACF10E70C35A91A00E6B02F /* cConsoleRunDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cConsoleRunDriver.h; sourceTree = "<group>"; };
+		EACF10E80C35A91A00E6B02F /* cConsoleRunDriver.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cConsoleRunDriver.cc; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -1041,6 +1044,8 @@
 		70DCAC55097AF730002F8733 /* avida */ = {
 			isa = PBXGroup;
 			children = (
+				EACF10E80C35A91A00E6B02F /* cConsoleRunDriver.cc */,
+				EACF10E70C35A91A00E6B02F /* cConsoleRunDriver.h */,
 				70DCAC9B097AF7C0002F8733 /* primitive.cc */,
 			);
 			path = avida;
@@ -1866,6 +1871,7 @@
 			buildActionMask = 2147483647;
 			files = (
 				70DCAC9C097AF7C0002F8733 /* primitive.cc in Sources */,
+				EACF11C10C35DDB300E6B02F /* cConsoleRunDriver.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: branches/vo/source/drivers/cDefaultRunDriver.cc
===================================================================
--- branches/vo/source/drivers/cDefaultRunDriver.cc	2007-07-03 17:44:48 UTC (rev 1744)
+++ branches/vo/source/drivers/cDefaultRunDriver.cc	2007-07-03 17:53:13 UTC (rev 1745)
@@ -56,6 +56,16 @@
   delete m_world;
 }
 
+bool cDefaultRunDriver::UpdateProcess(const int UD_size, const double step_size, cAvidaContext& ctx, cPopulation& population)
+{
+  for (int i = 0; i < UD_size; i++) {
+    if (population.GetNumOrganisms() == 0) {
+      return true;
+    }
+    population.ProcessStep(ctx, step_size);
+  }
+  return false;
+}
 
 void cDefaultRunDriver::Run()
 {
@@ -97,13 +107,7 @@
     const int UD_size = ave_time_slice * population.GetNumOrganisms();
     const double step_size = 1.0 / (double) UD_size;
     
-    for (int i = 0; i < UD_size; i++) {
-      if (population.GetNumOrganisms() == 0) {
-        m_done = true;
-        break;
-      }
-      population.ProcessStep(ctx, step_size);
-    }
+    m_done = UpdateProcess(UD_size, step_size, ctx, population);
     
     // end of update stats...
     population.CalcUpdateStats();
@@ -113,22 +117,8 @@
       population.GetDeme(i).ProcessUpdate();
     }
     
-    // No viewer; print out status for this update....
-    if (m_world->GetVerbosity() > VERBOSE_SILENT) {
-      cout.setf(ios::left);
-      cout.setf(ios::showpoint);
-      cout << "UD: " << setw(6) << stats.GetUpdate() << "  "
-        << "Gen: " << setw(9) << setprecision(7) << stats.SumGeneration().Average() << "  "
-        << "Fit: " << setw(9) << setprecision(7) << stats.GetAveFitness() << "  "
-      //  << "Energy: " << setw(9) << setprecision(7) << stats.GetAveEnergy() << "  "
-//        << "Merit: " << setw(9) << setprecision(7) << stats.GetAveMerit() << "  "
-        << "Orgs: " << setw(6) << population.GetNumOrganisms() << "  "
-        << "Thrd: " << setw(6) << stats.GetNumThreads() << "  "
-        << "Para: " << stats.GetNumParasites()
-        << endl;
-    }
+    UpdateView();
     
-    
     // Do Point Mutations
     if (point_mut_prob > 0 ) {
       for (int i = 0; i < population.GetSize(); i++) {
@@ -143,6 +133,7 @@
   }
 }
 
+
 void cDefaultRunDriver::RaiseException(const cString& in_string)
 {
   cerr << "Error: " << in_string << endl;

Modified: branches/vo/source/drivers/cDefaultRunDriver.h
===================================================================
--- branches/vo/source/drivers/cDefaultRunDriver.h	2007-07-03 17:44:48 UTC (rev 1744)
+++ branches/vo/source/drivers/cDefaultRunDriver.h	2007-07-03 17:53:13 UTC (rev 1745)
@@ -34,6 +34,8 @@
 
 class cString;
 class cWorld;
+class cAvidaContext;
+class cPopulation;
 
 class cDefaultRunDriver : public cAvidaDriver, public cWorldDriver
 {
@@ -50,7 +52,11 @@
   cDefaultRunDriver(cWorld* world);
   ~cDefaultRunDriver();
   
+  virtual bool UpdateProcess( const int UD_size, const double step_size, cAvidaContext& ctx, cPopulation& population);
+  virtual void UpdateView() =0;
   void Run();
+
+
   
   // Driver Actions
   void SignalBreakpoint() { return; }

Modified: branches/vo/source/targets/avida/primitive.cc
===================================================================
--- branches/vo/source/targets/avida/primitive.cc	2007-07-03 17:44:48 UTC (rev 1744)
+++ branches/vo/source/targets/avida/primitive.cc	2007-07-03 17:53:13 UTC (rev 1745)
@@ -24,7 +24,7 @@
 #include "avida.h"
 #include "cAvidaConfig.h"
 #include "cDefaultAnalyzeDriver.h"
-#include "cDefaultRunDriver.h"
+#include "cConsoleRunDriver.h"
 #include "cWorld.h"
 #include "PlatformExpert.h"
 
@@ -44,7 +44,7 @@
   if (world->GetConfig().ANALYZE_MODE.Get() > 0) {
     driver = new cDefaultAnalyzeDriver(world, (world->GetConfig().ANALYZE_MODE.Get() == 2));
   } else {
-    driver = new cDefaultRunDriver(world);
+    driver = new cConsoleRunDriver(world);
   }
 
   cout << endl;

Modified: branches/vo/source/targets/avida-viewer/cTextViewerAnalyzeDriver.cc
===================================================================
--- branches/vo/source/targets/avida-viewer/cTextViewerAnalyzeDriver.cc	2007-07-03 17:44:48 UTC (rev 1744)
+++ branches/vo/source/targets/avida-viewer/cTextViewerAnalyzeDriver.cc	2007-07-03 17:53:13 UTC (rev 1745)
@@ -44,7 +44,7 @@
 
 
 cTextViewerAnalyzeDriver::cTextViewerAnalyzeDriver(cWorld* world, bool inter)
-  : cTextViewerDriver_Base(world), m_interactive(inter)
+  : cTextViewerDriver_Base(), m_interactive(inter), m_done(false)
 {
   m_view = new cAnalyzeView(world);
 

Modified: branches/vo/source/targets/avida-viewer/cTextViewerAnalyzeDriver.h
===================================================================
--- branches/vo/source/targets/avida-viewer/cTextViewerAnalyzeDriver.h	2007-07-03 17:44:48 UTC (rev 1744)
+++ branches/vo/source/targets/avida-viewer/cTextViewerAnalyzeDriver.h	2007-07-03 17:53:13 UTC (rev 1745)
@@ -28,9 +28,18 @@
 #include "cTextViewerDriver_Base.h"
 #endif
 
+#ifndef cAvidaDriver_h
+#include "cAvidaDriver.h"
+#endif
+
+#ifndef cWorldDriver_h
+#include "cWorldDriver.h"
+#endif
+
 class cAnalyzeView;
+class cWorld;
 
-class cTextViewerAnalyzeDriver : public cTextViewerDriver_Base
+class cTextViewerAnalyzeDriver : public cTextViewerDriver_Base, public cWorldDriver, public cAvidaDriver
 {
 private:
   cTextViewerAnalyzeDriver(); // @not_implemented
@@ -39,6 +48,9 @@
   
 protected:
   bool m_interactive;
+  bool m_done;
+  cWorld* m_world;
+
   
 public:
   cTextViewerAnalyzeDriver(cWorld* world, bool inter = false);

Modified: branches/vo/source/targets/avida-viewer/cTextViewerDriver.cc
===================================================================
--- branches/vo/source/targets/avida-viewer/cTextViewerDriver.cc	2007-07-03 17:44:48 UTC (rev 1744)
+++ branches/vo/source/targets/avida-viewer/cTextViewerDriver.cc	2007-07-03 17:53:13 UTC (rev 1745)
@@ -43,7 +43,7 @@
 
 
 cTextViewerDriver::cTextViewerDriver(cWorld* world)
-  : cTextViewerDriver_Base(world)
+  : cTextViewerDriver_Base(), cDefaultRunDriver(world)
 {
   m_view = new cView(world);
   m_view->SetViewMode(world->GetConfig().VIEW_MODE.Get());
@@ -59,101 +59,53 @@
   if (m_view != NULL) EndProg(0);
 }
 
-
-void cTextViewerDriver::Run()
+bool cTextViewerDriver::UpdateProcess( const int UD_size, const double step_size, cAvidaContext& ctx, cPopulation& population)
 {
-  cClassificationManager& classmgr = m_world->GetClassificationManager();
-  cPopulation& population = m_world->GetPopulation();
-  cStats& stats = m_world->GetStats();
-  
-  const int ave_time_slice = m_world->GetConfig().AVE_TIME_SLICE.Get();
-  const double point_mut_prob = m_world->GetConfig().POINT_MUT_PROB.Get();
-  
-  cAvidaContext ctx(m_world->GetRandom());
-  
-  while (!m_done) {
-    if (cChangeList* change_list = population.GetChangeList()) {
-      change_list->Reset();
-    }
-    
-    m_world->GetEvents(ctx);
-    if (m_done == true) break;
-    
-    // Increment the Update.
-    stats.IncCurrentUpdate();
-    
-    // Handle all data collection for previous update.
-    if (stats.GetUpdate() > 0) {
-      // Tell the stats object to do update calculations and printing.
-      stats.ProcessUpdate();
-      
-      // Update all the genotypes for the end of this update.
-      for (cGenotype * cur_genotype = classmgr.ResetThread(0);
-           cur_genotype != NULL && cur_genotype->GetThreshold();
-           cur_genotype = classmgr.NextGenotype(0)) {
-        cur_genotype->UpdateReset();
+  if (m_view->GetStepOrganism() != -1) {  // Yes we are!
+                                          // Keep the viewer informed about the organism we are stepping through...
+    for (int i = 0; i < UD_size; i++) {
+      if (population.GetNumOrganisms() == 0) {
+        return true;
       }
-    }
-    
-    
-    // Process the update.
-    const int UD_size = ave_time_slice * population.GetNumOrganisms();
-    const double step_size = 1.0 / (double) UD_size;
-    
-
-    // Are we stepping through an organism?
-    if (m_view->GetStepOrganism() != -1) {  // Yes we are!
-                                            // Keep the viewer informed about the organism we are stepping through...
-      for (int i = 0; i < UD_size; i++) {
-        const int next_id = population.ScheduleOrganism();
-        if (next_id == m_view->GetStepOrganism()) {
-          m_view->NotifyUpdate();
-          m_view->NewUpdate();
-          
-          // This is needed to have the top bar drawn properly; I'm not sure why...
-          static bool first_update = true;
-          if (first_update) {
-            m_view->Refresh();
-            first_update = false;
-          }
+      const int next_id = population.ScheduleOrganism();
+      if (next_id == m_view->GetStepOrganism()) {
+        m_view->NotifyUpdate();
+        m_view->NewUpdate();
+        
+        // This is needed to have the top bar drawn properly; I'm not sure why...
+        static bool first_update = true;
+        if (first_update) {
+          m_view->Refresh();
+          first_update = false;
         }
-        population.ProcessStep(ctx, step_size, next_id);
       }
+      population.ProcessStep(ctx, step_size, next_id);
     }
-    else {
-      for (int i = 0; i < UD_size; i++) population.ProcessStep(ctx, step_size);
-    }
-    
-    
-    // end of update stats...
-    population.CalcUpdateStats();
-    
-    
-    // Setup the viewer for the new update.
-    if (m_view->GetStepOrganism() == -1) {
-      m_view->NotifyUpdate();
-      m_view->NewUpdate();
-      
-      // This is needed to have the top bar drawn properly; I'm not sure why...
-      static bool first_update = true;
-      if (first_update) {
-        m_view->Refresh();
-        first_update = false;
+  }
+  else {
+    for (int i = 0; i < UD_size; i++) {
+      if (population.GetNumOrganisms() == 0) {
+        return true;
       }
+      population.ProcessStep(ctx, step_size);
     }
+  }
+  return false;
+}
+
+void cTextViewerDriver::UpdateView()
+{
+  // Setup the viewer for the new update.
+  if (m_view->GetStepOrganism() == -1) {
+    m_view->NotifyUpdate();
+    m_view->NewUpdate();
     
-    
-    // Do Point Mutations
-    if (point_mut_prob > 0 ) {
-      for (int i = 0; i < population.GetSize(); i++) {
-        if (population.GetCell(i).IsOccupied()) {
-          population.GetCell(i).GetOrganism()->GetHardware().PointMutate(ctx, point_mut_prob);
-        }
-      }
+    // This is needed to have the top bar drawn properly; I'm not sure why...
+    static bool first_update = true;
+    if (first_update) {
+      m_view->Refresh();
+      first_update = false;
     }
-    
-    // Exit conditons...
-    if (population.GetNumOrganisms() == 0) m_done = true;
   }
 }
 

Modified: branches/vo/source/targets/avida-viewer/cTextViewerDriver.h
===================================================================
--- branches/vo/source/targets/avida-viewer/cTextViewerDriver.h	2007-07-03 17:44:48 UTC (rev 1744)
+++ branches/vo/source/targets/avida-viewer/cTextViewerDriver.h	2007-07-03 17:53:13 UTC (rev 1745)
@@ -29,7 +29,11 @@
 #include "cTextViewerDriver_Base.h"
 #endif
 
-class cTextViewerDriver : public cTextViewerDriver_Base
+#ifndef cDefaultRunDriver_h
+#include "cDefaultRunDriver.h"
+#endif
+
+class cTextViewerDriver : public cTextViewerDriver_Base, public cDefaultRunDriver
 {
 private:
   cTextViewerDriver();  // not implemented
@@ -38,7 +42,8 @@
   cTextViewerDriver(cWorld* world);
   ~cTextViewerDriver();
   
-  void Run();
+  bool UpdateProcess( const int UD_size, const double step_size, cAvidaContext& ctx, cPopulation& population);
+  void UpdateView();
   
   // Driver Actions
   void SignalBreakpoint();

Modified: branches/vo/source/targets/avida-viewer/cTextViewerDriver_Base.cc
===================================================================
--- branches/vo/source/targets/avida-viewer/cTextViewerDriver_Base.cc	2007-07-03 17:44:48 UTC (rev 1744)
+++ branches/vo/source/targets/avida-viewer/cTextViewerDriver_Base.cc	2007-07-03 17:53:13 UTC (rev 1745)
@@ -29,8 +29,8 @@
 #include "cView_Base.h"
 #include "cWorld.h"
 
-cTextViewerDriver_Base::cTextViewerDriver_Base(cWorld * world)
-  : m_world(world), m_view(NULL), m_done(false)
+cTextViewerDriver_Base::cTextViewerDriver_Base()
+  : m_view(NULL)
 {
   std::cout.rdbuf(out_stream.rdbuf());
   std::cerr.rdbuf(err_stream.rdbuf());
@@ -38,7 +38,6 @@
 
 cTextViewerDriver_Base::~cTextViewerDriver_Base()
 {
-  delete m_world;
 }
 
 

Modified: branches/vo/source/targets/avida-viewer/cTextViewerDriver_Base.h
===================================================================
--- branches/vo/source/targets/avida-viewer/cTextViewerDriver_Base.h	2007-07-03 17:44:48 UTC (rev 1744)
+++ branches/vo/source/targets/avida-viewer/cTextViewerDriver_Base.h	2007-07-03 17:53:13 UTC (rev 1745)
@@ -24,31 +24,22 @@
 #ifndef cTextViewerDriver_Base_h
 #define cTextViewerDriver_Base_h
 
-#ifndef cAvidaDriver_h
-#include "cAvidaDriver.h"
-#endif
 
-#ifndef cWorldDriver_h
-#include "cWorldDriver.h"
-#endif
-
 #include <sstream>
 #include <iostream>
 
 class cView_Base;
 class cWorld;
 
-class cTextViewerDriver_Base : public cAvidaDriver, public cWorldDriver {
+class cTextViewerDriver_Base {
 protected:
-  cWorld* m_world;
   cView_Base* m_view;
-  bool m_done;  // This is set to true when run should finish.
 
   std::stringstream out_stream;
   std::stringstream err_stream;
 
   // Protected constructor.
-  cTextViewerDriver_Base(cWorld * world);
+  cTextViewerDriver_Base();
   ~cTextViewerDriver_Base();
 
 public:




More information about the Avida-cvs mailing list