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;
36 // EventSet(const Configuration&);
37 // EventSet(Configuration&&);
39 void remove(UnfoldingEvent* e);
40 void subtract(const EventSet& other);
41 void subtract(const Configuration& other);
42 EventSet subtracting(UnfoldingEvent* e) const;
43 EventSet subtracting(const EventSet& e) const;
44 EventSet subtracting(const Configuration* e) const;
46 void insert(UnfoldingEvent* e);
47 void form_union(const EventSet&);
48 void form_union(const Configuration&);
49 EventSet make_union(UnfoldingEvent* e) const;
50 EventSet make_union(const EventSet&) const;
51 EventSet make_union(const Configuration& e) const;
55 bool contains(UnfoldingEvent* e) const;
56 bool is_subset_of(const EventSet& other) const;
58 // // TODO: What is this used for?
59 // UnfoldingEvent* find(const UnfoldingEvent* e) const;
61 // // TODO: What is this used for
62 // bool depends(const EventSet& other) const;
64 // // TODO: What is this used for
65 // bool is_empty_intersection(EventSet evtS) const;
69 EventSet causuality_events;
76 Configuration() = default;
77 Configuration(const Configuration&) = default;
78 Configuration& operator=(Configuration const&) = default;
79 Configuration(Configuration&&) = default;
81 // EventSet maxEvent; // Events recently added to events_
82 // EventSet actorMaxEvent; // maximal events of the actors in current configuration
83 // UnfoldingEvent* lastEvent; // The last added event
85 inline const EventSet& get_events() const { return this->events_; }
86 inline const EventSet& get_maxmimal_events() const { return this->max_events_; }
88 void add_event(UnfoldingEvent*);
90 // Configuration plus_config(UnfoldingEvent*) const;
92 // void createEvts(Configuration C, EventSet& result, const std::string& trans_tag, s_evset_in_t ev_sets, bool chk,
93 // UnfoldingEvent* immPreEvt);
95 // void updateMaxEvent(UnfoldingEvent*); // update maximal events of the configuration and actors
96 // UnfoldingEvent* findActorMaxEvt(int actorId); // find maximal event of a Actor whose id = actorId
98 // UnfoldingEvent* findTestedComm(const UnfoldingEvent* testEvt); // find comm tested by action testTrans
103 * The <-maxmimal events of the configuration. These are
104 * dynamically adjusted as events are added to the configuration
106 * @invariant: Each event that is part of this set is
108 * 1. A <-maxmimal event of the configuration, in the sense that
109 * there is no event in the configuration that is "greater" than it
111 EventSet max_events_;
114 void recompute_maxmimal_events(UnfoldingEvent* new_event);
117 class UnfoldingEvent {
119 UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& causes, StateHandle sid);
120 UnfoldingEvent(const UnfoldingEvent&) = default;
121 UnfoldingEvent& operator=(UnfoldingEvent const&) = default;
122 UnfoldingEvent(UnfoldingEvent&&) = default;
124 EventSet get_history() const;
125 bool in_history(const UnfoldingEvent* otherEvent) const;
127 // bool concernSameComm(const UnfoldingEvent* event, const UnfoldingEvent* otherEvent) const;
129 bool conflicts_with(const UnfoldingEvent* otherEvent) const;
130 bool conflicts_with(const Configuration& config) const;
131 bool immediately_conflicts_with(const UnfoldingEvent* otherEvt) const;
133 bool operator==(const UnfoldingEvent&) const { return false; };
137 inline StateHandle get_state_id() const { return state_id; }
138 inline void set_state_id(StateHandle sid) { state_id = sid; }
140 // inline std::string get_transition_tag() const { return transition_tag; }
141 // inline void set_transition_tag(std::string_view tr_tag) { transition_tag = tr_tag; }
144 EventSet causes; // used to store directed ancestors of event e
146 StateHandle state_id;
147 // std::string transition_tag{""}; // The tag of the last transition that lead to creating the event
148 // bool transition_is_IReceive(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
149 // bool transition_is_ISend(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
150 // bool check_tr_concern_same_comm(bool& chk1, bool& chk2, UnfoldingEvent* evt1, UnfoldingEvent* evt2) const;
155 using Handle = StateHandle;
157 Handle current_handle_ = 0ul;
158 std::map<Handle, std::unique_ptr<State>> state_map_;
161 Handle record_state(const std::unique_ptr<State>&&);
162 std::optional<std::reference_wrapper<State>> get_state(Handle);
165 } // namespace simgrid::mc::udpor