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"
14 #include <string_view>
16 /* TODO: many method declared in this module are not implemented */
18 namespace simgrid::mc::udpor {
25 std::set<UnfoldingEvent*> events_;
29 EventSet(const EventSet&) = default;
30 EventSet& operator=(const EventSet&) = default;
31 EventSet(EventSet&&) = default;
32 EventSet(const Configuration&);
34 void remove(const UnfoldingEvent* e);
35 void subtract(const EventSet& other);
36 void subtract(const Configuration& other);
37 EventSet subtracting(const EventSet& e) const;
38 EventSet subtracting(const UnfoldingEvent* e) const;
39 EventSet subtracting(const Configuration* e) const;
41 void insert(UnfoldingEvent* e);
42 void form_union(const EventSet&);
43 void form_union(const Configuration&);
44 EventSet make_union(const UnfoldingEvent* e) const;
45 EventSet make_union(const EventSet&) const;
46 EventSet make_union(const Configuration& e) const;
50 bool contains(const UnfoldingEvent* e) const;
51 bool is_subset_of(const EventSet& other) const;
53 // TODO: What is this used for?
54 UnfoldingEvent* find(const UnfoldingEvent* e) const;
56 // TODO: What is this used for
57 bool depends(const EventSet& other) const;
59 // TODO: What is this used for
60 bool is_empty_intersection(EventSet evtS) const;
64 EventSet causuality_events;
71 Configuration() = default;
72 Configuration(const Configuration&) = default;
73 Configuration& operator=(Configuration const&) = default;
74 Configuration(Configuration&&) = default;
77 EventSet maxEvent; // Events recently added to events_
78 EventSet actorMaxEvent; // maximal events of the actors in current configuration
79 UnfoldingEvent* lastEvent; // The last added event
81 Configuration plus_config(UnfoldingEvent*) const;
83 void createEvts(Configuration C, EventSet& result, const std::string& trans_tag, s_evset_in_t ev_sets, bool chk,
84 UnfoldingEvent* immPreEvt);
86 void updateMaxEvent(UnfoldingEvent*); // update maximal events of the configuration and actors
87 UnfoldingEvent* findActorMaxEvt(int actorId); // find maximal event of a Actor whose id = actorId
89 UnfoldingEvent* findTestedComm(const UnfoldingEvent* testEvt); // find comm tested by action testTrans
92 class UnfoldingEvent {
94 UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& causes, int sid = -1);
95 UnfoldingEvent(const UnfoldingEvent&) = default;
96 UnfoldingEvent& operator=(UnfoldingEvent const&) = default;
97 UnfoldingEvent(UnfoldingEvent&&) = default;
99 EventSet get_history() const;
101 bool isConflict(UnfoldingEvent* event, UnfoldingEvent* otherEvent) const;
102 bool concernSameComm(const UnfoldingEvent* event, const UnfoldingEvent* otherEvent) const;
104 // check otherEvent is in my history ?
105 bool inHistory(UnfoldingEvent* otherEvent) const;
107 bool isImmediateConflict1(UnfoldingEvent* evt, UnfoldingEvent* otherEvt) const;
109 bool conflictWithConfig(UnfoldingEvent* event, Configuration const& config) const;
110 bool operator==(const UnfoldingEvent&) const { return false; };
113 inline int get_state_id() const { return state_id; }
114 inline void set_state_id(int sid) { state_id = sid; }
116 inline std::string get_transition_tag() const { return transition_tag; }
117 inline void set_transition_tag(std::string_view tr_tag) { transition_tag = tr_tag; }
120 EventSet causes; // used to store directed ancestors of event e
123 std::string transition_tag{""}; // The tag of the last transition that lead to creating the event
124 bool transition_is_IReceive(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
125 bool transition_is_ISend(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
126 bool check_tr_concern_same_comm(bool& chk1, bool& chk2, UnfoldingEvent* evt1, UnfoldingEvent* evt2) const;
131 using Handle = uint64_t;
132 std::map<Handle, std::unique_ptr<State>> state_map_;
135 Handle record_state(const std::unique_ptr<State>&&);
138 } // namespace simgrid::mc::udpor