1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_MC_UDPOR_CONFIGURATION_HPP
7 #define SIMGRID_MC_UDPOR_CONFIGURATION_HPP
9 #include "src/mc/explo/udpor/EventSet.hpp"
10 #include "src/mc/explo/udpor/udpor_forward.hpp"
12 namespace simgrid::mc::udpor {
14 using StateHandle = uint64_t;
18 Configuration() = default;
19 Configuration(const Configuration&) = default;
20 Configuration& operator=(Configuration const&) = default;
21 Configuration(Configuration&&) = default;
23 inline auto begin() const { return this->events_.begin(); }
24 inline auto end() const { return this->events_.end(); }
25 inline const EventSet& get_events() const { return this->events_; }
26 inline const EventSet& get_maximal_events() const { return this->max_events_; }
28 void add_event(UnfoldingEvent*);
29 UnfoldingEvent* get_latest_event() const;
33 * @brief The most recent event added to the configuration
35 UnfoldingEvent* newest_event = nullptr;
39 * The <-maxmimal events of the configuration. These are
40 * dynamically adjusted as events are added to the configuration
42 * @invariant: Each event that is part of this set is
44 * 1. a <-maxmimal event of the configuration, in the sense that
45 * there is no event in the configuration that is "greater" than it.
46 * In UDPOR terminology, each event does not "cause" another event
48 * 2. contained in the set of events `events_` which comprise
54 void recompute_maxmimal_events(UnfoldingEvent* new_event);
57 class UnfoldingEvent {
59 UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& immediate_causes,
61 UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& immediate_causes);
62 UnfoldingEvent(const UnfoldingEvent&) = default;
63 UnfoldingEvent& operator=(UnfoldingEvent const&) = default;
64 UnfoldingEvent(UnfoldingEvent&&) = default;
66 EventSet get_history() const;
67 bool in_history(const UnfoldingEvent* otherEvent) const;
69 bool conflicts_with(const UnfoldingEvent* otherEvent) const;
70 bool conflicts_with(const Configuration& config) const;
71 bool immediately_conflicts_with(const UnfoldingEvent* otherEvt) const;
73 bool operator==(const UnfoldingEvent&) const { return false; };
75 inline StateHandle get_state_id() const { return state_id; }
76 inline void set_state_id(StateHandle sid) { state_id = sid; }
82 * @brief The "immediate" causes of this event.
84 * An event `e` is an immediate cause of an event `e'` if
87 * 2. There is no event `e''` in E such that
88 * `e < e''` and `e'' < e'`
90 * Intuitively, an immediate cause "happened right before"
91 * this event was executed. It is sufficient to store
92 * only the immediate causes of any event `e`, as any indirect
93 * causes of that event would either be an indirect cause
94 * or an immediate cause of the immediate causes of `e`, and
97 EventSet immediate_causes;
98 StateHandle state_id = 0ul;
103 using Handle = StateHandle;
105 Handle current_handle_ = 1ul;
106 std::unordered_map<Handle, std::unique_ptr<State>> state_map_;
109 Handle record_state(std::unique_ptr<State>);
110 std::optional<std::reference_wrapper<State>> get_state(Handle);
113 } // namespace simgrid::mc::udpor