Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix conflict detection between configs + history
[simgrid.git] / src / mc / explo / udpor / UnfoldingEvent.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_UDPOR_UNFOLDING_EVENT_HPP
7 #define SIMGRID_MC_UDPOR_UNFOLDING_EVENT_HPP
8
9 #include "src/mc/explo/udpor/EventSet.hpp"
10 #include "src/mc/explo/udpor/udpor_forward.hpp"
11 #include "src/mc/transition/Transition.hpp"
12
13 #include <initializer_list>
14 #include <memory>
15 #include <string>
16
17 namespace simgrid::mc::udpor {
18
19 class UnfoldingEvent {
20 public:
21   explicit UnfoldingEvent(std::initializer_list<const UnfoldingEvent*> init_list);
22   UnfoldingEvent(EventSet immediate_causes              = EventSet(),
23                  std::shared_ptr<Transition> transition = std::make_unique<Transition>());
24
25   UnfoldingEvent(const UnfoldingEvent&)            = default;
26   UnfoldingEvent& operator=(UnfoldingEvent const&) = default;
27   UnfoldingEvent(UnfoldingEvent&&)                 = default;
28
29   EventSet get_history() const;
30   EventSet get_local_config() const;
31   bool in_history_of(const UnfoldingEvent* other) const;
32
33   /**
34    * @brief Whether or not the given event is a decendant
35    * of or an ancestor of the given event
36    */
37   bool related_to(const UnfoldingEvent* other) const;
38
39   /// @brief Whether or not this event is in conflict with
40   /// the given one (i.e. whether `this # other`)
41   bool conflicts_with(const UnfoldingEvent* other) const;
42
43   /// @brief Whether or not this event is in conflict with
44   /// any event in the given set
45   bool conflicts_with_any(const EventSet& events) const;
46
47   /// @brief Computes "this #ⁱ other"
48   bool immediately_conflicts_with(const UnfoldingEvent* other) const;
49   bool is_dependent_with(const Transition*) const;
50   bool is_dependent_with(const UnfoldingEvent* other) const;
51
52   const EventSet& get_immediate_causes() const { return this->immediate_causes; }
53   Transition* get_transition() const { return this->associated_transition.get(); }
54   aid_t get_actor() const { return get_transition()->aid_; }
55
56   void set_transition(std::shared_ptr<Transition> t) { this->associated_transition = std::move(t); }
57
58   std::string to_string() const;
59
60   bool operator==(const UnfoldingEvent&) const;
61   bool operator!=(const UnfoldingEvent& other) const { return not(*this == other); }
62
63 private:
64   /**
65    * @brief The transition that UDPOR "attaches" to this
66    * specific event for later use while computing e.g. extension
67    * sets
68    *
69    * The transition points to that of a particular actor
70    * in the state reached by the configuration C (recall
71    * this is denoted `state(C)`) that excludes this event.
72    * In other words, this transition was the "next" event
73    * of the actor that executes it in `state(C)`.
74    */
75   std::shared_ptr<Transition> associated_transition;
76
77   /**
78    * @brief The "immediate" causes of this event.
79    *
80    * An event `e` is an immediate cause of an event `e'` if
81    *
82    * 1. e < e'
83    * 2. There is no event `e''` in E such that
84    * `e < e''` and `e'' < e'`
85    *
86    * Intuitively, an immediate cause "happened right before"
87    * this event was executed. It is sufficient to store
88    * only the immediate causes of any event `e`, as any indirect
89    * causes of that event would either be an indirect cause
90    * or an immediate cause of the immediate causes of `e`, and
91    * so on.
92    */
93   EventSet immediate_causes;
94 };
95
96 } // namespace simgrid::mc::udpor
97 #endif