1 /* Copyright (c) 2008-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 #include "src/mc/explo/udpor/EventSet.hpp"
7 #include "src/mc/explo/udpor/Configuration.hpp"
8 #include "src/mc/explo/udpor/History.hpp"
12 namespace simgrid::mc::udpor {
14 EventSet::EventSet(Configuration&& config) : EventSet(std::move(config.get_events())) {}
16 void EventSet::remove(UnfoldingEvent* e)
18 this->events_.erase(e);
21 void EventSet::subtract(const EventSet& other)
23 this->events_ = std::move(subtracting(other).events_);
26 void EventSet::subtract(const Configuration& config)
28 subtract(config.get_events());
31 EventSet EventSet::subtracting(const EventSet& other) const
33 std::unordered_set<UnfoldingEvent*> result = this->events_;
35 for (UnfoldingEvent* e : other.events_)
38 return EventSet(std::move(result));
41 EventSet EventSet::subtracting(const Configuration& config) const
43 return subtracting(config.get_events());
46 EventSet EventSet::subtracting(UnfoldingEvent* e) const
48 auto result = this->events_;
50 return EventSet(std::move(result));
53 void EventSet::insert(UnfoldingEvent* e)
55 this->events_.insert(e);
58 void EventSet::form_union(const EventSet& other)
60 this->events_ = std::move(make_union(other).events_);
63 void EventSet::form_union(const Configuration& config)
65 form_union(config.get_events());
68 EventSet EventSet::make_union(UnfoldingEvent* e) const
70 auto result = this->events_;
72 return EventSet(std::move(result));
75 EventSet EventSet::make_union(const EventSet& other) const
77 std::unordered_set<UnfoldingEvent*> result = this->events_;
79 for (UnfoldingEvent* e : other.events_)
82 return EventSet(std::move(result));
85 EventSet EventSet::make_union(const Configuration& config) const
87 return make_union(config.get_events());
90 size_t EventSet::size() const
92 return this->events_.size();
95 bool EventSet::empty() const
97 return this->events_.empty();
100 bool EventSet::contains(UnfoldingEvent* e) const
102 return this->events_.find(e) != this->events_.end();
105 bool EventSet::is_subset_of(const EventSet& other) const
107 // If there is some element not contained in `other`, then
108 // the set difference will contain that element and the
109 // result won't be empty
110 return subtracting(other).empty();
113 bool EventSet::is_valid_configuration() const
115 /// @invariant: A collection of events `E` is a configuration
116 /// if and only if following while following the history of
117 /// each event `e` of `E`you remain in `E`. In other words, you
118 /// only see events from set `E`
120 /// The proof is based on the definition of a configuration
121 /// which requires that all
122 const History history(*this);
123 return this->contains(history);
126 bool EventSet::contains(const History& history) const
128 return std::all_of(history.begin(), history.end(), [=](UnfoldingEvent* e) { return this->contains(e); });
131 bool EventSet::is_maximal_event_set() const
133 const History history(*this);
134 return *this == history.get_all_maximal_events();
137 } // namespace simgrid::mc::udpor