1 /* Copyright (c) 2004-2018. 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
9 #include "src/kernel/resource/Action.hpp"
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
19 class XBT_PUBLIC Model {
24 /** @brief Get the set of [actions](@ref Action) in *ready* state */
25 virtual ActionList* getReadyActionSet() const { return readyActionSet_; }
27 /** @brief Get the set of [actions](@ref Action) in *running* state */
28 virtual ActionList* getRunningActionSet() const { return runningActionSet_; }
30 /** @brief Get the set of [actions](@ref Action) in *failed* state */
31 virtual ActionList* getFailedActionSet() const { return failedActionSet_; }
33 /** @brief Get the set of [actions](@ref Action) in *done* state */
34 virtual ActionList* getDoneActionSet() const { return doneActionSet_; }
36 /** @brief Get the set of modified [actions](@ref Action) */
37 virtual ActionLmmListPtr getModifiedSet() const { return modifiedSet_; }
39 /** @brief Get the maxmin system of the current Model */
40 lmm_system_t getMaxminSystem() const { return maxminSystem_; }
43 * @brief Get the update mechanism of the current Model
46 e_UM_t getUpdateMechanism() const { return updateMechanism_; }
47 void setUpdateMechanism(e_UM_t mechanism) { updateMechanism_ = mechanism; }
49 /** @brief Get Action heap */
50 heap_type& getActionHeap() { return actionHeap_; }
52 double actionHeapTopDate() const { return actionHeap_.top().first; }
53 Action* actionHeapPop();
54 bool actionHeapIsEmpty() const { return actionHeap_.empty(); }
57 * @brief Share the resources between the actions
59 * @param now The current time of the simulation
60 * @return The delta of time till the next action will finish
62 virtual double nextOccuringEvent(double now);
63 virtual double nextOccuringEventLazy(double now);
64 virtual double nextOccuringEventFull(double now);
67 * @brief Update action to the current time
69 * @param now The current time of the simulation
70 * @param delta The delta of time since the last update
72 virtual void updateActionsState(double now, double delta);
73 virtual void updateActionsStateLazy(double now, double delta);
74 virtual void updateActionsStateFull(double now, double delta);
76 /** @brief Returns whether this model have an idempotent shareResource()
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.
81 virtual bool nextOccuringEventIsIdempotent() { return true; }
84 ActionLmmListPtr modifiedSet_;
85 lmm_system_t maxminSystem_ = nullptr;
86 bool selectiveUpdate_;
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_;
98 } // namespace simgrid
99 } // namespace simgrid