X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/985e0a5509e230076d22095da54dd0123d2afe5e..dc6726419e36dd2853c7773e0a8fc177091e79e0:/src/mc/api/strategy/Strategy.hpp diff --git a/src/mc/api/strategy/Strategy.hpp b/src/mc/api/strategy/Strategy.hpp index de2f941fb8..9bdebad0e4 100644 --- a/src/mc/api/strategy/Strategy.hpp +++ b/src/mc/api/strategy/Strategy.hpp @@ -8,6 +8,7 @@ #include "simgrid/forward.h" #include "src/mc/api/RemoteApp.hpp" +#include "src/mc/mc_config.hpp" #include "xbt/asserts.h" #include #include @@ -16,32 +17,40 @@ namespace simgrid::mc { class Strategy { protected: - /** State's exploration status by actor. Not all the actors are there, only the ones that are ready-to-run in this - * state */ + /** State's exploration status by actor. All actors should be present, eventually disabled for now. */ std::map actors_to_run_; public: - Strategy() = default; - virtual ~Strategy() = default; - Strategy(const Strategy&) = delete; - Strategy& operator=(const Strategy&) - { /* nothing to copy over while cloning */ - return *this; - } + virtual void copy_from(const Strategy*) = 0; + Strategy() = default; + virtual ~Strategy() = default; - virtual std::pair next_transition() const = 0; + virtual std::pair best_transition(bool must_be_todo) const = 0; + + std::pair next_transition() { return best_transition(true); } virtual void execute_next(aid_t aid, RemoteApp& app) = 0; - virtual void consider_best() = 0; // Mark the first enabled and not yet done transition as todo // If there's already a transition marked as todo, does nothing + 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 void consider_one(aid_t aid) { xbt_assert(actors_to_run_.at(aid).is_enabled() and not actors_to_run_.at(aid).is_done(), "Tried to mark as TODO actor %ld but it is either not enabled or already done", aid); actors_to_run_.at(aid).mark_todo(); } - // Matk as todo all actors enabled that are not done yet + // Mark as todo all actors enabled that are not done yet and return the number + // of marked actors unsigned long consider_all() { unsigned long count = 0;