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>
14 namespace simgrid::mc::udpor {
18 Configuration() = default;
19 Configuration(const Configuration&) = default;
20 Configuration& operator=(Configuration const&) = default;
21 Configuration(Configuration&&) = default;
23 Configuration(EventSet events);
24 Configuration(std::initializer_list<UnfoldingEvent*> events);
26 auto begin() const { return this->events_.begin(); }
27 auto end() const { return this->events_.end(); }
29 bool contains(UnfoldingEvent* e) const { return this->events_.contains(e); }
30 const EventSet& get_events() const { return this->events_; }
31 UnfoldingEvent* get_latest_event() const { return this->newest_event; }
34 * @brief Insert a new event into the configuration
36 * When the newly added event is inserted into the configuration,
37 * an assertion is made to ensure that the configuration remains
38 * valid, i.e. that the newly added event's dependencies are contained
39 * within the configuration.
41 * @param e the event to add to the configuration. If the event is
42 * already a part of the configuration, calling this method has no
45 * @throws an invalid argument exception is raised should the event
46 * be missing one of its dependencies
48 * @note: UDPOR technically enforces the invariant that all newly-added events
49 * will ensure that the configuration is valid. We perform extra checks to ensure
50 * that UDPOR is implemented as expected. There is a performance penalty that
51 * should be noted: checking for maximality requires ensuring that all events in the
52 * configuration have their dependencies containes within the configuration, which
53 * essentially means performing a BFS/DFS over the configuration using a History object.
54 * However, since the slowest part of UDPOR involves enumerating all
55 * subsets of maximal events and computing k-partial alternatives (the
56 * latter definitively an NP-hard problem when optimal), Amdahl's law suggests
57 * we shouldn't focus so much on this (let alone the additional benefit of the
60 void add_event(UnfoldingEvent* e);
64 * @brief The most recent event added to the configuration
66 UnfoldingEvent* newest_event = nullptr;
69 * @brief The events which make up this configuration
71 * @invariant For each event `e` in `events_`, the set of
72 * dependencies of `e` is also contained in `events_`
77 } // namespace simgrid::mc::udpor