Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
No more types for models.
[simgrid.git] / include / simgrid / kernel / resource / Model.hpp
1 /* Copyright (c) 2004-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_KERNEL_RESOURCE_MODEL_HPP
7 #define SIMGRID_KERNEL_RESOURCE_MODEL_HPP
8
9 #include <memory>
10 #include <simgrid/kernel/resource/Action.hpp>
11 #include <unordered_map>
12
13 namespace simgrid {
14 namespace kernel {
15 namespace resource {
16
17 /** @ingroup SURF_interface
18  * @brief SURF model interface class
19  * @details A model is an object which handle the interactions between its Resources and its Actions
20  */
21 class XBT_PUBLIC Model {
22 public:
23   /** @brief Possible update mechanisms */
24   enum class UpdateAlgo {
25     FULL, /**< Full update mechanism: the remaining time of every action is recomputed at each step */
26     LAZY  /**< Lazy update mechanism: only the modified actions get recomputed.
27                    It may be slower than full if your system is tightly coupled to the point where every action
28                    gets recomputed anyway. In that case, you'd better not try to be cleaver with lazy and go for
29                    a simple full update.  */
30   };
31   Model()             = default;
32   Model(const Model&) = delete;
33   Model& operator=(const Model&) = delete;
34
35   virtual ~Model();
36
37   bool is_update_lazy() const { return update_algorithm_ == UpdateAlgo::LAZY; }
38   Model* set_update_algorithm(UpdateAlgo algo);
39
40   /** @brief Get the set of [actions](@ref Action) in *inited* state */
41   Action::StateSet* get_inited_action_set() { return &inited_action_set_; }
42
43   /** @brief Get the set of [actions](@ref Action) in *started* state */
44   Action::StateSet* get_started_action_set() { return &started_action_set_; }
45
46   /** @brief Get the set of [actions](@ref Action) in *failed* state */
47   Action::StateSet* get_failed_action_set() { return &failed_action_set_; }
48
49   /** @brief Get the set of [actions](@ref Action) in *finished* state */
50   Action::StateSet* get_finished_action_set() { return &finished_action_set_; }
51
52   /** @brief Get the set of [actions](@ref Action) in *ignored* state */
53   Action::StateSet* get_ignored_action_set() { return &ignored_action_set_; }
54
55   /** @brief Get the set of modified [actions](@ref Action) */
56   Action::ModifiedSet* get_modified_set() const;
57
58   /** @brief Get the maxmin system of the current Model */
59   lmm::System* get_maxmin_system() const { return maxmin_system_.get(); }
60
61   /** @brief Set the maxmin system of the current Model */
62   void set_maxmin_system(lmm::System* system);
63
64   /** @brief Get the update algorithm of the current Model */
65   XBT_ATTRIB_DEPRECATED_v329("Please use is_update_lazy()") UpdateAlgo get_update_algorithm() const
66   {
67     return update_algorithm_;
68   }
69
70   /** @brief Get Action heap */
71   ActionHeap& get_action_heap() { return action_heap_; }
72
73   /**
74    * @brief Share the resources between the actions
75    *
76    * @param now The current time of the simulation
77    * @return The delta of time till the next action will finish
78    */
79   virtual double next_occurring_event(double now);
80   virtual double next_occurring_event_lazy(double now);
81   virtual double next_occurring_event_full(double now);
82
83   XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event()") virtual double next_occuring_event(double now) final
84   {
85     return next_occurring_event(now);
86   }
87   XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event_lazy()") virtual double next_occuring_event_lazy(
88       double now) final
89   {
90     return next_occurring_event_lazy(now);
91   }
92   XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event_full()") virtual double next_occuring_event_full(
93       double now) final
94   {
95     return next_occurring_event_full(now);
96   }
97
98 private:
99   Action* extract_action(Action::StateSet* list);
100
101 public:
102   Action* extract_done_action();
103   Action* extract_failed_action();
104
105   /**
106    * @brief Update action to the current time
107    *
108    * @param now The current time of the simulation
109    * @param delta The delta of time since the last update
110    */
111   virtual void update_actions_state(double now, double delta);
112   virtual void update_actions_state_lazy(double now, double delta);
113   virtual void update_actions_state_full(double now, double delta);
114
115   /** @brief Returns whether this model have an idempotent share_resource()
116    *
117    * The only model that is not is ns-3: computing the next timestamp moves the model up to that point,
118    * so we need to call it only when the next timestamp of other sources is computed.
119    */
120   virtual bool next_occurring_event_is_idempotent() { return true; }
121
122   XBT_ATTRIB_DEPRECATED_v329(
123       "Please use next_occurring_event_is_idempotent()") virtual bool next_occuring_event_is_idempotent() final
124   {
125     return next_occurring_event_is_idempotent();
126   }
127
128   /** @brief Gets the model name */
129   std::string get_name() const { return name_; }
130   /** @brief Sets the model name */
131   Model* set_name(const std::string& name);
132
133 private:
134   UpdateAlgo update_algorithm_ = UpdateAlgo::FULL;
135   std::unique_ptr<lmm::System> maxmin_system_;
136   Action::StateSet inited_action_set_;   /**< Created not started */
137   Action::StateSet started_action_set_;  /**< Started not done */
138   Action::StateSet failed_action_set_;   /**< Done with failure */
139   Action::StateSet finished_action_set_; /**< Done successful */
140   Action::StateSet ignored_action_set_;  /**< not considered (failure detectors?) */
141   std::string name_ = "Unnamed";         /**< Model name */
142
143   ActionHeap action_heap_;
144 };
145
146 } // namespace resource
147 } // namespace kernel
148 } // namespace simgrid
149
150 #endif