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_ODPOR_EXECUTION_HPP
7 #define SIMGRID_MC_ODPOR_EXECUTION_HPP
9 #include "src/mc/api/ClockVector.hpp"
10 #include "src/mc/explo/odpor/odpor_forward.hpp"
11 #include "src/mc/transition/Transition.hpp"
15 #include <unordered_set>
18 namespace simgrid::mc::odpor {
20 using ProcessSequence = std::list<aid_t>;
21 using ExecutionSequence = std::list<const State*>;
22 using Hypothetical = ExecutionSequence;
25 * @brief The occurrence of a transition in an execution
28 std::pair<const Transition*, ClockVector> contents_;
32 Event(Event&&) = default;
33 Event(const Event&) = default;
34 Event& operator=(const Event&) = default;
36 explicit Event(std::pair<const Transition*, ClockVector> pair) : contents_(std::move(pair)) {}
38 const Transition* get_transition() const { return std::get<0>(contents_); }
39 const ClockVector& get_clock_vector() const { return std::get<1>(contents_); }
43 * @brief An ordered sequence of transitions which describe
44 * the evolution of a process undergoing model checking
46 * An execution conceptually is just a string of actors
47 * ids (e.g. "1.2.3.1.2.2.1.1"), where the `i`th occurrence
48 * of actor id `j` corresponds to the `i`th action executed
49 * by the actor with id `j` (viz. the `i`th step of actor `j`).
50 * Executions can stand alone on their own or can extend
51 * the execution of other sequences
53 * Executions are conceived based on the following papers:
54 * 1. "Source Sets: A Foundation for Optimal Dynamic Partial Order Reduction"
57 * In addition to representing an actual steps taken,
58 * an execution keeps track of the "happens-before"
59 * relation among the transitions in the execution
60 * by following the procedure outlined in the
61 * original DPOR paper with clock vectors
63 * @note: For more nuanced happens-before relations, clock
64 * vectors may not always suffice. Clock vectors work
65 * well with transition-based dependencies like that used in
66 * SimGrid; but to have a more refined independence relation,
67 * an event-based dependency approach is needed. See the section 2
68 * in the ODPOR paper [1] concerning event-based dependencies and
69 * how the happens-before relation can be refined in a
70 * computation model much like that of SimGrid. In fact, the same issue
71 * arrises with UDPOR with context-sensitive dependencies:
72 * the two concepts are analogous if not identical
77 * @brief The actual steps that are taken by the process
78 * during exploration, relative to the
80 std::vector<Event> contents_;
83 using Handle = decltype(contents_)::const_iterator;
84 using EventHandle = uint32_t;
86 Execution() = default;
87 Execution(const Execution&) = default;
88 Execution& operator=(Execution const&) = default;
89 Execution(Execution&&) = default;
91 Execution(ExecutionSequence&& seq, std::optional<Handle> base = {});
92 Execution(const ExecutionSequence& seq, std::optional<Handle> base = {});
94 std::unordered_set<aid_t> get_initials_after(const Hypothetical& w) const;
95 std::unordered_set<aid_t> get_weak_initials_after(const Hypothetical& w) const;
97 bool is_initial(aid_t p, const Hypothetical& w) const;
98 bool is_weak_initial(aid_t p, const Hypothetical& w) const;
100 const Event& get_event_with_handle(EventHandle handle) const { return contents_[handle]; }
101 aid_t get_actor_with_handle(EventHandle handle) const { return get_event_with_handle(handle).get_transition()->aid_; }
104 * @brief Returns a set of IDs of events which are in
105 * "immediate conflict" (according to the definition given
106 * in the ODPOR paper) with one another
108 std::unordered_set<EventHandle> get_racing_events_of(EventHandle) const;
111 * @brief Returns a handle to the newest event of the execution,
112 * if such an event exists
114 std::optional<EventHandle> get_latest_event_handle() const
116 return contents_.empty() ? std::nullopt : std::optional<EventHandle>{static_cast<EventHandle>(size() - 1)};
119 Execution get_prefix_up_to(EventHandle);
122 * @brief Whether the event represented by `e1`
123 * "happens-before" the event represented by
124 * `e2` in the context of this execution
126 * In the terminology of the ODPOR paper,
127 * this function computes
131 * where `E` is this execution
133 bool happens_before(EventHandle e1, EventHandle e2) const;
136 * @brief Removes the last event of the execution,
137 * if such an event exists
139 * @note: When you remove events from an execution, any views
140 * of the execution referring to those removed events
146 * @brief Extends the execution by one more step
148 * Intutively, pushing a transition `t` onto execution `E`
149 * is equivalent to making the execution become (using the
150 * notation of [1]) `E.proc(t)` where `proc(t)` is the
151 * actor which executed transition `t`.
153 void push_transition(const Transition*);
156 * @brief The total number of steps contained in the execution
158 size_t size() const { return this->contents_.size(); }
161 } // namespace simgrid::mc::odpor