Main Content

eventGenerate

Class: matlab.DiscreteEventSystem
Namespace: matlab

Create entity generate event

Syntax

event=eventGenerate(storageID,tag,delay,priority)

Description

event=eventGenerate(storageID,tag,delay,priority) creates an event to generate an entity. 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

Index of the storage element, where a new entity will be generated.

Custom tag of this entity generate event.

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

Positive integer value indicating system priority of the new entity. A smaller numeric value indicates a higher priority.

Output Arguments

expand all

Event that generates an new entity in the specified storage element.

Examples

Define Entity Generation Event

Define entity generation event in storage element 3.

function event = setupEvents(obj) 
    % Define an entity generation event
    % - A new entity shall be created in storage element 3
    % - The event has a custom tag 'seed'
    % - The event shall be executed 0.5 second later
    % - The new entity shall be initialized with a priority of 200
    event = obj.eventGenerate(3, 'seed', 0.5, 200);
end

Create a Custom Block to Generate Entities

This example shows how to create a custom source block that generates entities and to manage discrete states when implementing the discrete-event System object™ methods.

For more information, see Custom Entity Generator Block with Signal Input and Signal Output.

classdef CustomEntityStorageBlockGeneration < matlab.DiscreteEventSystem...
                                            & matlab.System
    % A custom entity generator block.
    
    % Nontunable properties 
    properties (Nontunable)
        % Generation period
        period = 1;
    end

    properties(DiscreteState)
        % Entity priority
        priority;
        % Entity value
        value;
    end

    % Discrete-event algorithms
    methods
        function [events, out1] = setupEvents(obj)
            % Set up entity generation events at simulation start.
            events = obj.eventGenerate(1,'mygen',obj.period,obj.priority);
            % Set up the initial value of the output signal.
            out1 = 10;
        end

        function [entity,events,out1] = generate(obj,storage,entity,tag,in1)            
            % Specify event actions when entity is generated in storage.            
            entity.data = obj.value;
            % The priority value is assigned from the input signal.
            obj.priority = in1;
            % Output signal is the assigned priority value.
            out1 = obj.priority;
            events = [obj.eventForward('output',1,0) ...
                      obj.eventGenerate(1,'mygen',obj.period,obj.priority)];
        end
    end

    methods(Access = protected)
        
        function entityTypes = getEntityTypesImpl(obj)
            entityTypes = obj.entityType('Material');
        end
        
        function [inputTypes,outputTypes] = getEntityPortsImpl(obj)
            % Specify entity input and output ports. Return entity types at
            % a port as strings in a cell array. Use empty string to
            % indicate a data port.
            inputTypes = {''};
            outputTypes = {'Material',''};
        end

        function resetImpl(obj)
            % Initialize / reset discrete-state properties.
            obj.priority = 10;
            obj.value = 1:12;            
        end
        
        function [storageSpecs, I, O] = getEntityStorageImpl(obj)
            storageSpecs = obj.queueFIFO('Material', 1);
            I = 0;
            O = [1 0];
        end   

        function num = getNumInputsImpl(obj)
            % Define total number of inputs for system with optional
            % inputs.
            num = 1;
        end
        
        function num = getNumOutputsImpl(~)
            % Define total number of outputs.
            num = 2;
        end  
        function [out1 out2] = getOutputSizeImpl(obj)
            % Return size for each output port.
            out1 = [1 12];
            out2 = 1;
        end

        function [out1 out2] = getOutputDataTypeImpl(obj)
            % Return data type for each output port.
            out1 = "double";
            out2 = "double";
        end

        function [out1 out2] = isOutputComplexImpl(obj)
            % Return true for each output port with complex data.
            out1 = false;
            out2 = false;
        end

        function [sz,dt,cp] = getDiscreteStateSpecificationImpl(obj,name)
            % Return size, data type, and complexity of discrete-state
            % specified in name.
            switch name
                case 'priority'
                    sz = [1 1];
                case 'value'
                    sz = [1 12];
            end
            dt = "double";
            cp = false;           
        end
    end
end

Version History

Introduced in R2016a