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.

Manage Entities Using Event Actions

This example shows how to control entity generation rate and write event actions to change entity attributes in a simple queuing system. In a discrete-event simulation, an event is an observation of an instantaneous incident that may change a state variable, an output, or the occurrence of other events. SimEvents® allows you to create custom actions when an event occurs. These actions are called event actions. Events can have corresponding actions. You can write event actions to change entity attributes by using MATLAB® code or Simulink® functions.

This is a simple queuing system with Entity Generator, Entity Queue, Entity Server, and Entity Terminator blocks. For more information about performing basic model-building tasks to create this model, see Create a Discrete-Event Model.

In this example, an entity represents the tank of a truck that arrives at a gas station. The attribute of an entity represents the current gas level in a tank. Event actions represent the changes of the gas level in a tank. Tanks are randomly generated, queued, and they are serviced with a pump which transfers a constant amount of gas for one second duration. Tanks depart from the station with their new total gas amount.

To open the example model without performing the configuration steps, see Manage Entities in a Queueing System.

Build the Model

  1. Select the whole model or the entity paths originating from the Entity Generator, Entity Queue, and Entity Server blocks and right-click to select Log Selected Signals. Simulation Data Inspector is used to visualize the flow of tanks and their gas level in the model. For more information, see Inspect Simulation Data (Simulink).

  2. Rename the Entity Generator block as Tank Generator, the Entity Queue block as Waiting Queue, the Entity Server block as Pump, and the Entity Terminator block as Exit.

  3. Rename the path originating from the Tank Generator block as Tank to Queue, the Waiting Queue block as Tank to Pump, and the Pump block as Tank to Exit.

Configure and Simulate Model

  1. Double-click the Tank Generator, and select the Entity type tab. Change the Entity type name to Tank, and the Attribute Name to CurrentGasLevel.

    The entity attribute CurrentGasLevel represents the existing amount of gas in each tank.

  2. Simulate the model. Open the Simulation Data Inspector. Observe that the tanks approach the Waiting Queue, the Pump, and the Exit with the same rate.

    Tanks leave the station with their initial gas amount 1 which is the Attribute Initial Value.

  3. Open the Tank Generator block parameters dialog box. In the Entity generation tab, set Time source to Matlab action. Observe the default MATLAB code.

    dt = rand(1,1);

    The code randomizes the entity intergeneration time parameter dt to represent random tank arrivals.

  4. Simulate the updated model. In the Simulation Data Inspector, observe that tanks arrive randomly with the same initial gas amount 1.

    Observe that the tanks are generated randomly but they approach the pump with a regulated fixed rate because service time for the Pump is 1.

  5. Open the Tank Generator block dialog box. In the Event actions tab, in the Generate action field, enter the code.

    entity.CurrentGasLevel = randi([1,4]);

    Tanks arrive at the station with a random gas amount that ranges from 1 to 4.

  6. Simulate the updated model. In the Simulation Data Inspector, observe that the tanks arrive with random amounts of gas.

  7. For the Pump block, set these parameters:

    1. In the Event actions tab, select Service complete.

    2. For the Service complete action field, enter the code.

      entity.CurrentGasLevel = entity.CurrentGasLevel + 3;

      Each tank is filled with 3 units of gas for 1s duration, and then it departs the pump.

    Observe that the Tank Generator and the Pump blocks update with the event action icon {...} indicating that the blocks define an event action.

  8. Simulate the updated model. In the Simulation Data Inspector, observe that each tank leaves the station with 3 additional units of gas.

Manage Entities in a Queueing System

Open the example to investigate the model that manages entities with event actions.

See Also

| | |

Related Topics