Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add factorisation for strategy and Use dynamic over static cast
[simgrid.git] / src / mc / api / strategy / Strategy.hpp
index 8b5d094..9bdebad 100644 (file)
@@ -3,11 +3,16 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "xbt/asserts.h"
-
 #ifndef SIMGRID_MC_STRATEGY_HPP
 #define SIMGRID_MC_STRATEGY_HPP
 
+#include "simgrid/forward.h"
+#include "src/mc/api/RemoteApp.hpp"
+#include "src/mc/mc_config.hpp"
+#include "xbt/asserts.h"
+#include <map>
+#include <utility>
+
 namespace simgrid::mc {
 
 class Strategy {
@@ -20,12 +25,21 @@ public:
   Strategy()                              = default;
   virtual ~Strategy()                     = default;
 
-  virtual std::pair<aid_t, int> next_transition() const = 0;
+  virtual std::pair<aid_t, int> best_transition(bool must_be_todo) const = 0;
+    
+  std::pair<aid_t, int> next_transition() { return best_transition(true); }
   virtual void execute_next(aid_t aid, RemoteApp& app)  = 0;
 
   // Mark the first enabled and not yet done transition as todo
   // If there's already a transition marked as todo, does nothing
-  virtual void consider_best() = 0;
+  void consider_best() {
+       for (auto& [_, actor] :actors_to_run_)
+           if (actor.is_todo())
+               return;
+       aid_t best_aid = best_transition(false).first;
+       if (best_aid != -1)
+           actors_to_run_.at(best_aid).mark_todo();
+  }
 
   // Mark aid as todo. If it makes no sense, ie. if it is already done or not enabled,
   // raise an error