Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix few typos and add random seed intializer
[simgrid.git] / include / simgrid / kernel / resource / Model.hpp
1 /* Copyright (c) 2004-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_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 class XBT_PUBLIC Model {
18 public:
19   /** @brief Possible update mechanisms */
20   enum class UpdateAlgo {
21     FULL, /**< Full update mechanism: the remaining time of every action is recomputed at each step */
22     LAZY  /**< Lazy update mechanism: only the modified actions get recomputed.
23                    It may be slower than full if your system is tightly coupled to the point where every action
24                    gets recomputed anyway. In that case, you'd better not try to be cleaver with lazy and go for
25                    a simple full update.  */
26   };
27   explicit Model(const std::string& name);
28   Model(const Model&) = delete;
29   Model& operator=(const Model&) = delete;
30
31   virtual ~Model();
32
33   bool is_update_lazy() const { return update_algorithm_ == UpdateAlgo::LAZY; }
34   Model* set_update_algorithm(UpdateAlgo algo);
35
36   /** @brief Get the set of [actions](@ref Action) in *inited* state */
37   Action::StateSet* get_inited_action_set() { return &inited_action_set_; }
38
39   /** @brief Get the set of [actions](@ref Action) in *started* state */
40   Action::StateSet* get_started_action_set() { return &started_action_set_; }
41
42   /** @brief Get the set of [actions](@ref Action) in *failed* state */
43   Action::StateSet* get_failed_action_set() { return &failed_action_set_; }
44
45   /** @brief Get the set of [actions](@ref Action) in *finished* state */
46   Action::StateSet* get_finished_action_set() { return &finished_action_set_; }
47
48   /** @brief Get the set of [actions](@ref Action) in *ignored* state */
49   Action::StateSet* get_ignored_action_set() { return &ignored_action_set_; }
50
51   /** @brief Get the set of modified [actions](@ref Action) */
52   Action::ModifiedSet* get_modified_set() const;
53
54   /** @brief Get the maxmin system of the current Model */
55   lmm::System* get_maxmin_system() const { return maxmin_system_.get(); }
56
57   /** @brief Set the maxmin system of the current Model */
58   void set_maxmin_system(lmm::System* system);
59
60   /** @brief Get Action heap */
61   ActionHeap& get_action_heap() { return action_heap_; }
62
63   /**
64    * @brief Share the resources between the actions
65    *
66    * @param now The current time of the simulation
67    * @return The delta of time till the next action will finish
68    */
69   virtual double next_occurring_event(double now);
70   virtual double next_occurring_event_lazy(double now);
71   virtual double next_occurring_event_full(double now);
72
73 private:
74   Action* extract_action(Action::StateSet* list);
75
76 public:
77   Action* extract_done_action();
78   Action* extract_failed_action();
79
80   /**
81    * @brief Update action to the current time
82    *
83    * @param now The current time of the simulation
84    * @param delta The delta of time since the last update
85    */
86   virtual void update_actions_state(double now, double delta);
87   virtual void update_actions_state_lazy(double now, double delta);
88   virtual void update_actions_state_full(double now, double delta);
89
90   /** @brief Returns whether this model have an idempotent share_resource()
91    *
92    * The only model that is not is ns-3: computing the next timestamp moves the model up to that point,
93    * so we need to call it only when the next timestamp of other sources is computed.
94    */
95   virtual bool next_occurring_event_is_idempotent() { return true; }
96
97   /** @brief Gets the model name */
98   std::string get_name() const { return name_; }
99
100 private:
101   UpdateAlgo update_algorithm_ = UpdateAlgo::FULL;
102   std::unique_ptr<lmm::System> maxmin_system_;
103   Action::StateSet inited_action_set_;   /**< Created not started */
104   Action::StateSet started_action_set_;  /**< Started not done */
105   Action::StateSet failed_action_set_;   /**< Done with failure */
106   Action::StateSet finished_action_set_; /**< Done successful */
107   Action::StateSet ignored_action_set_;  /**< not considered (failure detectors?) */
108   const std::string name_;               /**< Model name */
109
110   ActionHeap action_heap_;
111 };
112
113 } // namespace resource
114 } // namespace kernel
115 } // namespace simgrid
116
117 #endif