Logo AND Algorithmique Numérique Distribuée

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