1 /* Copyright (c) 2004-2021. 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>
11 #include <unordered_map>
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
21 class XBT_PUBLIC Model {
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. */
31 explicit Model(const std::string& name);
32 Model(const Model&) = delete;
33 Model& operator=(const Model&) = delete;
37 bool is_update_lazy() const { return update_algorithm_ == UpdateAlgo::LAZY; }
38 Model* set_update_algorithm(UpdateAlgo algo);
40 /** @brief Get the set of [actions](@ref Action) in *inited* state */
41 Action::StateSet* get_inited_action_set() { return &inited_action_set_; }
43 /** @brief Get the set of [actions](@ref Action) in *started* state */
44 Action::StateSet* get_started_action_set() { return &started_action_set_; }
46 /** @brief Get the set of [actions](@ref Action) in *failed* state */
47 Action::StateSet* get_failed_action_set() { return &failed_action_set_; }
49 /** @brief Get the set of [actions](@ref Action) in *finished* state */
50 Action::StateSet* get_finished_action_set() { return &finished_action_set_; }
52 /** @brief Get the set of [actions](@ref Action) in *ignored* state */
53 Action::StateSet* get_ignored_action_set() { return &ignored_action_set_; }
55 /** @brief Get the set of modified [actions](@ref Action) */
56 Action::ModifiedSet* get_modified_set() const;
58 /** @brief Get the maxmin system of the current Model */
59 lmm::System* get_maxmin_system() const { return maxmin_system_.get(); }
61 /** @brief Set the maxmin system of the current Model */
62 void set_maxmin_system(lmm::System* system);
64 /** @brief Get Action heap */
65 ActionHeap& get_action_heap() { return action_heap_; }
68 * @brief Share the resources between the actions
70 * @param now The current time of the simulation
71 * @return The delta of time till the next action will finish
73 virtual double next_occurring_event(double now);
74 virtual double next_occurring_event_lazy(double now);
75 virtual double next_occurring_event_full(double now);
78 Action* extract_action(Action::StateSet* list);
81 Action* extract_done_action();
82 Action* extract_failed_action();
85 * @brief Update action to the current time
87 * @param now The current time of the simulation
88 * @param delta The delta of time since the last update
90 virtual void update_actions_state(double now, double delta);
91 virtual void update_actions_state_lazy(double now, double delta);
92 virtual void update_actions_state_full(double now, double delta);
94 /** @brief Returns whether this model have an idempotent share_resource()
96 * The only model that is not is ns-3: computing the next timestamp moves the model up to that point,
97 * so we need to call it only when the next timestamp of other sources is computed.
99 virtual bool next_occurring_event_is_idempotent() { return true; }
101 /** @brief Gets the model name */
102 std::string get_name() const { return name_; }
105 UpdateAlgo update_algorithm_ = UpdateAlgo::FULL;
106 std::unique_ptr<lmm::System> maxmin_system_;
107 Action::StateSet inited_action_set_; /**< Created not started */
108 Action::StateSet started_action_set_; /**< Started not done */
109 Action::StateSet failed_action_set_; /**< Done with failure */
110 Action::StateSet finished_action_set_; /**< Done successful */
111 Action::StateSet ignored_action_set_; /**< not considered (failure detectors?) */
112 const std::string name_; /**< Model name */
114 ActionHeap action_heap_;
117 } // namespace resource
118 } // namespace kernel
119 } // namespace simgrid