Logo AND Algorithmique Numérique Distribuée

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