1 /* Copyright (c) 2007-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 #ifndef SIMGRID_MC_UDPOR_GLOBAL_HPP
7 #define SIMGRID_MC_UDPOR_GLOBAL_HPP
9 #include "src/mc/api/State.hpp"
15 #include <string_view>
17 /* TODO: many method declared in this module are not implemented */
19 namespace simgrid::mc::udpor {
23 using StateHandle = uint64_t;
27 std::set<UnfoldingEvent*> events_;
28 explicit EventSet(std::set<UnfoldingEvent*>&& raw_events) : events_(raw_events) {}
32 EventSet(const EventSet&) = default;
33 EventSet& operator=(const EventSet&) = default;
34 EventSet& operator=(EventSet&&) = default;
35 EventSet(EventSet&&) = default;
37 inline auto begin() const { return this->events_.begin(); }
38 inline auto end() const { return this->events_.end(); }
40 void remove(UnfoldingEvent* e);
41 void subtract(const EventSet& other);
42 void subtract(const Configuration& other);
43 EventSet subtracting(UnfoldingEvent* e) const;
44 EventSet subtracting(const EventSet& e) const;
45 EventSet subtracting(const Configuration* e) const;
47 void insert(UnfoldingEvent* e);
48 void form_union(const EventSet&);
49 void form_union(const Configuration&);
50 EventSet make_union(UnfoldingEvent* e) const;
51 EventSet make_union(const EventSet&) const;
52 EventSet make_union(const Configuration& e) const;
56 bool contains(UnfoldingEvent* e) const;
57 bool is_subset_of(const EventSet& other) const;
59 // // TODO: What is this used for?
60 // UnfoldingEvent* find(const UnfoldingEvent* e) const;
62 // // TODO: What is this used for
63 // bool depends(const EventSet& other) const;
65 // // TODO: What is this used for
66 // bool is_empty_intersection(EventSet evtS) const;
70 EventSet causuality_events;
77 Configuration() = default;
78 Configuration(const Configuration&) = default;
79 Configuration& operator=(Configuration const&) = default;
80 Configuration(Configuration&&) = default;
82 // EventSet maxEvent; // Events recently added to events_
83 // EventSet actorMaxEvent; // maximal events of the actors in current configuration
84 // UnfoldingEvent* lastEvent; // The last added event
86 inline auto begin() const { return this->events_.begin(); }
87 inline auto end() const { return this->events_.end(); }
88 inline const EventSet& get_events() const { return this->events_; }
89 inline const EventSet& get_maxmimal_events() const { return this->max_events_; }
91 void add_event(UnfoldingEvent*);
93 // Configuration plus_config(UnfoldingEvent*) const;
95 // void createEvts(Configuration C, EventSet& result, const std::string& trans_tag, s_evset_in_t ev_sets, bool chk,
96 // UnfoldingEvent* immPreEvt);
98 // void updateMaxEvent(UnfoldingEvent*); // update maximal events of the configuration and actors
99 // UnfoldingEvent* findActorMaxEvt(int actorId); // find maximal event of a Actor whose id = actorId
101 // UnfoldingEvent* findTestedComm(const UnfoldingEvent* testEvt); // find comm tested by action testTrans
106 * The <-maxmimal events of the configuration. These are
107 * dynamically adjusted as events are added to the configuration
109 * @invariant: Each event that is part of this set is
111 * 1. A <-maxmimal event of the configuration, in the sense that
112 * there is no event in the configuration that is "greater" than it
114 EventSet max_events_;
117 void recompute_maxmimal_events(UnfoldingEvent* new_event);
120 class UnfoldingEvent {
122 UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& causes, StateHandle sid);
123 UnfoldingEvent(const UnfoldingEvent&) = default;
124 UnfoldingEvent& operator=(UnfoldingEvent const&) = default;
125 UnfoldingEvent(UnfoldingEvent&&) = default;
127 EventSet get_history() const;
128 bool in_history(const UnfoldingEvent* otherEvent) const;
130 // bool concernSameComm(const UnfoldingEvent* event, const UnfoldingEvent* otherEvent) const;
132 bool conflicts_with(const UnfoldingEvent* otherEvent) const;
133 bool conflicts_with(const Configuration& config) const;
134 bool immediately_conflicts_with(const UnfoldingEvent* otherEvt) const;
136 bool operator==(const UnfoldingEvent&) const { return false; };
140 inline StateHandle get_state_id() const { return state_id; }
141 inline void set_state_id(StateHandle sid) { state_id = sid; }
143 // inline std::string get_transition_tag() const { return transition_tag; }
144 // inline void set_transition_tag(std::string_view tr_tag) { transition_tag = tr_tag; }
147 EventSet causes; // used to store directed ancestors of event e
149 StateHandle state_id;
150 // std::string transition_tag{""}; // The tag of the last transition that lead to creating the event
151 // bool transition_is_IReceive(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
152 // bool transition_is_ISend(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
153 // bool check_tr_concern_same_comm(bool& chk1, bool& chk2, UnfoldingEvent* evt1, UnfoldingEvent* evt2) const;
158 using Handle = StateHandle;
160 Handle current_handle_ = 0ul;
161 std::unordered_map<Handle, std::unique_ptr<State>> state_map_;
164 Handle record_state(std::unique_ptr<State>);
165 std::optional<std::reference_wrapper<State>> get_state(Handle);
168 } // namespace simgrid::mc::udpor