[Avida-SVN] r2327 - in development/source: actions cpu drivers main

barrick at myxo.css.msu.edu barrick at myxo.css.msu.edu
Thu Feb 14 10:28:39 PST 2008


Author: barrick
Date: 2008-02-14 13:28:39 -0500 (Thu, 14 Feb 2008)
New Revision: 2327

Modified:
   development/source/actions/DriverActions.cc
   development/source/cpu/cHardwareBase.cc
   development/source/drivers/cDefaultRunDriver.cc
   development/source/drivers/cDefaultRunDriver.h
   development/source/drivers/cWorldDriver.h
   development/source/main/cAvidaConfig.h
   development/source/main/cPhenotype.h
   development/source/main/cPopulation.cc
Log:
Fixed problem with gestation times when using trials and speculative execution.
Put in a fast-forward hack to skip execution during epochs when resource has been used up.
Added error message for when CompeteOrganisms is used with other means of replicating.



Modified: development/source/actions/DriverActions.cc
===================================================================
--- development/source/actions/DriverActions.cc	2008-02-14 15:33:24 UTC (rev 2326)
+++ development/source/actions/DriverActions.cc	2008-02-14 18:28:39 UTC (rev 2327)
@@ -80,12 +80,29 @@
   }
 };
 
+class cActionStopFastForward : public cAction
+{
+private:
+public:
+  cActionStopFastForward(cWorld* world, const cString& args) : cAction(world, args)
+  {
+    cString largs(args);
+  }
+  
+  static const cString GetDescription() { return "Arguments: none"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+      m_world->GetDriver().ClearFastForward();
+  }
+};
 
 void RegisterDriverActions(cActionLibrary* action_lib)
 {
   action_lib->Register<cActionExit>("Exit");
   action_lib->Register<cActionExitAveLineageLabelGreater>("ExitAveLineageLabelGreater");
   action_lib->Register<cActionExitAveLineageLabelLess>("ExitAveLineageLabelLess");
+  action_lib->Register<cActionStopFastForward>("StopFastForward");
 
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionExit>("exit");

Modified: development/source/cpu/cHardwareBase.cc
===================================================================
--- development/source/cpu/cHardwareBase.cc	2008-02-14 15:33:24 UTC (rev 2326)
+++ development/source/cpu/cHardwareBase.cc	2008-02-14 18:28:39 UTC (rev 2327)
@@ -805,7 +805,8 @@
   if( (m_world->GetConfig().IMPLICIT_REPRO_TIME.Get() && (organism->GetPhenotype().GetTimeUsed() >= m_world->GetConfig().IMPLICIT_REPRO_TIME.Get()))
    || (m_world->GetConfig().IMPLICIT_REPRO_CPU_CYCLES.Get() && (organism->GetPhenotype().GetCPUCyclesUsed() >= m_world->GetConfig().IMPLICIT_REPRO_CPU_CYCLES.Get()))
    || (m_world->GetConfig().IMPLICIT_REPRO_BONUS.Get() && (organism->GetPhenotype().GetCurBonus() >= m_world->GetConfig().IMPLICIT_REPRO_BONUS.Get()))
-   || (m_world->GetConfig().IMPLICIT_REPRO_END.Get() && exec_last_inst ))
+   || (m_world->GetConfig().IMPLICIT_REPRO_END.Get() && exec_last_inst )
+   || (m_world->GetConfig().IMPLICIT_REPRO_ENERGY.Get() && ( organism->GetPhenotype().GetStoredEnergy() >= m_world->GetConfig().IMPLICIT_REPRO_ENERGY.Get())) )
   {
     Inst_Repro(ctx);
   }

Modified: development/source/drivers/cDefaultRunDriver.cc
===================================================================
--- development/source/drivers/cDefaultRunDriver.cc	2008-02-14 15:33:24 UTC (rev 2326)
+++ development/source/drivers/cDefaultRunDriver.cc	2008-02-14 18:28:39 UTC (rev 2327)
@@ -45,10 +45,14 @@
 using namespace std;
 
 
-cDefaultRunDriver::cDefaultRunDriver(cWorld* world) : m_world(world), m_done(false)
+cDefaultRunDriver::cDefaultRunDriver(cWorld* world) : m_world(world), m_done(false), 
+      m_fastforward(false),m_last_generation(0),  m_generation_same_update_count(0) 
 {
   cDriverManager::Register(static_cast<cAvidaDriver*>(this));
   world->SetDriver(this);
+  
+  // Save this config variable
+  m_generation_update_fastforward_threshold = m_world->GetConfig().FASTFORWARD_UPDATES.Get();
 }
 
 cDefaultRunDriver::~cDefaultRunDriver()
