This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Events and Event Actions

In a discrete-event simulation, an event is an observation of an instantaneous incident that may change a state variable, an output, and/or the occurrence of other events. You can create event actions to occur when entities change state, for example, when an entity exits a block. For a list of blocks and the actions they can have, see Storage Actions.

An event calendar tracks upcoming events for a model during a discrete-event simulation. For more information on the event calendar, see Event Calendar.

The event actions assistant helps you create repeated sequence of event actions or random event actions according to a statistical distribution. For more information on the event actions assistant, see Event Actions Assistant for Events.

Create Event Actions

Define event actions on the Event actions tab of a block. These are the possible actions for which you can create events.

Entity GeneratorEntity QueueEntity ServerEntity TerminatorResource AcquirerEntity Batch Creator

Entity generation

Entity entry to queue block

Entity entry to server block

Entity entry to terminator block

Entity entry to acquirer block

Entity entry to batch block

Entity exit from block

Entity exit from block

Service completion of entity

N/A

Entity exit from acquirer block

Entity batch generation

N/A

Entity is blocked

Entity exit from block

N/A

Entity is blocked

Entity exit from block

N/A

N/A

Entity is blocked

N/A

N/A

Entity is blocked

N/A

N/A

Entity is preempted

N/A

N/A

N/A

In event actions, you can also modify entity attributes (entityName.attributeName), entity priorities (sys.entity.priority), and entity IDs (sys.entity.id). However, you cannot change these entity attributes or its system properties (entitySys) for exit actions in any block. Attempting to change these values causes an error at simulation.

The seExampleTankFilling example has two event actions defined, in the Entity Generator and Entity Server blocks. This example recreates the event action in the Entity Server block.

  1. In a new model, from the SimEvents® library, drag the Entity Server and Simulink Function blocks.

  2. In the Entity Server block:

    • Click the Entity actions tab.

    • To create an action on entity entry, click Entry.

    • In the Entry action section, type:

      startFilling(entity.Capacity);

      This command calls the function, startFilling.

      The ingoing line to the Entity Server block icon updates with the event action icon ({...}) indicating that the block defines an event action.

  3. In the Simulink Function block:

    1. In Trigger Port, enter startFilling in the Function name parameter.

    2. Drag in an Inport block and rename it to cap.

    3. Rename the u input to capacity and connect it to cap.

    4. Remove the y output.

    5. Drag in a MATLAB Function block and an Outport block.

    6. In the MATLAB Function, enter the code:

      function y = toggle()
      %#codegen
      persistent u
      
      if isempty(u)
          u = -1;
      end
      
      if u == -1
          u = 1;
      else
          u = -1;
      end
      
      y = u;
    7. Connect the y output of the MATLAB Function block to the Outport block and rename the Outport block to reset.

    You have now defined the startFilling function for the event action. To optionally visualize the connection between the Entity Server block and the Simulink Function block, in the Editor, select Display > Function Connectors.

See Also

| | | | | | | | | | | | | | | |

Related Examples

More About