1 /* Copyright (c) 2004-2020. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_KERNEL_RESOURCE_MODEL_HPP
7 #define SIMGRID_KERNEL_RESOURCE_MODEL_HPP
10 #include <simgrid/kernel/resource/Action.hpp>
16 /** @ingroup SURF_interface
17 * @brief SURF model interface class
18 * @details A model is an object which handle the interactions between its Resources and its Actions
20 class XBT_PUBLIC Model {
22 /** @brief Possible update mechanisms */
23 enum class UpdateAlgo {
24 FULL, /**< Full update mechanism: the remaining time of every action is recomputed at each step */
25 LAZY /**< Lazy update mechanism: only the modified actions get recomputed.
26 It may be slower than full if your system is tightly coupled to the point where every action
27 gets recomputed anyway. In that case, you'd better not try to be cleaver with lazy and go for
28 a simple full update. */
31 explicit Model(Model::UpdateAlgo algo);
32 Model(const Model&) = delete;
33 Model& operator=(const Model&) = delete;
37 bool is_update_lazy() { return update_algorithm_ == UpdateAlgo::LAZY; }
39 /** @brief Get the set of [actions](@ref Action) in *inited* state */
40 Action::StateSet* get_inited_action_set() { return &inited_action_set_; }
42 /** @brief Get the set of [actions](@ref Action) in *started* state */
43 Action::StateSet* get_started_action_set() { return &started_action_set_; }
45 /** @brief Get the set of [actions](@ref Action) in *failed* state */
46 Action::StateSet* get_failed_action_set() { return &failed_action_set_; }
48 /** @brief Get the set of [actions](@ref Action) in *finished* state */
49 Action::StateSet* get_finished_action_set() { return &finished_action_set_; }
51 /** @brief Get the set of [actions](@ref Action) in *ignored* state */
52 Action::StateSet* get_ignored_action_set() { return &ignored_action_set_; }
54 /** @brief Get the set of modified [actions](@ref Action) */
55 Action::ModifiedSet* get_modified_set() const;
57 /** @brief Get the maxmin system of the current Model */
58 lmm::System* get_maxmin_system() const { return maxmin_system_.get(); }
60 /** @brief Set the maxmin system of the current Model */
61 void set_maxmin_system(lmm::System* system);
63 /** @brief Get the update algorithm of the current Model */
64 XBT_ATTRIB_DEPRECATED_v329("Please use is_update_lazy()") UpdateAlgo get_update_algorithm() const
66 return update_algorithm_;
69 /** @brief Get Action heap */
70 ActionHeap& get_action_heap() { return action_heap_; }
73 * @brief Share the resources between the actions
75 * @param now The current time of the simulation
76 * @return The delta of time till the next action will finish
78 virtual double next_occurring_event(double now);
79 virtual double next_occurring_event_lazy(double now);
80 virtual double next_occurring_event_full(double now);
82 XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event()") virtual double next_occuring_event(double now) final
84 return next_occurring_event(now);
86 XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event_lazy()") virtual double next_occuring_event_lazy(
89 return next_occurring_event_lazy(now);
91 XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event_full()") virtual double next_occuring_event_full(
94 return next_occurring_event_full(now);
98 Action* extract_action(Action::StateSet* list);
101 Action* extract_done_action();
102 Action* extract_failed_action();
105 * @brief Update action to the current time
107 * @param now The current time of the simulation
108 * @param delta The delta of time since the last update
110 virtual void update_actions_state(double now, double delta);
111 virtual void update_actions_state_lazy(double now, double delta);
112 virtual void update_actions_state_full(double now, double delta);
114 /** @brief Returns whether this model have an idempotent share_resource()
116 * The only model that is not is ns-3: computing the next timestamp moves the model up to that point,
117 * so we need to call it only when the next timestamp of other sources is computed.
119 virtual bool next_occurring_event_is_idempotent() { return true; }
121 XBT_ATTRIB_DEPRECATED_v329(
122 "Please use next_occurring_event_is_idempotent()") virtual bool next_occuring_event_is_idempotent() final
124 return next_occurring_event_is_idempotent();
128 std::unique_ptr<lmm::System> maxmin_system_;
129 const UpdateAlgo update_algorithm_;
130 Action::StateSet inited_action_set_; /**< Created not started */
131 Action::StateSet started_action_set_; /**< Started not done */
132 Action::StateSet failed_action_set_; /**< Done with failure */
133 Action::StateSet finished_action_set_; /**< Done successful */
134 Action::StateSet ignored_action_set_; /**< not considered (failure detectors?) */
136 ActionHeap action_heap_;
139 } // namespace resource
140 } // namespace kernel
141 } // namespace simgrid
143 /** @ingroup SURF_models
144 * @brief List of initialized models
146 XBT_PUBLIC_DATA std::vector<simgrid::kernel::resource::Model*> all_existing_models;