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 #include <initializer_list>
15 namespace simgrid::mc::udpor {
19 Configuration() = default;
20 Configuration(const Configuration&) = default;
21 Configuration& operator=(Configuration const&) = default;
22 Configuration(Configuration&&) = default;
24 Configuration(EventSet events);
25 Configuration(std::initializer_list<UnfoldingEvent*> events);
27 auto begin() const { return this->events_.begin(); }
28 auto end() const { return this->events_.end(); }
30 bool contains(UnfoldingEvent* e) const { return this->events_.contains(e); }
31 const EventSet& get_events() const { return this->events_; }
32 UnfoldingEvent* get_latest_event() const { return this->newest_event; }
35 * @brief Insert a new event into the configuration
37 * When the newly added event is inserted into the configuration,
38 * an assertion is made to ensure that the configuration remains
39 * valid, i.e. that the newly added event's dependencies are contained
40 * within the configuration.
42 * @param e the event to add to the configuration. If the event is
43 * already a part of the configuration, calling this method has no
46 * @throws an invalid argument exception is raised should the event
47 * be missing one of its dependencies
49 * @note: UDPOR technically enforces the invariant that all newly-added events
50 * will ensure that the configuration is valid. We perform extra checks to ensure
51 * that UDPOR is implemented as expected. There is a performance penalty that
52 * should be noted: checking for maximality requires ensuring that all events in the
53 * configuration have their dependencies containes within the configuration, which
54 * essentially means performing a BFS/DFS over the configuration using a History object.
55 * However, since the slowest part of UDPOR involves enumerating all
56 * subsets of maximal events and computing k-partial alternatives (the
57 * latter definitively an NP-hard problem when optimal), Amdahl's law suggests
58 * we shouldn't focus so much on this (let alone the additional benefit of the
61 void add_event(UnfoldingEvent* e);
64 * @brief Orders the events of the configuration such that
65 * "more recent" events (i.e. those that are farther down in
66 * the event structure's dependency chain) come after those
67 * that appeared "farther in the past"
69 * @returns a vector `V` with the following property:
71 * 1. Let i(e) := C -> I map events to their indices in `V`.
72 * For every pair of events e, e' in C, if e < e' then i(e) < i(e')
74 * Intuitively, events that are closer to the "bottom" of the event
75 * structure appear farther along in the list than those that appear
78 std::vector<UnfoldingEvent*> get_topologically_sorted_events() const;
81 * @brief Orders the events of the configuration such that
82 * "more recent" events (i.e. those that are farther down in
83 * the event structure's dependency chain) come before those
84 * that appear "farther in the past"
86 * @note The events of the event structure are arranged such that
87 * e < e' implies a directed edge from e to e'. However, it is
88 * also useful to be able to traverse the *reverse* graph (for
89 * example when computing the compatibility graph of a configuration),
90 * hence the distinction between "reversed" and the method
91 * "Configuration::get_topologically_sorted_events()"
93 * @returns a vector `V` with the following property:
95 * 1. Let i(e) := C -> I map events to their indices in `V`.
96 * For every pair of events e, e' in C, if e < e' then i(e) > i(e')
98 * Intuitively, events that are closer to the "top" of the event
99 * structure appear farther along in the list than those that appear
100 * closer to the "bottom"
102 std::vector<UnfoldingEvent*> get_topologically_sorted_events_of_reverse_graph() const;
106 * @brief The most recent event added to the configuration
108 UnfoldingEvent* newest_event = nullptr;
111 * @brief The events which make up this configuration
113 * @invariant For each event `e` in `events_`, the set of
114 * dependencies of `e` is also contained in `events_`
119 } // namespace simgrid::mc::udpor