simevent
The simevent module provides the basic implementation for simulation events, or SimEvent in short. SimEvents are instances that store information about a method that can be called later by the simulator, as used in the event scheduling paradigm for discrete-event simulation. This later, or deferred, calling of a method is known as “deferred method invocation”.
The SimEventInterface in this module allows other implementations of the SimEvent, which will be recognized by the event lists and other classes.
- class pydsol.core.simevent.SimEventInterface[source]
Bases:
ABC
SimEventInterface defines the properties that all SimEvent classes need to have. The most important property of a SimEvent is that it is executable, so it defines the execute() method.
- abstract property time: int | float
Return the absolute execution time, float or int.
- abstract property priority: int
Return the priority; higher value is higher priority.
- abstract property id: int
Return the unique id of of the SimEvent.
- class pydsol.core.simevent.SimEvent(time: int | float, target, method: str, priority: int = 5, **kwargs)[source]
Bases:
SimEventInterface
SimEvent stores the information on a deferred method call that will be scheduled on the event list. Deferred method invocation is the execution of a method with arguments at a chosen time, rather than immediately.
The methods to implement are specified in the SimEventInterface.
- Attributes:
_absolute_time (float or int) – the absolute execution time of the SimEvent
_priority (int) – the priority of the event when two events are scheduled at the same time; higher numbers indicate higher priority; typically, priorities are numbered 1 through 10 with a default priority of 5
_id (int) – unique number of the event to act as a tie breaker when both the absolute time and the priority of the event are the same
_target (object) – the object on which the method has to be called
_method (method) – the method to call, stored as the attr of the target
_kwargs (dict) – a dict with arguments to use for the method
- __init__(time: int | float, target, method: str, priority: int = 5, **kwargs)[source]
- Parameters:
time (float or int) – the absolute execution time of the SimEvent
target (object) – the object instance on which the method has to be called
method (str) – the name of the method to call, as a string
priority (int (optional)) – the priority of the event when two events are scheduled at the same time. Higher numbers indicate higher priority. Typically, priorities are numbered 1 through 10 with a default priority of 5. When not provided, the default priority of 5 will be used.
**kwargs (dict (optional)) – the arguments of the method call provided as comma-separated arg=value pairs
- Raises:
DSOLError – when one of the arguments is not of the correct type, when: the method does not exist for the target, or when the method is not callable on the target.
- execute()[source]
Execute the stored method on the target object with the provided arguments for the method.
- Returns:
This is quite important. Since the method will be called asynchronously, no object can do anything with a return value.
- Return type:
None
- Raises:
DSOLError – when the method call fails or returns an exception:
- property time: float | int
Return the absolute execution time, float or int.
- property priority: int
Return the priority; higher value is higher priority.
- property id: int
Return the unique id of of the SimEvent.
- property target: object
Return the target object instance to execute the method call on.
- property method: str
Return the name of the method to be called on the target.
- property kwargs: dict
Return the dict of arguments to be passed to the method.