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_BASICSTRATEGY_HPP
7 #define SIMGRID_MC_BASICSTRATEGY_HPP
9 #include "Strategy.hpp"
10 #include "src/mc/explo/Exploration.hpp"
12 XBT_LOG_EXTERNAL_CATEGORY(mc_dfs);
14 namespace simgrid::mc {
16 /** Basic MC guiding class which corresponds to no guide. When asked for different states
17 * it will follow a depth first search politics to minize the number of opened states. */
18 class BasicStrategy : public Strategy {
19 int depth_ = _sg_mc_max_depth; // Arbitrary starting point. next_transition must return a positive value to work with
20 // threshold in DFSExplorer
23 void copy_from(const Strategy* strategy) override
25 const auto* cast_strategy = dynamic_cast<BasicStrategy const*>(strategy);
26 xbt_assert(cast_strategy != nullptr);
27 depth_ = cast_strategy->depth_ - 1;
30 "The exploration reached a depth greater than %d. Change the depth limit with "
31 "--cfg=model-check/max-depth. Here are the 100 first trace elements",
32 _sg_mc_max_depth.get());
33 auto trace = Exploration::get_instance()->get_textual_trace(100);
34 for (auto elm : trace)
35 XBT_CERROR(mc_dfs, " %s", elm.c_str());
36 xbt_die("Aborting now.");
39 BasicStrategy() = default;
40 ~BasicStrategy() override = default;
42 std::pair<aid_t, int> best_transition(bool must_be_todo) const override {
43 for (auto const& [aid, actor] : actors_to_run_) {
44 /* Only consider actors (1) marked as interleaving by the checker and (2) currently enabled in the application */
45 if ((not actor.is_todo() && must_be_todo) || not actor.is_enabled() || actor.is_done()) {
49 return std::make_pair(aid, depth_);
51 return std::make_pair(-1, depth_);
54 void execute_next(aid_t aid, RemoteApp& app) override { return; }
57 } // namespace simgrid::mc