Main Content


Class: matlab.DiscreteEventSystem
Namespace: matlab

Create entity forward event




event=eventForward(locationType,locationIndex,delay) creates an event to forward an entity from the current location to a new location. You can then schedule this event by returning it as the output argument when implementing an event action method, such as entry.

Input Arguments

expand all

Type of the new location. Specify 'storage' if the new location is a storage element of the discrete-event system. Specify 'output' if you want the entity to exit from an output port of the discrete-event system.

Index of the new location. If location type is 'storage', it indicates the index of a storage element. If location type is 'output', it indicates the index of an output port.

Time delay between current simulation time and the time the entity will be forwarded.

Output Arguments

expand all

Event that forwards the entity in current event action context to a new location.


Forward Current Entity to Storage

Define an event that forwards the current entity to storage.

function [entity,events] = entry(obj,storage,entity,src)  
    % Define an event that forwards the current entity to storage
    % element 2. Event shall be scheduled to execute 0.8 second later.
    event1 = obj.eventForward('storage', 2, 0.8);
    % Define an event that forwards the current entity to output port 1.
    % Event shall be scheduled to execute at current simulation clock time. 
    event2 = obj.eventForward('output', 1, 0);

    % Define events as event1 and event2
    events = [event1, event2];

Create a Custom Entity Storage Block to Delay Entities

This example shows how to use discrete-event System object™ methods to create a custom entity storage block that has one input port, one output port, and one storage element. The discrete-event System object is the instantiation of the matlab.DiscreteEventSystem class, which allows you to use the implementation and service methods provided by this class. Then, you use the MATLAB Discrete-Event System block to integrate the System object into a SimEvents® model.

The custom MATLAB Discrete-Event System block accepts an entity from its input port and forwards it to its output port with a specified delay. For more information, see Delay Entities with a Custom Entity Storage Block.

classdef CustomEntityStorageBlock < matlab.DiscreteEventSystem
    % A custom entity storage block with one input, one output, and one storage. 
    % Nontunable properties 
    properties (Nontunable)
    % Capacity
        Capacity = 1;
    % Delay
    methods (Access=protected)        
        function num = getNumInputsImpl(~)
            num = 1;
        function num = getNumOutputsImpl(~)
            num = 1;
        function entityTypes = getEntityTypesImpl(obj)
            entityTypes = obj.entityType('Car');
        function [inputTypes,outputTypes] = getEntityPortsImpl(obj)
            inputTypes = {'Car'};
            outputTypes = {'Car'};

        function [storageSpecs, I, O] = getEntityStorageImpl(obj)
            storageSpecs = obj.queueFIFO('Car', obj.Capacity);
            I = 1;
            O = 1;
        function [entity,event] = CarEntry(obj,storage,entity,source)
            % Specify event actions when entity enters storage.
             event = obj.eventForward('output', 1, obj.Delay);

Version History

Introduced in R2016a