Main Content

entry

Class: matlab.DiscreteEventSystem
Namespace: matlab

Event action when entity enters storage element

Syntax

[entity,events]=entry(obj,storage,entity,source)
[entity,events,out1,...]=entry(obj,storage,entity,source,in1,...)

Description

[entity,events]=entry(obj,storage,entity,source) specifies event actions of the object when an entity enters storage.

[entity,events,out1,...]=entry(obj,storage,entity,source,in1,...) such event actions of the object when the block has one or more input signal ports and/or signal output ports.

Input Arguments

expand all

Discrete-event System object.

Index of the storage element.

Entity entering storage component. Entity has these fields:

  • sys (MATLAB structure) — It has these fields:

    • id (double) — Entity ID

    • priority (double) — Entity priority

  • data — Entity data

Source location of entity, such as an input port or a storage element. It has these fields:

  • type (character vector) — Specify input or storage

  • index (double) — Input or storage index

Any data inputs of the object. These input arguments exist only when the object has data inputs.

Output Arguments

expand all

Entity entering storage, possibly with changed data. See entity.

Events to be scheduled. Use matlab.DiscreteEventSystem class methods to create events. Each event has these fields:

  • type (character vector) — Type of the event

  • delay (double) — Delay before the event

  • priority (double) — Priority of the event

  • Storage (double) — Index of the storage element

  • tag (character vector) — Event tag

  • location (MATLAB structure) — Source or destination location of entity, see source

Data outputs of the object. You must specify these output arguments when the object has data outputs.

Examples

Event Action Upon Entity Entry

Event action for entity entry to storage.

function [entity,events] = entry(obj,storage,entity,src)
    % Specify event actions when entity entered storage.
    disp(['Entity of ID ' num2str(entity.sys.id) ...
          ' has entered storage element ' num2str(storage)]);
    switch src.type
        case 'input'
            disp(['Entity came from input port ' num2str(src.index)]);
        case 'storage'
            disp(['Entity came from storage element ' num2str(src.index)]);
    end
    events = [ ...
        obj.eventDestroy(), ...    % Destroy the newly entered entity
        obj.eventIterate(2, '')];  % Iterate entities in storage element 2
end

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
        Delay=4;
    end
    
    methods (Access=protected)        
        function num = getNumInputsImpl(~)
            num = 1;
        end
        
        function num = getNumOutputsImpl(~)
            num = 1;
        end      
        
        function entityTypes = getEntityTypesImpl(obj)
            entityTypes = obj.entityType('Car');
        end
        
        function [inputTypes,outputTypes] = getEntityPortsImpl(obj)
            inputTypes = {'Car'};
            outputTypes = {'Car'};
        end

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

Version History

Introduced in R2016a