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 "udpor_global.hpp"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_udpor_global, mc, "udpor_global");
14 namespace simgrid::mc::udpor {
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& other);
28 EventSet EventSet::subtracting(const EventSet& other) const
30 std::set<UnfoldingEvent*> result;
31 std::set_difference(this->events_.begin(), this->events_.end(), other.events_.begin(), other.events_.end(),
32 std::inserter(result, result.end()));
33 return EventSet(std::move(result));
36 EventSet EventSet::subtracting(UnfoldingEvent* e) const
38 auto result = this->events_;
40 return EventSet(std::move(result));
42 // EventSet EventSet::subtracting(const Configuration* e) const;
44 void EventSet::insert(UnfoldingEvent* e)
46 // TODO: Potentially react if the event is already inserted
47 this->events_.insert(e);
50 void EventSet::form_union(const EventSet& other)
52 this->events_ = std::move(make_union(other).events_);
55 // void EventSet::form_union(const Configuration&);
56 EventSet EventSet::make_union(UnfoldingEvent* e) const
58 auto result = this->events_;
60 return EventSet(std::move(result));
63 EventSet EventSet::make_union(const EventSet& other) const
65 std::set<UnfoldingEvent*> result;
66 std::set_union(this->events_.begin(), this->events_.end(), other.events_.begin(), other.events_.end(),
67 std::inserter(result, result.end()));
68 return EventSet(std::move(result));
71 // EventSet EventSet::make_union(const Configuration& e) const;
73 size_t EventSet::size() const
75 return this->events_.size();
78 bool EventSet::empty() const
80 return this->events_.empty();
83 bool EventSet::contains(UnfoldingEvent* e) const
85 return this->events_.find(e) != this->events_.end();
88 bool EventSet::is_subset_of(const EventSet& other) const
90 // If there is some element not contained in `other`, then
91 // the set difference will contain that element and the
92 // result won't be empty
93 return subtracting(other).empty();
96 void Configuration::add_event(UnfoldingEvent* e)
98 this->events_.insert(e);
100 // Re-compute the maxmimal events
103 UnfoldingEvent::UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& causes,
106 // TODO: Implement this
109 StateManager::Handle StateManager::record_state(const std::unique_ptr<State>&& state)
111 // // TODO: Throw an error perhaps if the state is nullptr?
113 // // std::map<int, std::unique_ptr<int>> a;
114 // // auto test = std::make_unique<int>(10);
115 // // std::move(state);
116 // // // const auto&& ab = std::move(test);
117 // // a.insert({1, test});
119 // const auto&& state2 = std::move(state);
121 // const auto integer_handle = this->current_handle_;
122 // this->state_map_.insert(std::make_pair(std::move(integer_handle), state2));
124 // // Increment the current handle
125 // // TODO: Check for state handle overflow!
126 // this->current_handle_++;
130 std::optional<std::reference_wrapper<State>> StateManager::get_state(StateManager::Handle handle)
132 // TODO: Return the actual state based on the handle provided
136 } // namespace simgrid::mc::udpor