Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make field private.
[simgrid.git] / src / 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 "src/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 XBT_PUBLIC_CLASS Model
20 {
21 public:
22   Model();
23   virtual ~Model();
24
25   /** @brief Get the set of [actions](@ref Action) in *ready* state */
26   virtual ActionList* getReadyActionSet() const { return readyActionSet_; }
27
28   /** @brief Get the set of [actions](@ref Action) in *running* state */
29   virtual ActionList* getRunningActionSet() const { return runningActionSet_; }
30
31   /** @brief Get the set of [actions](@ref Action) in *failed* state */
32   virtual ActionList* getFailedActionSet() const { return failedActionSet_; }
33
34   /** @brief Get the set of [actions](@ref Action) in *done* state */
35   virtual ActionList* getDoneActionSet() const { return doneActionSet_; }
36
37   /** @brief Get the set of modified [actions](@ref Action) */
38   virtual ActionLmmListPtr getModifiedSet() const { return modifiedSet_; }
39
40   /** @brief Get the maxmin system of the current Model */
41   lmm_system_t getMaxminSystem() const { return maxminSystem_; }
42
43   /**
44    * @brief Get the update mechanism of the current Model
45    * @see e_UM_t
46    */
47   e_UM_t getUpdateMechanism() const { return updateMechanism_; }
48   void setUpdateMechanism(e_UM_t mechanism) { updateMechanism_ = mechanism; }
49
50   /** @brief Get Action heap */
51   heap_type& getActionHeap() { return actionHeap_; }
52
53   double actionHeapTopDate() const { return actionHeap_.top().first; }
54   Action* actionHeapPop();
55   bool actionHeapIsEmpty() const { return actionHeap_.empty(); }
56
57   /**
58    * @brief Share the resources between the actions
59    *
60    * @param now The current time of the simulation
61    * @return The delta of time till the next action will finish
62    */
63   virtual double nextOccuringEvent(double now);
64   virtual double nextOccuringEventLazy(double now);
65   virtual double nextOccuringEventFull(double now);
66
67   /**
68    * @brief Update action to the current time
69    *
70    * @param now The current time of the simulation
71    * @param delta The delta of time since the last update
72    */
73   virtual void updateActionsState(double now, double delta);
74   virtual void updateActionsStateLazy(double now, double delta);
75   virtual void updateActionsStateFull(double now, double delta);
76
77   /** @brief Returns whether this model have an idempotent shareResource()
78    *
79    * The only model that is not is NS3: computing the next timestamp moves the model up to that point,
80    * so we need to call it only when the next timestamp of other sources is computed.
81    */
82   virtual bool nextOccuringEventIsIdempotent() { return true; }
83
84 protected:
85   ActionLmmListPtr modifiedSet_;
86   lmm_system_t maxminSystem_ = nullptr;
87   bool selectiveUpdate_;
88
89 private:
90   e_UM_t updateMechanism_ = UM_UNDEFINED;
91   ActionList* readyActionSet_;   /**< Actions in state SURF_ACTION_READY */
92   ActionList* runningActionSet_; /**< Actions in state SURF_ACTION_RUNNING */
93   ActionList* failedActionSet_;  /**< Actions in state SURF_ACTION_FAILED */
94   ActionList* doneActionSet_;    /**< Actions in state SURF_ACTION_DONE */
95   heap_type actionHeap_;
96 };
97
98 } // namespace surf
99 } // namespace simgrid
100 } // namespace simgrid
101 #endif