1 /* Copyright (c) 2007-2022. 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
11 #include <string_view>
13 namespace simgrid::mc {
16 using EventSet = std::deque<UnfoldingEvent*>;
20 static bool contains(const EventSet& events, const UnfoldingEvent* e);
21 static UnfoldingEvent* find(const EventSet& events, const UnfoldingEvent* e);
22 static void subtract(EventSet& events, EventSet const& otherSet);
23 static bool depends(const EventSet& events, const EventSet& otherSet);
24 static bool isEmptyIntersection(EventSet evtS1, EventSet evtS2);
25 static EventSet makeUnion(const EventSet& s1, const EventSet& s2);
26 static void pushBack(EventSet& events, UnfoldingEvent* e);
27 static void remove(EventSet& events, UnfoldingEvent* e);
28 static EventSet minus(EventSet events, UnfoldingEvent* e);
29 static EventSet plus(EventSet events, UnfoldingEvent* e);
33 EventSet causuality_events;
41 EventSet maxEvent; // Events recently added to events_
42 EventSet actorMaxEvent; // maximal events of the actors in current configuration
43 UnfoldingEvent* lastEvent; // The last added event
45 Configuration plus_config(UnfoldingEvent*) const;
46 void createEvts(Configuration C, EventSet& result, const std::string& trans_tag, s_evset_in_t ev_sets, bool chk,
47 UnfoldingEvent* immPreEvt);
48 void updateMaxEvent(UnfoldingEvent*); // update maximal events of the configuration and actors
49 UnfoldingEvent* findActorMaxEvt(int actorId); // find maximal event of a Actor whose id = actorId
51 UnfoldingEvent* findTestedComm(const UnfoldingEvent* testEvt); // find comm tested by action testTrans
53 Configuration() = default;
54 Configuration(const Configuration&) = default;
55 Configuration& operator=(Configuration const&) = default;
56 Configuration(Configuration&&) = default;
59 class UnfoldingEvent {
61 UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& causes, int sid = -1);
62 UnfoldingEvent(const UnfoldingEvent&) = default;
63 UnfoldingEvent& operator=(UnfoldingEvent const&) = default;
64 UnfoldingEvent(UnfoldingEvent&&) = default;
66 EventSet getHistory() const;
68 bool isConflict(UnfoldingEvent* event, UnfoldingEvent* otherEvent) const;
69 bool concernSameComm(const UnfoldingEvent* event, const UnfoldingEvent* otherEvent) const;
71 // check otherEvent is in my history ?
72 bool inHistory(UnfoldingEvent* otherEvent) const;
74 bool isImmediateConflict1(UnfoldingEvent* evt, UnfoldingEvent* otherEvt) const;
76 bool conflictWithConfig(UnfoldingEvent* event, Configuration const& config) const;
78 bool operator==(const UnfoldingEvent&) const { return false; };
81 inline int get_state_id() const { return state_id; }
82 inline void set_state_id(int sid) { state_id = sid; }
84 inline std::string get_transition_tag() const { return transition_tag; }
85 inline void set_transition_tag(std::string_view tr_tag) { transition_tag = tr_tag; }
88 EventSet causes; // used to store directed ancestors of event e
91 std::string transition_tag{""}; // The tag of the last transition that lead to creating the event
92 bool transition_is_IReceive(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
93 bool transition_is_ISend(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
94 bool check_tr_concern_same_comm(bool& chk1, bool& chk2, UnfoldingEvent* evt1, UnfoldingEvent* evt2) const;
96 } // namespace simgrid::mc