Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert EventSet into class from typedef
[simgrid.git] / src / mc / udpor_global.hpp
1 /* Copyright (c) 2007-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 #ifndef SIMGRID_MC_UDPOR_GLOBAL_HPP
7 #define SIMGRID_MC_UDPOR_GLOBAL_HPP
8
9 #include <iostream>
10 #include <queue>
11 #include <set>
12 #include <string_view>
13
14 /* TODO: many method declared in this module are not implemented */
15
16 namespace simgrid::mc {
17
18 class UnfoldingEvent;
19 class Configuration;
20
21 class EventSet {
22 private:
23   std::set<UnfoldingEvent*> events_;
24
25 public:
26   EventSet()                           = default;
27   EventSet(const EventSet&)            = default;
28   EventSet& operator=(EventSet const&) = default;
29   EventSet(EventSet&&)                 = default;
30
31   void remove(UnfoldingEvent* e);
32   void subtract(const EventSet& other);
33   EventSet subtracting(const EventSet& e);
34   EventSet subtracting(const UnfoldingEvent* e);
35
36   void insert(UnfoldingEvent* e);
37   void form_union(const EventSet&);
38   EventSet make_union(const EventSet&) const;
39   EventSet make_union(const UnfoldingEvent* e) const;
40
41   bool contains(const UnfoldingEvent* e) const;
42
43   // TODO: What is this used for?
44   UnfoldingEvent* find(const UnfoldingEvent* e) const;
45
46   // TODO: What is this used for
47   bool depends(const EventSet& other) const;
48
49   // TODO: What is this used for
50   bool is_empty_intersection(EventSet evtS) const;
51 };
52
53 struct s_evset_in_t {
54   EventSet causuality_events;
55   EventSet cause;
56   EventSet ancestorSet;
57 };
58
59 class Configuration {
60 public:
61   Configuration()                                = default;
62   Configuration(const Configuration&)            = default;
63   Configuration& operator=(Configuration const&) = default;
64   Configuration(Configuration&&)                 = default;
65
66   EventSet events_;
67   EventSet maxEvent;         // Events recently added to events_
68   EventSet actorMaxEvent;    // maximal events of the actors in current configuration
69   UnfoldingEvent* lastEvent; // The last added event
70
71   Configuration plus_config(UnfoldingEvent*) const;
72
73   void createEvts(Configuration C, EventSet& result, const std::string& trans_tag, s_evset_in_t ev_sets, bool chk,
74                   UnfoldingEvent* immPreEvt);
75
76   void updateMaxEvent(UnfoldingEvent*);         // update maximal events of the configuration and actors
77   UnfoldingEvent* findActorMaxEvt(int actorId); // find maximal event of a Actor whose id = actorId
78
79   UnfoldingEvent* findTestedComm(const UnfoldingEvent* testEvt); // find comm tested by action testTrans
80 };
81
82 class UnfoldingEvent {
83 public:
84   UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& causes, int sid = -1);
85   UnfoldingEvent(const UnfoldingEvent&)            = default;
86   UnfoldingEvent& operator=(UnfoldingEvent const&) = default;
87   UnfoldingEvent(UnfoldingEvent&&)                 = default;
88
89   EventSet getHistory() const;
90
91   bool isConflict(UnfoldingEvent* event, UnfoldingEvent* otherEvent) const;
92   bool concernSameComm(const UnfoldingEvent* event, const UnfoldingEvent* otherEvent) const;
93
94   // check otherEvent is in my history ?
95   bool inHistory(UnfoldingEvent* otherEvent) const;
96
97   bool isImmediateConflict1(UnfoldingEvent* evt, UnfoldingEvent* otherEvt) const;
98
99   bool conflictWithConfig(UnfoldingEvent* event, Configuration const& config) const;
100   bool operator==(const UnfoldingEvent&) const { return false; };
101   void print() const;
102
103   inline int get_state_id() const { return state_id; }
104   inline void set_state_id(int sid) { state_id = sid; }
105
106   inline std::string get_transition_tag() const { return transition_tag; }
107   inline void set_transition_tag(std::string_view tr_tag) { transition_tag = tr_tag; }
108
109 private:
110   EventSet causes; // used to store directed ancestors of event e
111   int id = -1;
112   int state_id{-1};
113   std::string transition_tag{""}; // The tag of the last transition that lead to creating the event
114   bool transition_is_IReceive(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
115   bool transition_is_ISend(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
116   bool check_tr_concern_same_comm(bool& chk1, bool& chk2, UnfoldingEvent* evt1, UnfoldingEvent* evt2) const;
117 };
118 } // namespace simgrid::mc
119 #endif