1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_MC_UNIFORMSTRATEGY_HPP
7 #define SIMGRID_MC_UNIFORMSTRATEGY_HPP
9 #include "src/mc/transition/Transition.hpp"
10 #include "xbt/random.hpp"
12 #define MAX_RAND 100000
14 namespace simgrid::mc {
16 /** Guiding strategy that valuate states randomly */
17 class UniformStrategy : public Strategy {
18 std::map<aid_t, int> valuation;
23 for (long aid = 0; aid < 10; aid++)
24 valuation[aid] = xbt::random::uniform_int(0, MAX_RAND);
26 void copy_from(const Strategy* strategy) override
28 for (auto& [aid, _] : actors_to_run_)
29 valuation[aid] = xbt::random::uniform_int(0, MAX_RAND);
32 std::pair<aid_t, int> best_transition(bool must_be_todo) const override
34 int possibilities = 0;
36 // Consider only valid actors
37 for (auto const& [aid, actor] : actors_to_run_) {
38 if ((actor.is_todo() or not must_be_todo) and (not actor.is_done()) and actor.is_enabled())
43 if (possibilities == 0)
44 return std::make_pair(-1, 0);
45 if (possibilities == 1)
48 chosen = xbt::random::uniform_int(0, possibilities-1);
50 for (auto const& [aid, actor] : actors_to_run_) {
51 if (((not actor.is_todo()) and must_be_todo) or actor.is_done() or (not actor.is_enabled()))
54 return std::make_pair(aid, valuation.at(aid));
59 return std::make_pair(-1, 0);
62 void execute_next(aid_t aid, RemoteApp& app) override {}
65 } // namespace simgrid::mc