Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add tests for adding events to configurations
[simgrid.git] / src / mc / explo / udpor / Configuration.hpp
1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_MC_UDPOR_CONFIGURATION_HPP
7 #define SIMGRID_MC_UDPOR_CONFIGURATION_HPP
8
9 #include "src/mc/explo/udpor/EventSet.hpp"
10 #include "src/mc/explo/udpor/udpor_forward.hpp"
11
12 #include <initializer_list>
13
14 namespace simgrid::mc::udpor {
15
16 class Configuration {
17 public:
18   Configuration()                                = default;
19   Configuration(const Configuration&)            = default;
20   Configuration& operator=(Configuration const&) = default;
21   Configuration(Configuration&&)                 = default;
22
23   Configuration(EventSet events);
24   Configuration(std::initializer_list<UnfoldingEvent*> events);
25
26   auto begin() const { return this->events_.begin(); }
27   auto end() const { return this->events_.end(); }
28
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; }
32
33   /**
34    * @brief Insert a new event into the configuration
35    *
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.
40    *
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
43    * effect.
44    *
45    * @throws an invalid argument exception is raised should the event
46    * be missing one of its dependencies
47    *
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
58    * assertions)
59    */
60   void add_event(UnfoldingEvent* e);
61
62 private:
63   /**
64    * @brief The most recent event added to the configuration
65    */
66   UnfoldingEvent* newest_event = nullptr;
67
68   /**
69    * @brief The events which make up this configuration
70    *
71    * @invariant For each event `e` in `events_`, the set of
72    * dependencies of `e` is also contained in `events_`
73    */
74   EventSet events_;
75 };
76
77 } // namespace simgrid::mc::udpor
78 #endif