Discrete Event Dynamic System¶
This module contains the definition of a discrete-event dynamic system. It has the definition of the DiscreteEventDynamicSystem that allows simulations over networks of models.
Example
Creating a discrete-event dynamic system:
class LinearAutomaton(DiscreteEventDynamicSystem):
_cells: List[Cell]
def __init__(self, cells: int = 5, random_seed: int = 42):
super().__init__()
seed(random_seed)
self._create_cells(cells)
self._create_relations(cells)
def _create_cells(self, cells: int):
self._cells = []
for i in range(cells):
is_alive = random() < 0.5
# When a model is created, is added to the _models' collection od the dynamic system.
self._cells.append(Cell(self, is_alive))
def _create_relations(self, cells: int):
for i in range(cells):
self._cells[i - 1].add(self._cells[i])
def __str__(self):
s = ""
for cell in self._cells:
s += str(cell)
return s
Add a model to the dynamic system:
Model(dynamic_system)
Add a link between models:
path = Path(from_model, to_model, Value(1), 'path name')
dynamic_system.add(path)
# or
from_model.add(to_model, Value(1), 'path name')
-
class
gsf.dynamic_system.dynamic_systems.discrete_event_dynamic_system.
DiscreteEventDynamicSystem
(scheduler: Optional[gsf.dynamic_system.future_event_list.scheduler.Scheduler] = None, event_bus: Optional[event_bus.bus.EventBus] = None)¶ Bases:
abc.ABC
,gsf.dynamic_system.core.base_dynamic_sytem.BaseDynamicSystem
Dynamic system for discrete-event models.
Its state transitions receives an specific time taken from the scheduler, using the event-scheduling time-advance algorithm.
-
_outputs
¶ Output of the models.
- Type
DynamicSystemOutput
-
_execute_autonomous
(models_already_executed: Set[DiscreteEventModel], event_time: Time) → Set[DiscreteEventModel]¶ Executes autonomous transition for the given input and external events of the affected models.
- Parameters
event_time (Time) – Time of the event.
models_already_executed – Models that its state was changed by the external transition and must be ignored.
-
_execute_external
(input_model_values: DynamicSystemInput, event_time: Time) → Set[DiscreteEventModel]¶ Executes external transition for the given input.
- Parameters
input_model_values (DynamicSystemInput) – Dictionary with key the identifier of the model.
event_time (Time) – Time of the event.
-
_get_affected_models_and_its_inputs
()¶ Gets models that were affected by an output
-
_get_effective_paths
(emitter_model: DiscreteEventModel) → Set[Path]¶ Gets the correct paths for an output
-
get_next_models
()¶ Gets the next models that will execute an autonomous event
-
get_output
()¶ Gets the output of all the models in the dynamic system. Changes only the model that changes at time t
-
get_time_of_next_events
()¶ Get time of the next event
-
remove
(model: DiscreteEventModel)¶ Removes a model of the dynamic system.
- Parameters
model (DiscreteEventModel) – Model to be removed.
-
schedule
()¶ Schedules an event at the specified time
- Parameters
model (DiscreteEventModel) – Model with an autonomous event scheduled
time (Time) – Time to execute event
-
state_transition
()¶ Executes the state transition of the models. If an input is given, the models defined as its inputs will be ignored.
- Parameters
input_models_values (DynamicSystemInput) – Dictionary with key the identifier of the model.
event_time (Time) – Time of the event.
-
unschedule
()¶ Undo a scheduled event
- Parameters
model (DiscreteEventModel) – Model with an autonomous event scheduled
-