Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / mc / api / strategy / BasicStrategy.hpp
1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_MC_BASICSTRATEGY_HPP
7 #define SIMGRID_MC_BASICSTRATEGY_HPP
8
9 #include "Strategy.hpp"
10
11 namespace simgrid::mc {
12
13 /** Basic MC guiding class which corresponds to no guide. When asked for different states
14  *  it will follow a depth first search politics to minize the number of opened states. */
15 class BasicStrategy : public Strategy {
16     int depth_ = 100000; // Arbitrary starting point. next_transition must return a positiv value to work with threshold in DFSExplorer
17
18 public:
19   void copy_from(const Strategy* strategy) override
20   {
21     const BasicStrategy* cast_strategy = static_cast<BasicStrategy const*>(strategy);
22     xbt_assert(cast_strategy != nullptr);
23     depth_ = cast_strategy->depth_ - 1;
24     xbt_assert(depth_ > 0, "The exploration reached a depth greater than 100000. We will stop here to prevent weird interaction with DFSExplorer.");
25   }
26   BasicStrategy()                     = default;
27   ~BasicStrategy() override           = default;
28
29   std::pair<aid_t, int> next_transition() const override
30   {
31     for (auto const& [aid, actor] : actors_to_run_) {
32       /* Only consider actors (1) marked as interleaving by the checker and (2) currently enabled in the application */
33       if (not actor.is_todo() || not actor.is_enabled() || actor.is_done()) {
34         continue;
35       }
36
37       return std::make_pair(aid, depth_);
38     }
39     return std::make_pair(-1, depth_);
40   }
41   void execute_next(aid_t aid, RemoteApp& app) override { return; }
42
43   void consider_best() override
44   {
45     for (auto& [_, actor] : actors_to_run_) {
46       if (actor.is_todo())
47         return;
48       if (actor.is_enabled() and not actor.is_done()) {
49         actor.mark_todo();
50         return;
51       }
52     }
53   }
54 };
55
56 } // namespace simgrid::mc
57
58 #endif