Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / mc / explo / DFSExplorer.hpp
1 /* Copyright (c) 2008-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_SAFETY_CHECKER_HPP
7 #define SIMGRID_MC_SAFETY_CHECKER_HPP
8
9 #include "src/mc/VisitedState.hpp"
10 #include "src/mc/explo/Exploration.hpp"
11
12 #include <list>
13 #include <memory>
14 #include <string>
15 #include <vector>
16
17 namespace simgrid::mc {
18
19 typedef std::list<std::shared_ptr<State>> stack_t;
20
21 class XBT_PRIVATE DFSExplorer : public Exploration {
22
23   XBT_DECLARE_ENUM_CLASS(ReductionMode, none, dpor);
24
25   ReductionMode reduction_mode_;
26   unsigned long backtrack_count_      = 0; // for statistics
27   unsigned long visited_states_count_ = 0; // for statistics
28
29   static xbt::signal<void(RemoteApp&)> on_exploration_start_signal;
30   static xbt::signal<void(RemoteApp&)> on_backtracking_signal;
31
32   static xbt::signal<void(State*, RemoteApp&)> on_state_creation_signal;
33
34   static xbt::signal<void(State*, RemoteApp&)> on_restore_system_state_signal;
35   static xbt::signal<void(RemoteApp&)> on_restore_initial_state_signal;
36   static xbt::signal<void(Transition*, RemoteApp&)> on_transition_replay_signal;
37   static xbt::signal<void(Transition*, RemoteApp&)> on_transition_execute_signal;
38
39   static xbt::signal<void(RemoteApp&)> on_log_state_signal;
40
41 public:
42   explicit DFSExplorer(const std::vector<char*>& args, bool with_dpor, bool need_memory_info = false);
43   void run() override;
44   RecordTrace get_record_trace() override;
45   std::vector<std::string> get_textual_trace() override;
46   void log_state() override;
47
48   /** Called once when the exploration starts */
49   static void on_exploration_start(std::function<void(RemoteApp& remote_app)> const& f)
50   {
51     on_exploration_start_signal.connect(f);
52   }
53   /** Called each time that the exploration backtracks from a exploration end */
54   static void on_backtracking(std::function<void(RemoteApp& remote_app)> const& f)
55   {
56     on_backtracking_signal.connect(f);
57   }
58   /** Called each time that a new state is create */
59   static void on_state_creation(std::function<void(State*, RemoteApp& remote_app)> const& f)
60   {
61     on_state_creation_signal.connect(f);
62   }
63   /** Called when rollbacking directly onto a previously checkpointed state */
64   static void on_restore_system_state(std::function<void(State*, RemoteApp& remote_app)> const& f)
65   {
66     on_restore_system_state_signal.connect(f);
67   }
68   /** Called when the state to which we backtrack was not checkpointed state, forcing us to restore the initial state
69    * before replaying some transitions */
70   static void on_restore_initial_state(std::function<void(RemoteApp& remote_app)> const& f)
71   {
72     on_restore_initial_state_signal.connect(f);
73   }
74   /** Called when replaying a transition that was previously executed, to reach a backtracked state */
75   static void on_transition_replay(std::function<void(Transition*, RemoteApp& remote_app)> const& f)
76   {
77     on_transition_replay_signal.connect(f);
78   }
79   /** Called when executing a new transition */
80   static void on_transition_execute(std::function<void(Transition*, RemoteApp& remote_app)> const& f)
81   {
82     on_transition_execute_signal.connect(f);
83   }
84   /** Called when displaying the statistics at the end of the exploration */
85   static void on_log_state(std::function<void(RemoteApp&)> const& f) { on_log_state_signal.connect(f); }
86
87 private:
88   void check_non_termination(const State* current_state);
89   void backtrack();
90
91   /** Stack representing the position in the exploration graph */
92   stack_t stack_;
93   VisitedStates visited_states_;
94   std::unique_ptr<VisitedState> visited_state_;
95
96   /** Opened states are states that still contains todo actors.
97    *  When backtracking, we pick a state from it*/
98   std::vector<stack_t> opened_states;
99 };
100
101 } // namespace simgrid::mc
102
103 #endif