Discrete Event Model¶
This module contains the definition of a discrete-event simulation Model. It has an abstract definition DiscreteEventModel that should be extended, implementing its abstract methods.
Example
Creating a model:
class Station(DiscreteEventModel):
_processing_time: Expression
def __init__(
self, dynamic_system: DiscreteEventDynamicSystem, processing_time: Expression
):
super().__init__(dynamic_system, state={"parts": 0, "remaining_time": -1})
self._processing_time = processing_time
def _internal_state_transition_function(self, state: StationState) -> StationState:
state["parts"] = max(state["parts"] - 1, 0)
self.schedule(self.get_time())
return state
def _external_state_transition_function(
self, state: StationState, inputs: Dict[str, int], event_time: Time
) -> StationState:
values = inputs.values()
state["remaining_time"] = state["remaining_time"] - event_time
for number_of_parts in values:
if state["parts"] > 0:
state["parts"] = state["parts"] + number_of_parts
elif state["parts"] == 0:
state["parts"] = number_of_parts
self.schedule(self.get_time())
return state
def _time_advance_function(self, state: StationState) -> Time:
if state["parts"] < 1:
state["remaining_time"] = Time(-1)
else:
state["remaining_time"] = Time(self._processing_time.evaluate())
return state["remaining_time"]
def _output_function(self, state: StationState) -> int:
if state["parts"] > 0:
return 1
return 0
def __str__(self):
return self.get_id()
-
class
gsf.models.models.discrete_event_model.
DiscreteEventModel
(dynamic_system: DiscreteEventDynamicSystem, name: str = None, state: ModelState = None, entity_manager: EntityManager = None)¶ Bases:
gsf.models.core.base_model.BaseModel
A discrete-event model executes can receive inputs at any time. Each event occurs at a particular instant in time and marks a change of state in the system.
-
_confluent_state_transition_function
(state: Any, inputs: Dict[str, Any]) → Any¶ Implements the confluent state transition function delta. The confluent state transition executes an external transition function at the time of an autonomous event.
- Parameters
state (ModelState) – Current state of the model.
inputs (ModelInput) – Input trajectory x.
-
abstract
_external_state_transition_function
(state: Any, inputs: Dict[str, Any], event_time: decimal.Decimal) → Any¶ Implements the external state transition function delta. The external state transition function computes the next state of the model from its current total state (s,e) Q at time of an input and the input itself.
- Parameters
state (ModelState) – Current state of the model.
inputs (ModelInput) – Input trajectory x.
event_time (float) – Time of event e.
-
abstract
_internal_state_transition_function
(state: Any) → Any¶ Implements the internal state transition function delta. The internal state transition function takes the system from its state at the time of the autonomous event to a subsequent state.
- Parameters
state (ModelState) – Current state of the model.
-
abstract
_output_function
(state: Any) → Any¶ Implements the output function lambda. The output function describes how the state of the system appears to an observer when e=ta(s).
- Parameters
state (ModelState) – current state s of the model.
-
abstract
_time_advance_function
(state: Any) → decimal.Decimal¶ Implement the model’s time advance function ta. The time advance function schedules output from the model and autonomous changes in its state.
- Parameters
state (ModelState) – Current state of the system.
-
add
()¶ Adds a model as an input for the current model in the dynamic system and returns the model added.
- Parameters
model (BaseModel) – Output model to be added.
weight (ExpressionProperty) – Weight of the path.
name (str) – Name of the path.
-
get_output
() → Any¶ Gets the output of the model.
-
get_time
()¶ Gets the time of the next autonomous event.
-
schedule
()¶ Schedules an autonomous event
- Parameters
time (float) – Time when the event will be executed.
-
state_transition
()¶ Executes the state transition using the state given by the state transition function. If there are no inputs is an internal transition, otherwise it is an external transition.
- Parameters
inputs (ModelInput) – Input trajectory x. If it is None, the state transition is autonomous
event_time (Time) – Time of the event. If there are inputs and the time is ta(s), it is an confluent transition.
-
unschedule
()¶ Unscheduled an autonomous event
-