A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Respect coding style for boolean operators.
[simgrid.git]
/
src
/
mc
/
api
/
strategy
/
UniformStrategy.hpp
diff --git
a/src/mc/api/strategy/UniformStrategy.hpp
b/src/mc/api/strategy/UniformStrategy.hpp
index
1dfcd07
..
472c571
100644
(file)
--- a/
src/mc/api/strategy/UniformStrategy.hpp
+++ b/
src/mc/api/strategy/UniformStrategy.hpp
@@
-7,25
+7,26
@@
#define SIMGRID_MC_UNIFORMSTRATEGY_HPP
#include "src/mc/transition/Transition.hpp"
#define SIMGRID_MC_UNIFORMSTRATEGY_HPP
#include "src/mc/transition/Transition.hpp"
-
-#define MAX_RAND 100000
+#include "xbt/random.hpp"
namespace simgrid::mc {
/** Guiding strategy that valuate states randomly */
class UniformStrategy : public Strategy {
namespace simgrid::mc {
/** Guiding strategy that valuate states randomly */
class UniformStrategy : public Strategy {
+ static constexpr int MAX_RAND = 100000;
+
std::map<aid_t, int> valuation;
public:
UniformStrategy()
{
for (long aid = 0; aid < 10; aid++)
std::map<aid_t, int> valuation;
public:
UniformStrategy()
{
for (long aid = 0; aid < 10; aid++)
- valuation[aid] =
rand() % 10000
;
+ valuation[aid] =
xbt::random::uniform_int(0, MAX_RAND)
;
}
void copy_from(const Strategy* strategy) override
{
}
void copy_from(const Strategy* strategy) override
{
- for (auto& [aid, _] : actors_to_run_)
- valuation[aid] =
rand() % 10000
;
+ for (auto
const
& [aid, _] : actors_to_run_)
+ valuation[aid] =
xbt::random::uniform_int(0, MAX_RAND)
;
}
std::pair<aid_t, int> best_transition(bool must_be_todo) const override
}
std::pair<aid_t, int> best_transition(bool must_be_todo) const override
@@
-34,7
+35,7
@@
public:
// Consider only valid actors
for (auto const& [aid, actor] : actors_to_run_) {
// Consider only valid actors
for (auto const& [aid, actor] : actors_to_run_) {
-
if ((actor.is_todo() or not must_be_todo) and (not actor.is_done()) and
actor.is_enabled())
+
if ((actor.is_todo() || not must_be_todo) && (not actor.is_done()) &&
actor.is_enabled())
possibilities++;
}
possibilities++;
}
@@
-44,10
+45,10
@@
public:
if (possibilities == 1)
chosen = 0;
else
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_) {
for (auto const& [aid, actor] : actors_to_run_) {
-
if (((not actor.is_todo()) and must_be_todo) or actor.is_done() or
(not actor.is_enabled()))
+
if (((not actor.is_todo()) && must_be_todo) || actor.is_done() ||
(not actor.is_enabled()))
continue;
if (chosen == 0) {
return std::make_pair(aid, valuation.at(aid));
continue;
if (chosen == 0) {
return std::make_pair(aid, valuation.at(aid));
@@
-58,9
+59,7
@@
public:
return std::make_pair(-1, 0);
}
return std::make_pair(-1, 0);
}
-
void execute_next(aid_t aid, RemoteApp& app) override {}
void execute_next(aid_t aid, RemoteApp& app) override {}
-
};
} // namespace simgrid::mc
};
} // namespace simgrid::mc