Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9a614ca37f528aa20c09f5d204c6c8a7fdba422c
[simgrid.git] / include / simgrid / kernel / resource / Model.hpp
1 /* Copyright (c) 2004-2018. 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 <simgrid/kernel/resource/Action.hpp>
10
11 namespace simgrid {
12 namespace kernel {
13 namespace resource {
14
15 /** @ingroup SURF_interface
16  * @brief SURF model interface class
17  * @details A model is an object which handle the interactions between its Resources and its Actions
18  */
19 class XBT_PUBLIC Model {
20 public:
21   /** @brief Possible update mechanisms */
22   enum class UpdateAlgo {
23     Full, /**< Full update mechanism: the remaining time of every action is recomputed at each step */
24     Lazy  /**< Lazy update mechanism: only the modified actions get recomputed.
25                    It may be slower than full if your system is tightly coupled to the point where every action
26                    gets recomputed anyway. In that case, you'd better not try to be cleaver with lazy and go for
27                    a simple full update.  */
28   };
29
30   explicit Model(Model::UpdateAlgo algo);
31
32   virtual ~Model();
33
34   /** @brief Get the set of [actions](@ref Action) in *inited* state */
35   Action::StateSet* get_inited_action_set() const { return inited_action_set_; }
36
37   /** @brief Get the set of [actions](@ref Action) in *started* state */
38   Action::StateSet* get_started_action_set() const { return started_action_set_; }
39
40   /** @brief Get the set of [actions](@ref Action) in *failed* state */
41   Action::StateSet* get_failed_action_set() const { return failed_action_set_; }
42
43   /** @brief Get the set of [actions](@ref Action) in *finished* state */
44   Action::StateSet* get_finished_action_set() const { return finished_action_set_; }
45
46   /** @brief Get the set of modified [actions](@ref Action) */
47   Action::ModifiedSet* get_modified_set() const;
48
49   /** @brief Get the maxmin system of the current Model */
50   lmm::System* get_maxmin_system() const { return maxmin_system_; }
51
52   /** @brief Set the maxmin system of the current Model */
53   void set_maxmin_system(lmm::System* system) { maxmin_system_ = system; }
54
55   /** @brief Get the update algorithm of the current Model */
56   UpdateAlgo get_update_algorithm() const { return update_algorithm_; }
57
58   /** @brief Get Action heap */
59   ActionHeap& get_action_heap() { return action_heap_; }
60
61   /**
62    * @brief Share the resources between the actions
63    *
64    * @param now The current time of the simulation
65    * @return The delta of time till the next action will finish
66    */
67   virtual double next_occuring_event(double now);
68   virtual double next_occuring_event_lazy(double now);
69   virtual double next_occuring_event_full(double now);
70
71   /**
72    * @brief Update action to the current time
73    *
74    * @param now The current time of the simulation
75    * @param delta The delta of time since the last update
76    */
77   virtual void update_actions_state(double now, double delta);
78   virtual void update_actions_state_lazy(double now, double delta);
79   virtual void update_actions_state_full(double now, double delta);
80
81   /** @brief Returns whether this model have an idempotent share_resource()
82    *
83    * The only model that is not is NS3: computing the next timestamp moves the model up to that point,
84    * so we need to call it only when the next timestamp of other sources is computed.
85    */
86   virtual bool next_occuring_event_is_idempotent() { return true; }
87
88 private:
89   lmm::System* maxmin_system_           = nullptr;
90   const UpdateAlgo update_algorithm_;
91   Action::StateSet* inited_action_set_  = new Action::StateSet(); /**< Created not started */
92   Action::StateSet* started_action_set_  = new Action::StateSet(); /**< Started not done */
93   Action::StateSet* failed_action_set_  = new Action::StateSet(); /**< Done with failure */
94   Action::StateSet* finished_action_set_ = new Action::StateSet(); /**< Done successful */
95   ActionHeap action_heap_;
96 };
97
98 } // namespace resource
99 } // namespace kernel
100 } // namespace simgrid
101 #endif