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/Configuration.hpp"
7 #include "src/mc/explo/udpor/History.hpp"
8 #include "src/mc/explo/udpor/UnfoldingEvent.hpp"
9 #include "src/mc/explo/udpor/maximal_subsets_iterator.hpp"
10 #include "xbt/asserts.h"
15 namespace simgrid::mc::udpor {
17 Configuration::Configuration(std::initializer_list<const UnfoldingEvent*> events)
18 : Configuration(EventSet(std::move(events)))
22 Configuration::Configuration(const EventSet& events) : events_(events)
24 if (!events_.is_valid_configuration()) {
25 throw std::invalid_argument("The events do not form a valid configuration");
29 void Configuration::add_event(const UnfoldingEvent* e)
32 throw std::invalid_argument("Expected a nonnull `UnfoldingEvent*` but received NULL instead");
35 if (this->events_.contains(e)) {
39 this->events_.insert(e);
40 this->newest_event = e;
42 // Preserves the property that the configuration is valid
44 if (!this->events_.contains(history)) {
45 throw std::invalid_argument("The newly added event has dependencies "
46 "which are missing from this configuration");
50 std::vector<const UnfoldingEvent*> Configuration::get_topologically_sorted_events() const
52 return this->events_.get_topological_ordering();
55 std::vector<const UnfoldingEvent*> Configuration::get_topologically_sorted_events_of_reverse_graph() const
57 return this->events_.get_topological_ordering_of_reverse_graph();
60 EventSet Configuration::get_minimally_reproducible_events() const
62 // The implementation exploits the following observations:
64 // To select the smallest reproducible set of events, we want
65 // to pick events that "knock out" a lot of others. Furthermore,
66 // we need to ensure that the events furthest down in the
67 // causality graph are also selected. If you combine these ideas,
68 // you're basically left with traversing the set of maximal
69 // subsets of C! And we have an iterator for that already!
71 // The next observation is that the moment we don't increase in size
72 // the current maximal set (or decrease the number of events),
73 // we know that the prior set `S` covered the entire history of C and
74 // was maximal. Subsequent sets will miss events earlier in the
75 // topological ordering that appear in `S`
76 EventSet minimally_reproducible_events = EventSet();
78 for (const auto& maximal_set : maximal_subsets_iterator_wrapper<Configuration>(*this)) {
79 if (maximal_set.size() > minimally_reproducible_events.size()) {
80 minimally_reproducible_events = maximal_set;
82 // The moment we see the iterator generate a set of size
83 // that is not monotonically increasing, we can stop:
84 // the set prior was the minimally-reproducible one
85 return minimally_reproducible_events;
88 return minimally_reproducible_events;
91 } // namespace simgrid::mc::udpor