Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a1d65b7ca9391adb89713dd705bf8262d9c0dbe8
[simgrid.git] / src / mc / udpor_global.hpp
1 /* Copyright (c) 2007-2021. 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
12 namespace simgrid {
13 namespace mc {
14
15 class UnfoldingEvent;
16 using EventSet = std::deque<UnfoldingEvent*>;
17
18 class EvtSetTools {
19 public:
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(EventSet const& events, EventSet const& otherSet);
24   static bool isEmptyIntersection(EventSet evtS1, EventSet evtS2);
25   static EventSet makeUnion(EventSet s1, 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);
30 };
31
32 typedef struct s_evset_in {
33   EventSet causuality_events;
34   EventSet cause;
35   EventSet ancestorSet;
36 } s_evset_in_t;
37
38 class Configuration {
39 public:
40   EventSet 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
44
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
50
51   UnfoldingEvent* findTestedComm(const UnfoldingEvent* testEvt); // find comm tested by action testTrans
52
53   Configuration()                     = default;
54   Configuration(const Configuration&) = default;
55   Configuration& operator=(Configuration const&) = default;
56   Configuration(Configuration&&)                 = default;
57   ~Configuration()                               = default;
58 };
59
60 class UnfoldingEvent {
61 public:
62   int id = -1;
63   EventSet causes; // used to store directed ancestors of event e
64   UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& causes, int sid = -1);
65   UnfoldingEvent(const UnfoldingEvent&) = default;
66   UnfoldingEvent& operator=(UnfoldingEvent const&) = default;
67   UnfoldingEvent(UnfoldingEvent&&)                 = default;
68   ~UnfoldingEvent()                                = default;
69
70   EventSet getHistory() const;
71
72   bool isConflict(UnfoldingEvent* event, UnfoldingEvent* otherEvent) const;
73   bool concernSameComm(const UnfoldingEvent* event, const UnfoldingEvent* otherEvent) const;
74
75   // check otherEvent is in my history ?
76   bool inHistory(UnfoldingEvent* otherEvent) const;
77
78   bool isImmediateConflict1(UnfoldingEvent* evt, UnfoldingEvent* otherEvt) const;
79
80   bool conflictWithConfig(UnfoldingEvent* event, Configuration const& config) const;
81   /* TODO: implement */ 
82   bool operator==(const UnfoldingEvent& other) const { return false; };
83   void print() const;
84
85   inline int get_state_id() const { return state_id; }
86   inline void set_state_id(int sid) { state_id = sid; }
87
88   inline std::string get_transition_tag() const { return transition_tag; }
89   inline void set_transition_tag(std::string const& tr_tag) { transition_tag = tr_tag; }
90
91 private:
92   int state_id{-1};
93   std::string transition_tag{""}; // The tag of the last transition that lead to creating the event
94   bool transition_is_IReceive(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
95   bool transition_is_ISend(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
96   bool check_tr_concern_same_comm(bool& chk1, bool& chk2, UnfoldingEvent* evt1, UnfoldingEvent* evt2) const;
97 };
98 } // namespace mc
99 } // namespace simgrid
100 #endif