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_UNFOLDING_HPP
7 #define SIMGRID_MC_UDPOR_UNFOLDING_HPP
9 #include "src/mc/explo/udpor/EventSet.hpp"
10 #include "src/mc/explo/udpor/UnfoldingEvent.hpp"
11 #include "src/mc/explo/udpor/udpor_forward.hpp"
14 #include <unordered_map>
16 namespace simgrid::mc::udpor {
20 Unfolding() = default;
21 Unfolding& operator=(Unfolding&&) = default;
22 Unfolding(Unfolding&&) = default;
24 auto begin() const { return this->event_handles.begin(); }
25 auto end() const { return this->event_handles.end(); }
26 auto cbegin() const { return this->event_handles.cbegin(); }
27 auto cend() const { return this->event_handles.cend(); }
28 size_t size() const { return this->event_handles.size(); }
29 bool empty() const { return this->event_handles.empty(); }
32 * @brief Moves an event from UDPOR's global set `U` to
35 void mark_finished(const UnfoldingEvent* e);
38 * @brief Moves all events in a set from UDPOR's global
39 * set `U` to the global set `G`
41 void mark_finished(const EventSet& events);
43 /// @brief Adds a new event `e` to the Unfolding if that
44 /// event is not equivalent to any of those already contained
46 const UnfoldingEvent* insert(std::unique_ptr<UnfoldingEvent> e);
49 * @brief Informs the unfolding of a (potentially) new event
51 * The unfolding of a concurrent program is a well-defined
52 * structure. Given the labeled transition system (LTS) of
53 * a program, the unfolding of that program can be determined
54 * algorithmically. However, UDPOR does not a priori know the structure of the
55 * unfolding as it performs its exploration. Thus, events in the
56 * unfolding are "discovered" as they are encountered, specifically
57 * when computing the extension sets of the configurations that
58 * UDPOR decides to search.
60 * This lends itself to the following problem: the extension sets
61 * of two different configurations may overlap one another. That
62 * is, for two configurations C and C' explored by UDPOR where C != C',
64 * ex(C) - ex(C') != empty
66 * Hence, when extending both `C` and `C'`, any events contained in
67 * the intersection of ex(C) and ex(C') will be attempted to be added
68 * twice. The unfolding will notice that these events have already
69 * been added and simply return the event already added to the unfolding
71 * @tparam ...Args arguments passed to the `UnfoldingEvent` constructor
72 * @return the handle to either the newly created event OR
73 * to an equivalent event that was already noted by the unfolding
74 * at some point in the past
76 template <typename... Args> const UnfoldingEvent* discover_event(Args&&... args)
78 auto candidate_event = std::make_unique<UnfoldingEvent>(std::forward<Args>(args)...);
79 return insert(std::move(candidate_event));
82 /// @brief Computes "#ⁱ_U(e)" for the given event, where `U` is the set
83 /// of the events in this unfolding
84 EventSet get_immediate_conflicts_of(const UnfoldingEvent*) const;
88 * @brief All of the events that are currently are a part of the unfolding
90 * @invariant Each unfolding event maps itself to the owner of that event,
91 * i.e. the unique pointer that manages the data at the address. The Unfolding owns all
92 * of the addresses that are referenced by EventSet instances and Configuration
93 * instances. UDPOR guarantees that events are persisted for as long as necessary
95 std::unordered_map<const UnfoldingEvent*, std::unique_ptr<UnfoldingEvent>> global_events_;
98 * @brief: The collection of events in the unfolding
100 * @invariant: All of the events in this set are elements of `global_events_`
101 * and is kept updated at the same time as `global_events_`
103 * @note: This is for the convenience of iteration over the unfolding
105 EventSet event_handles;
108 * @brief: The collection of events in the unfolding that are "important"
113 * @brief The "irrelevant" portions of the unfolding that do not need to be kept
114 * around to ensure that UDPOR functions correctly
116 * The set `G` is another global variable maintained by the UDPOR algorithm which
117 * is used to keep track of all events which used to be important to UDPOR.
122 } // namespace simgrid::mc::udpor