Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a7892ad72e79be29bdd8990ea10e0da9b06455a7
[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 "src/mc/api/State.hpp"
10
11 #include <iostream>
12 #include <queue>
13 #include <set>
14 #include <string_view>
15
16 /* TODO: many method declared in this module are not implemented */
17
18 namespace simgrid::mc::udpor {
19
20 class UnfoldingEvent;
21 class Configuration;
22
23 class EventSet {
24 private:
25   std::set<UnfoldingEvent*> events_;
26
27 public:
28   EventSet()                           = default;
29   EventSet(const EventSet&)            = default;
30   EventSet& operator=(const EventSet&) = default;
31   EventSet(EventSet&&)                 = default;
32   EventSet(const Configuration&);
33
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;
40
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;
47
48   size_t size() const;
49   bool empty() const;
50   bool contains(const UnfoldingEvent* e) const;
51   bool is_subset_of(const EventSet& other) const;
52
53   // TODO: What is this used for?
54   UnfoldingEvent* find(const UnfoldingEvent* e) const;
55
56   // TODO: What is this used for
57   bool depends(const EventSet& other) const;
58
59   // TODO: What is this used for
60   bool is_empty_intersection(EventSet evtS) const;
61 };
62
63 struct s_evset_in_t {
64   EventSet causuality_events;
65   EventSet cause;
66   EventSet ancestorSet;
67 };
68
69 class Configuration {
70 public:
71   Configuration()                                = default;
72   Configuration(const Configuration&)            = default;
73   Configuration& operator=(Configuration const&) = default;
74   Configuration(Configuration&&)                 = default;
75
76   EventSet events_;
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
80
81   Configuration plus_config(UnfoldingEvent*) const;
82
83   void createEvts(Configuration C, EventSet& result, const std::string& trans_tag, s_evset_in_t ev_sets, bool chk,
84                   UnfoldingEvent* immPreEvt);
85
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
88
89   UnfoldingEvent* findTestedComm(const UnfoldingEvent* testEvt); // find comm tested by action testTrans
90 };
91
92 class UnfoldingEvent {
93 public:
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;
98
99   EventSet get_history() const;
100
101   bool isConflict(UnfoldingEvent* event, UnfoldingEvent* otherEvent) const;
102   bool concernSameComm(const UnfoldingEvent* event, const UnfoldingEvent* otherEvent) const;
103
104   // check otherEvent is in my history ?
105   bool inHistory(UnfoldingEvent* otherEvent) const;
106
107   bool isImmediateConflict1(UnfoldingEvent* evt, UnfoldingEvent* otherEvt) const;
108
109   bool conflictWithConfig(UnfoldingEvent* event, Configuration const& config) const;
110   bool operator==(const UnfoldingEvent&) const { return false; };
111   void print() const;
112
113   inline int get_state_id() const { return state_id; }
114   inline void set_state_id(int sid) { state_id = sid; }
115
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; }
118
119 private:
120   EventSet causes; // used to store directed ancestors of event e
121   int id = -1;
122   int state_id{-1};
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;
127 };
128
129 class StateManager {
130 private:
131   using Handle = uint64_t;
132   std::map<Handle, std::unique_ptr<State>> state_map_;
133
134 public:
135   Handle record_state(const std::unique_ptr<State>&&);
136 };
137
138 } // namespace simgrid::mc::udpor
139 #endif