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 #define MAX_RAND 100000
13 namespace simgrid::mc {
15 /** Guiding strategy that valuate states randomly */
16 class UniformStrategy : public Strategy {
17 std::map<aid_t, int> valuation;
22 for (long aid = 0; aid < 10; aid++)
23 valuation[aid] = rand() % 10000;
25 void copy_from(const Strategy* strategy) override
27 for (auto& [aid, _] : actors_to_run_)
28 valuation[aid] = rand() % 10000;
31 std::pair<aid_t, int> best_transition(bool must_be_todo) const override
33 int possibilities = 0;
35 // Consider only valid actors
36 for (auto const& [aid, actor] : actors_to_run_) {
37 if ((actor.is_todo() or not must_be_todo) and (not actor.is_done()) and actor.is_enabled())
42 if (possibilities == 0)
43 return std::make_pair(-1, 0);
44 if (possibilities == 1)
47 chosen = rand() % possibilities;
49 for (auto const& [aid, actor] : actors_to_run_) {
50 if (((not actor.is_todo()) and must_be_todo) or actor.is_done() or (not actor.is_enabled()))
53 return std::make_pair(aid, valuation.at(aid));
58 return std::make_pair(-1, 0);
62 void execute_next(aid_t aid, RemoteApp& app) override {}
66 } // namespace simgrid::mc