@@ -74,7 +78,7 @@
   }
   
   cAvidaContext& ctx = m_world->GetDefaultContext();
-
+  
   while (!m_done) {
     if (cChangeList* change_list = population.GetChangeList()) {
       change_list->Reset();
@@ -99,17 +103,20 @@
       }
     }
     
+    // don't process organisms if we are in fast-forward mode. -- @JEB
+    if (!GetFastForward())
+    {
+      // Process the update.
+      const int UD_size = ave_time_slice * population.GetNumOrganisms();
+      const double step_size = 1.0 / (double) UD_size;
     
-    // Process the update.
-    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;
+      for (int i = 0; i < UD_size; i++) {
+        if (population.GetNumOrganisms() == 0) {
+          m_done = true;
+          break;
+        }
+        (population.*ActiveProcessStep)(ctx, step_size, population.ScheduleOrganism());
       }
-      (population.*ActiveProcessStep)(ctx, step_size, population.ScheduleOrganism());
     }
     
     // end of update stats...
@@ -147,6 +154,9 @@
       }
     }
     
+    // Keep track of changes in generation for fast-forward purposes
+    UpdateFastForward(stats.GetGeneration());
+      
     // Exit conditons...
     if (population.GetNumOrganisms() == 0) m_done = true;
   }
@@ -172,3 +182,19 @@
 {
   cout << "Warning: " << in_string << endl;
 }
+
+void cDefaultRunDriver::UpdateFastForward (double inGeneration)
+{
+  if (!m_generation_update_fastforward_threshold) return;
+
+  if (inGeneration == m_last_generation)
+  {
+    m_generation_same_update_count++;
+    if (m_generation_same_update_count >= m_generation_update_fastforward_threshold) m_fastforward = true;
+  }
+  else
+  {
+    m_generation_same_update_count = 0;
+    m_last_generation = inGeneration;
+  }
+}

Modified: development/source/drivers/cDefaultRunDriver.h
===================================================================
--- development/source/drivers/cDefaultRunDriver.h	2008-02-14 15:33:24 UTC (rev 2326)
+++ development/source/drivers/cDefaultRunDriver.h	2008-02-14 18:28:39 UTC (rev 2327)
@@ -45,7 +45,11 @@
 protected:
   cWorld* m_world;
   bool m_done;  // This is set to true when run should finish.
-
+  bool m_fastforward;
+  double m_last_generation;
+  int m_generation_same_update_count;
+  int m_generation_update_fastforward_threshold;
+  
 public:
   cDefaultRunDriver(cWorld* world);
   ~cDefaultRunDriver();
@@ -62,6 +66,11 @@
   // Notifications
   void NotifyComment(const cString& in_string);
   void NotifyWarning(const cString& in_string);
+  
+  void ClearFastForward() { m_fastforward = false; m_generation_same_update_count = 0; }
+  void UpdateFastForward (double inGeneration);
+  bool GetFastForward() { return m_fastforward; }
+
 };
 
 

Modified: development/source/drivers/cWorldDriver.h
===================================================================
--- development/source/drivers/cWorldDriver.h	2008-02-14 15:33:24 UTC (rev 2326)
+++ development/source/drivers/cWorldDriver.h	2008-02-14 18:28:39 UTC (rev 2327)
@@ -46,6 +46,7 @@
 private:
   cWorldDriver(const cWorldDriver&); // @not_implemented
   cWorldDriver& operator=(const cWorldDriver&); // @not_implemented
+  
 public:
   cWorldDriver() { ; }
   virtual ~cWorldDriver() { ; }
@@ -65,6 +66,12 @@
   virtual bool IsInteractive() { return false; }
   virtual void Flush() { std::cout.flush(); std::cerr.flush(); }
   virtual bool ProcessKeypress(int keypress) { return false; }
+  
+  // Fast-forward through epochs when no replication is happening -- @JEB
+  // These are only implemented in the DefaultWorldDriver
+  virtual void ClearFastForward() { }
+  virtual bool GetFastForward() { }
+
 };
 
 

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2008-02-14 15:33:24 UTC (rev 2326)
+++ development/source/main/cAvidaConfig.h	2008-02-14 18:28:39 UTC (rev 2327)
@@ -343,6 +343,7 @@
   CONFIG_ADD_VAR(IMPLICIT_REPRO_CPU_CYCLES, int, 0, "Call Inst_Repro after this many cpu cycles. 0 = OFF");  
   CONFIG_ADD_VAR(IMPLICIT_REPRO_TIME, int, 0, "Call Inst_Repro after this time used. 0 = OFF");  
   CONFIG_ADD_VAR(IMPLICIT_REPRO_END, int, 0, "Call Inst_Repro after executing the last instruction in the genome.");  
