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"
11 namespace simgrid::mc {
13 /** Guiding strategy that valuate states randomly */
14 class UniformStrategy : public Strategy {
15 std::map<aid_t, int> valuation;
20 for (long aid = 0; aid < 10; aid++)
21 valuation[aid] = rand() % 1000;
23 void copy_from(const Strategy* strategy) override
25 for (auto& [aid, _] : actors_to_run_)
26 valuation[aid] = rand() % 1000;
29 std::pair<aid_t, int> next_transition() const override
31 int possibilities = 0;
33 // Consider only valid actors
34 for (auto const& [aid, actor] : actors_to_run_) {
35 if (actor.is_todo() and (not actor.is_done()) and actor.is_enabled())
40 if (possibilities == 0)
41 return std::make_pair(-1, 100000);
42 if (possibilities == 1)
45 chosen = rand() % possibilities;
47 for (auto const& [aid, actor] : actors_to_run_) {
48 if ((not actor.is_todo()) or actor.is_done() or (not actor.is_enabled()))
51 return std::make_pair(aid, valuation.at(aid));
56 return std::make_pair(-1, 100000);
59 void execute_next(aid_t aid, RemoteApp& app) override {}
61 void consider_best() override
64 int possibilities = 0;
65 // Consider only valid actors
66 // If some actor are already considered as todo, skip
67 for (auto const& [aid, actor] : actors_to_run_) {
68 if (valuation.count(aid) == 0)
69 for (auto& [aid, _] : actors_to_run_)
70 valuation[aid] = rand() % 1000;
73 if (actor.is_enabled() and not actor.is_done())
78 if (possibilities == 0)
80 if (possibilities == 1)
83 chosen = rand() % possibilities;
85 for (auto& [aid, actor] : actors_to_run_) {
86 if (not actor.is_enabled() or actor.is_done())
94 THROW_IMPOSSIBLE; // One actor should be marked as todo before
98 } // namespace simgrid::mc