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 "src/plugins/cfg/CFGMap.hpp"
12 namespace simgrid::mc {
14 /** Guiding strategy that valuate states randomly */
15 class UniformStrategy : public Strategy {
16 std::map<aid_t, int> valuation;
21 for (long aid = 0; aid < 10; aid++)
22 valuation[aid] = rand() % 1000;
24 void copy_from(const Strategy* strategy) override
26 for (auto& [aid, _] : actors_to_run_)
27 valuation[aid] = rand() % 1000;
30 std::pair<aid_t, int> next_transition() const override
32 int possibilities = 0;
34 // Consider only valid actors
35 for (auto const& [aid, actor] : actors_to_run_) {
36 if (actor.is_todo() and (not actor.is_done()) and actor.is_enabled())
41 if (possibilities == 0)
42 return std::make_pair(-1, 100000);
43 if (possibilities == 1)
46 chosen = rand() % possibilities;
48 for (auto const& [aid, actor] : actors_to_run_) {
49 if ((not actor.is_todo()) or actor.is_done() or (not actor.is_enabled()))
52 return std::make_pair(aid, valuation.at(aid));
57 return std::make_pair(-1, 100000);
60 void execute_next(aid_t aid, RemoteApp& app) override {}
62 void consider_best() override
65 int possibilities = 0;
66 // Consider only valid actors
67 // If some actor are already considered as todo, skip
68 for (auto const& [aid, actor] : actors_to_run_) {
69 if (valuation.count(aid) == 0)
70 for (auto& [aid, _] : actors_to_run_)
71 valuation[aid] = rand() % 1000;
74 if (actor.is_enabled() and not actor.is_done())
79 if (possibilities == 0)
81 if (possibilities == 1)
84 chosen = rand() % possibilities;
86 for (auto& [aid, actor] : actors_to_run_) {
87 if (not actor.is_enabled() or actor.is_done())
95 THROW_IMPOSSIBLE; // One actor should be marked as todo before
99 } // namespace simgrid::mc