+  CONFIG_ADD_VAR(IMPLICIT_REPRO_ENERGY, double, 0.0, "Call Inst_Repro if organism accumulates this amount of energy.");    
 
   CONFIG_ADD_GROUP(MUTATION_GROUP, "Mutations");
   CONFIG_ADD_VAR(POINT_MUT_PROB, double, 0.0, "Mutation rate (per-location per update)");
@@ -406,6 +407,7 @@
   CONFIG_ADD_VAR(DONATE_THRESH_QUANTA, int, 10, "The size of steps between quanta donate thresholds");
   CONFIG_ADD_VAR(MAX_DONATES, int, 1000000, "Limit on number of donates organisms are allowed.");
   CONFIG_ADD_VAR(PRECALC_PHENOTYPE, int, 0, "0 = Disabled\n 1 = Assign precalculated merit at birth (unlimited resources only)\n 2 = Assign precalculated gestation time\n 3 = Assign precalculated merit AND gestation time.\nFitness will be evaluated for organism based on these settings.");
+  CONFIG_ADD_VAR(FASTFORWARD_UPDATES, int, 0, "Fast-forward if the average generation has not changed in this many updates. (0 = off)");
 
   CONFIG_ADD_GROUP(GENEOLOGY_GROUP, "Geneology");
   CONFIG_ADD_VAR(TRACK_MAIN_LINEAGE, int, 1, "Keep all ancestors of the active population?\n0=no, 1=yes, 2=yes,w/sexual population");

Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h	2008-02-14 15:33:24 UTC (rev 2326)
+++ development/source/main/cPhenotype.h	2008-02-14 18:28:39 UTC (rev 2327)
@@ -325,6 +325,7 @@
   int GetGeneration() const { assert(initialized == true); return generation; }
   int GetCPUCyclesUsed() const { assert(initialized == true); return cpu_cycles_used; }
   int GetTimeUsed()   const { assert(initialized == true); return time_used; }
+  int GetTrialTimeUsed()   const { assert(initialized == true); return trial_time_used; }
   int GetAge()        const { assert(initialized == true); return age; }
   const cString& GetFault() const { assert(initialized == true); return fault_desc; }
   double GetNeutralMetric() const { assert(initialized == true); return neutral_metric; }
@@ -390,6 +391,7 @@
   void SetEnergy(const double value);
   void SetGestationTime(int in_time) { gestation_time = in_time; }
   void SetTimeUsed(int in_time) { time_used = in_time; }
+  void SetTrialTimeUsed(int in_time) { trial_time_used = in_time; }
   void SetFault(const cString& in_fault) { fault_desc = in_fault; }
   void SetNeutralMetric(double _in){ neutral_metric = _in; }
   void SetLifeFitness(double _in){ life_fitness = _in; }

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2008-02-14 15:33:24 UTC (rev 2326)
+++ development/source/main/cPopulation.cc	2008-02-14 18:28:39 UTC (rev 2327)
@@ -3402,6 +3402,14 @@
   {
     if (GetCell(i).IsOccupied())
     {
+      cPopulationCell& cell = GetCell(i);
+      
+      // Correct gestation time for speculative execution
+      cPhenotype & p =  GetCell(i).GetOrganism()->GetPhenotype();
+      p.SetTrialTimeUsed(p.GetTrialTimeUsed() - GetCell(i).GetSpeculativeState());
+      p.SetTimeUsed(p.GetTimeUsed() - GetCell(i).GetSpeculativeState());
+
+
       GetCell(i).GetOrganism()->NewTrial();
       GetCell(i).GetOrganism()->GetHardware().Reset();
     }
@@ -3438,7 +3446,7 @@
   int different_orgs_copied = 0;
   int num_competed_orgs = 0;
 
-  int num_trials = 0;
+  int num_trials = -1;
   int dynamic_scaling = (competition_type==3);
   
   // How many trials were there? -- same for every organism
@@ -3448,8 +3456,15 @@
     if (GetCell(i).IsOccupied())
     { 
       cPhenotype& p = GetCell(i).GetOrganism()->GetPhenotype();
+      
+      if ( (num_trials != -1) && (num_trials != p.GetTrialFitnesses().GetSize()) )
+      {
+        cout << "The number of trials is not the same for every organism in the population.\n";
+        cout << "You need to remove all normal ways of replicating for CompeteOrganisms to work correctly.\n";
+        exit(1);
+      }
+      
       num_trials = p.GetTrialFitnesses().GetSize();
-      break;
     }
   }
   tArray<double> min_trial_fitnesses(num_trials);




More information about the Avida-cvs mailing list