queueFIFO

Class: matlab.DiscreteEventSystem
Package: matlab

Define first-in first-out (FIFO) queue storage

Syntax

storage=queueFIFO(entityType,capacity)

Description

storage=queueFIFO(entityType,capacity) defines a FIFO queue storage element. Use this function when implementing the getEntityStorageImpl method.

Input Arguments

expand all

Type of entities that the new storage element works with.

Maximum number of entities that the storage can contain, specified as a double.

Output Arguments

expand all

Queue storage that contains entities and sorts them in FIFO order.

Examples

Specify FIFO Queue Entity Storage

Specify FIFO queue entity storage for the discrete-event system object.

% Define a storage element as a FIFO queue
% - Entities in the queue are sorted in First-In-First-Out (FIFO) order
% - Queue can store entities of type 'myEntity'
% - Queue can store no more than 25 entities
storage = obj.queueFIFO('myEntity', 25); 

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

Introduced in R2016a