Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a multiset to handle opened states, and ensures a reproductible order on differen...
[simgrid.git] / src / mc / explo / DFSExplorer.hpp
index 9301ed2..dae59bb 100644 (file)
@@ -6,11 +6,16 @@
 #ifndef SIMGRID_MC_SAFETY_CHECKER_HPP
 #define SIMGRID_MC_SAFETY_CHECKER_HPP
 
-#include "src/mc/VisitedState.hpp"
+#include "src/mc/api/State.hpp"
 #include "src/mc/explo/Exploration.hpp"
 
+#if SIMGRID_HAVE_STATEFUL_MC
+#include "src/mc/VisitedState.hpp"
+#endif
+
 #include <list>
 #include <memory>
+#include <set>
 #include <string>
 #include <vector>
 
@@ -18,6 +23,16 @@ namespace simgrid::mc {
 
 typedef std::list<std::shared_ptr<State>> stack_t;
 
+/* Used to compare two stacks and decide which one is better to backtrack,
+ * regarding the chosen guide in the last state. */
+class OpenedStatesCompare {
+public:
+  bool operator()(std::shared_ptr<State> const& lhs, std::shared_ptr<State> const& rhs) const
+  {
+    return lhs->next_transition_guided().second > rhs->next_transition_guided().second;
+  }
+};
+
 class XBT_PRIVATE DFSExplorer : public Exploration {
 
   XBT_DECLARE_ENUM_CLASS(ReductionMode, none, dpor);
@@ -90,13 +105,21 @@ private:
 
   /** Stack representing the position in the exploration graph */
   stack_t stack_;
+#if SIMGRID_HAVE_STATEFUL_MC
   VisitedStates visited_states_;
   std::unique_ptr<VisitedState> visited_state_;
+#else
+  void* visited_state_ = nullptr; /* The code uses it to detect whether we are doing stateful MC */
+#endif
 
   /** Opened states are states that still contains todo actors.
    *  When backtracking, we pick a state from it*/
-  std::list<stack_t> opened_states_;
-  void add_to_opened_states(stack_t stack);
+  std::multiset<std::shared_ptr<State>, OpenedStatesCompare> opened_states_;
+
+  /** Change current stack_ value to correspond to the one we would have
+   *  had if we executed transition to get to state. This is required when
+   *  backtracking, and achieved thanks to the fact states save their parent.*/
+  void restore_stack(std::shared_ptr<State> state);
 
   RecordTrace get_record_trace_of_stack(stack_t stack);
 };