X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f0534a5e2af72c36c12d55f7ea323040e6e9bf36..1363ce9624f4327f3ad5c934b15736a776637dfd:/src/mc/api/strategy/UniformStrategy.hpp diff --git a/src/mc/api/strategy/UniformStrategy.hpp b/src/mc/api/strategy/UniformStrategy.hpp index 72f1a37799..cc5bd85773 100644 --- a/src/mc/api/strategy/UniformStrategy.hpp +++ b/src/mc/api/strategy/UniformStrategy.hpp @@ -7,6 +7,9 @@ #define SIMGRID_MC_UNIFORMSTRATEGY_HPP #include "src/mc/transition/Transition.hpp" +#include "xbt/random.hpp" + +#define MAX_RAND 100000 namespace simgrid::mc { @@ -18,34 +21,34 @@ public: UniformStrategy() { for (long aid = 0; aid < 10; aid++) - valuation[aid] = rand() % 1000; + valuation[aid] = xbt::random::uniform_int(0, MAX_RAND); } void copy_from(const Strategy* strategy) override { for (auto& [aid, _] : actors_to_run_) - valuation[aid] = rand() % 1000; + valuation[aid] = xbt::random::uniform_int(0, MAX_RAND); } - std::pair next_transition() const override + std::pair best_transition(bool must_be_todo) const override { int possibilities = 0; // Consider only valid actors for (auto const& [aid, actor] : actors_to_run_) { - if (actor.is_todo() and (not actor.is_done()) and actor.is_enabled()) + if ((actor.is_todo() or not must_be_todo) and (not actor.is_done()) and actor.is_enabled()) possibilities++; } int chosen; if (possibilities == 0) - return std::make_pair(-1, 100000); + return std::make_pair(-1, 0); if (possibilities == 1) chosen = 0; else - chosen = rand() % possibilities; + chosen = xbt::random::uniform_int(0, possibilities-1); for (auto const& [aid, actor] : actors_to_run_) { - if ((not actor.is_todo()) or actor.is_done() or (not actor.is_enabled())) + if (((not actor.is_todo()) and must_be_todo) or actor.is_done() or (not actor.is_enabled())) continue; if (chosen == 0) { return std::make_pair(aid, valuation.at(aid)); @@ -53,46 +56,10 @@ public: chosen--; } - return std::make_pair(-1, 100000); + return std::make_pair(-1, 0); } void execute_next(aid_t aid, RemoteApp& app) override {} - - void consider_best() override - { - - int possibilities = 0; - // Consider only valid actors - // If some actor are already considered as todo, skip - for (auto const& [aid, actor] : actors_to_run_) { - if (valuation.count(aid) == 0) - for (auto& [aid, _] : actors_to_run_) - valuation[aid] = rand() % 1000; - if (actor.is_todo()) - return; - if (actor.is_enabled() and not actor.is_done()) - possibilities++; - } - - int chosen; - if (possibilities == 0) - return; - if (possibilities == 1) - chosen = 0; - else - chosen = rand() % possibilities; - - for (auto& [aid, actor] : actors_to_run_) { - if (not actor.is_enabled() or actor.is_done()) - continue; - if (chosen == 0) { - actor.mark_todo(); - return; - } - chosen--; - } - THROW_IMPOSSIBLE; // One actor should be marked as todo before - } }; } // namespace simgrid::mc