Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add incomplete implementations of udpor_globals.cpp
[simgrid.git] / src / mc / udpor_global.cpp
1 /* Copyright (c) 2008-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 #include "udpor_global.hpp"
7 #include "xbt/log.h"
8
9 #include <algorithm>
10 #include <iterator>
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_udpor_global, mc, "udpor_global");
13
14 namespace simgrid::mc::udpor {
15
16 void EventSet::remove(UnfoldingEvent* e)
17 {
18   this->events_.erase(e);
19 }
20
21 void EventSet::subtract(const EventSet& other)
22 {
23   this->events_ = std::move(subtracting(other).events_);
24 }
25
26 // void EventSet::subtract(const Configuration& other);
27
28 EventSet EventSet::subtracting(const EventSet& other) const
29 {
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));
34 }
35
36 EventSet EventSet::subtracting(UnfoldingEvent* e) const
37 {
38   auto result = this->events_;
39   result.erase(e);
40   return EventSet(std::move(result));
41 }
42 // EventSet EventSet::subtracting(const Configuration* e) const;
43
44 void EventSet::insert(UnfoldingEvent* e)
45 {
46   // TODO: Potentially react if the event is already inserted
47   this->events_.insert(e);
48 }
49
50 void EventSet::form_union(const EventSet& other)
51 {
52   this->events_ = std::move(make_union(other).events_);
53 }
54
55 // void EventSet::form_union(const Configuration&);
56 EventSet EventSet::make_union(UnfoldingEvent* e) const
57 {
58   auto result = this->events_;
59   result.insert(e);
60   return EventSet(std::move(result));
61 }
62
63 EventSet EventSet::make_union(const EventSet& other) const
64 {
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));
69 }
70
71 // EventSet EventSet::make_union(const Configuration& e) const;
72
73 size_t EventSet::size() const
74 {
75   return this->events_.size();
76 }
77
78 bool EventSet::empty() const
79 {
80   return this->events_.empty();
81 }
82
83 bool EventSet::contains(UnfoldingEvent* e) const
84 {
85   return this->events_.find(e) != this->events_.end();
86 }
87
88 bool EventSet::is_subset_of(const EventSet& other) const
89 {
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();
94 }
95
96 void Configuration::add_event(UnfoldingEvent* e)
97 {
98   this->events_.insert(e);
99
100   // Re-compute the maxmimal events
101 }
102
103 UnfoldingEvent::UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& causes,
104                                StateHandle sid)
105 {
106   // TODO: Implement this
107 }
108
109 StateManager::Handle StateManager::record_state(const std::unique_ptr<State>&& state)
110 {
111   // // TODO: Throw an error perhaps if the state is nullptr?
112
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});
118
119   // const auto&& state2 = std::move(state);
120
121   // const auto integer_handle = this->current_handle_;
122   // this->state_map_.insert(std::make_pair(std::move(integer_handle), state2));
123
124   // // Increment the current handle
125   // // TODO: Check for state handle overflow!
126   // this->current_handle_++;
127   return 0;
128 }
129
130 std::optional<std::reference_wrapper<State>> StateManager::get_state(StateManager::Handle handle)
131 {
132   // TODO: Return the actual state based on the handle provided
133   return std::nullopt;
134 }
135
136 } // namespace simgrid::mc::udpor