Main Content

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 typeTargetPurpose
eventAcquireResourceEntityAllow an entity to acquire one or more resources.
eventDestroyEntityDestroy an existing entity in storage.
eventForwardEntityMove an entity from its current storage to another storage or output port.
eventIterateStorageIterate and process each entity in storage.
eventReleaseResourceEntityAllow an entity to release one or more resources.
eventReleaseAllResourcesEntityAllow an entity to release all previously acquired resources.
eventTestEntryStorageCreate an event to indicate that the storage acceptance policy is changed and the storage retests the arriving entities.
eventTimerEntityCreate a timer event.
eventGenerateStorageCreate 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 the timer 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 ActionTriggering EventPurpose
blockedeventForwardCalled if, upon execution of a forward event, the entity cannot leave due to blocking from the target storage.
destroyeventDestroyCalled before an entity is destroyed and removed from storage.
entryeventForwardCalled upon an entity entry.
exiteventForwardCalled 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.
generateeventGenerateCalled after a new entity is created inside a storage element.
iterateeventIterateUpon 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.
resourceAcquiredeventAcquireResourceCalled after a successful resource acquisition. A resource acquisition is successful only if all of the specified resources are acquired.
resourceReleasedeventReleaseResourceCalled after the resource release.
testEntryeventTestEntryCalled after the test entry event.
timereventTimerCalled 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 TypePurpose
initEventArrayInitialize event array.
initResourceArrayInitialize a resource specification array.
setupEventsInitialize entity generation events.

Cancel Previously Scheduled Events

Use these methods to cancel previously scheduled events of a discrete-event system.

Event typePurpose
cancelAcquireResourceCancel previously scheduled resource acquisition event
cancelDestroyCancel previously scheduled entity destroy event.
cancelForwardCancel entity forward event.
cancelGenerateCancel previously scheduled entity generation event.
cancelIterateCancel previously scheduled iterate event.
cancelTimerCancel 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 and mytimer2 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 and output 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.

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

| | | | | | | |

Related Topics