Customize Discrete-Event System Behavior Using Events and Event Actions
You can customize the behavior of a discrete-event system by defining events and event actions.
You can:
Schedule events
Define event actions in response to events
Initialize events
Cancel events
Event Types and Event Actions
Event Types
A discrete-event system can have these event types and their targets.
Event type | Target | Purpose |
---|---|---|
eventAcquireResource | Entity | Allow an entity to acquire one or more resources. |
eventDestroy | Entity | Destroy an existing entity in storage. |
eventForward | Entity | Move an entity from its current storage to another storage or output port. |
eventIterate | Storage | Iterate and process each entity in storage. |
eventReleaseResource | Entity | Allow an entity to release one or more resources. |
eventReleaseAllResources | Entity | Allow an entity to release all previously acquired resources. |
eventTestEntry | Storage | Create an event to indicate that the storage acceptance policy is changed and the storage retests the arriving entities. |
eventTimer | Entity | Create a timer event. |
eventGenerate | Storage | Create an entity inside storage. |
Forward events
If a forward event fails because of blocking, the forward event remains active. When space becomes available, the discrete-event system reschedules the forward event for immediate execution.
Tagging events
You can schedule multiple events of the same type for the same actor. When using multiple events of the same type, use tags to distinguish between the events. For example, an entity can have multiple timers with distinct tags. When one timer expires, you can use the
tag
argument of thetimer
method to differentiate which timer it is. For more information, see Custom Entity Storage Block with Multiple Timer Events.If you schedule two events with the same tag on the same actor, the later event replaces the first event. If you schedule two events with different tags, the discrete-event system calls them separately.
Event Actions
When an event occurs, a discrete-event system responds to it by invoking a corresponding action. Implement these actions as System object™ methods. This table lists each action method and the triggering event.
Event Action | Triggering Event | Purpose |
---|---|---|
blocked | eventForward | Called if, upon execution of a forward event, the entity cannot leave due to blocking from the target storage. |
destroy | eventDestroy | Called before an entity is destroyed and removed from storage. |
entry | eventForward | Called upon an entity entry. |
exit | eventForward | Called upon entity exit. When an entity is forwarded from
storage 1 to storage 2 ,
the exit action of storage 1 and then the
entry action of storage 2 are called. |
generate | eventGenerate | Called after a new entity is created inside a storage element. |
iterate | eventIterate | Upon the execution of an Iterate event, this method is invoked for each entity from the front to the back of the storage, with the option of early termination. If entities need to be resorted due to key value changes, resorting takes place after the entire iteration is complete. |
resourceAcquired | eventAcquireResource | Called after a successful resource acquisition. A resource acquisition is successful only if all of the specified resources are acquired. |
resourceReleased | eventReleaseResource | Called after the resource release. |
testEntry | eventTestEntry | Called after the test entry event. |
timer | eventTimer | Called upon executing a timer event of an entity. |
Initialize Events
Use these methods to initialize empty arrays and events of a discrete-event system.
Event Type | Purpose |
---|---|
initEventArray | Initialize event array. |
initResourceArray | Initialize a resource specification array. |
setupEvents | Initialize entity generation events. |
Cancel Previously Scheduled Events
Use these methods to cancel previously scheduled events of a discrete-event system.
Event type | Purpose |
---|---|
cancelAcquireResource | Cancel previously scheduled resource acquisition event |
cancelDestroy | Cancel previously scheduled entity destroy event. |
cancelForward | Cancel entity forward event. |
cancelGenerate | Cancel previously scheduled entity generation event. |
cancelIterate | Cancel previously scheduled iterate event. |
cancelTimer | Cancel previously scheduled timer event. |
Event Identifiers
There are two distinct identifiers for the events provided by the matlab.DiscreteEventSystem
class.
Tag — Use the
tag
as an input argument for a method.event1 = obj.eventTimer('mytimer1', 2); event2 = obj.eventTimer('mytimer2', 5);
Here,
mytimer1
andmytimer2
are used as tags to refer to these two timer events.Destination — Use the destination to identify forward events.
event1 = obj.eventForward('storage', 2, 0.8); event2 = obj.eventForward('output', 1, 2);
Here,
storage
andoutput
are used to distinguish two forward events.
The events are not distinguishable when their identifiers are the same. This table shows how to identify an event when multiple events of the same type act on the same target.
Event Type | Identification |
---|---|
eventAcquireResource | Tag |
eventGenerate | Tag |
eventIterate | Tag |
eventReleaseResource | Tag |
eventReleaseAllResources | Tag |
eventTimer | Tag |
eventForward | Destination |
Note
If you define an event that is yet to be executed and a second event with the same type and identifier, the first event is replaced by the second one.
See Also
matlab.DiscreteEventSystem
| blocked
| destroy
| entry
| eventForward
| eventGenerate
| generate
| setupEvents
| matlab.System