Entities in a SimEvents Model

Entities are discrete items of interest in a discrete-event simulation. By definition, these items are called entities in SimEvents® software. Entities can pass through a network of queues, servers, gates, and switches during a simulation. Entities can carry data, known in SimEvents software as attributes.

SimEvents models typically contain at least one source block that generates entities. Other SimEvents blocks in the model process the entities that the source block generates.

Note

Entities are not the same as events. Events are instantaneous discrete incidents that change a state variable, an output, and/or the occurrence of other events. See Role of Events in a SimEvents Model for details.

Meaning of Entities in Different Applications

You determine what an entity signifies, based on what you are modeling. The table lists example entity representations in various applications.

Context of Sample ApplicationEntities
Airport with a queue for runway accessAirplanes waiting for access to runway
Communication networkPackets, frames, or messages to transmit
Bank of elevatorsPeople traveling in elevators
Conveyor belt for assembling partsParts to assemble
Computer operating systemComputational tasks or jobs

Vary the Interpretation of Entities

A single model can use entities to represent different kinds of items. For example, if you are modeling a factory that processes two different kinds of parts, you can:

  • Use two Entity Generator blocks to create the two kinds of parts.

  • Use one Entity Generator block and subsequently assign an attribute to indicate what kind of part each entity represents and another attribute to represent a property.

Note

SimEvents entities are fundamentally the same as Stateflow® messages.

Visualize Entities

Entities do not appear explicitly in the model window. A graphical block can represent a component that processes entities, but entities themselves do not have a graphical representation. However, you can gather information about entities using Simulink® scopes. You cannot branch an entity connection line. If your application requires an entity to arrive at multiple blocks, use Entity Replicator block to create copies of entities.

Storing Entities

These blocks are capable of holding an entity:

  • Entity Generator

  • Entity Queue

  • Multicast Receive Queue

  • Entity Server

  • Entity Terminator

  • Discrete Event Chart

  • MATLAB Discrete Event System

  • Entity Replicator

  • Resource Acquirer

  • Resource Releaser

These blocks permit an entity arrival but must output or destroy the entity at the same value of the simulation clock:

  • Entity Input Switch

  • Entity Output Switch

  • Entity Multicast

  • Entity Gate

  • Composite Entity Creator

  • Composite Entity Splitter

  • Resource Pool

Entity Types

An entity type is the identification tag associated with any block that creates entities in your model. For the Entity Generator block, you assign a name to the entity type on the Entity type tab of the generation block. From this block, each new entity receives this tag. For example, the name of the entity type associated with an Entity Generator in your model might be Customer. Each entity that originates in that block receives this entity type. A Composite Entity Creator block also generates new entities by combining two or more existing entities to form a new composite entity. You can assign a new entity type name to the entity type (named Combined by default).

Note

The Entity Replicator block also generates new entities by outputting copies of an incoming entity. However, because the incoming entity already possesses an entity type, the block does not create new entity types for the copies.

As an entity progresses through your model, its type does not change. Even if the entity acquires attribute, timeout, or timer data that give it a more complex structure, the entity type remains the same. Although a Composite Entity Creator block forms new composite entities with a new entity type, the underlying entity types remain the same.

By default, each new entity type that SimEvents creates in your model uses the name Entity.

The Entity Generator block can generate these entity types:

  • Anonymous — Unstructured entity with no name. You can specify only entity priority and initial data value for anonymous entity types.

  • Structured — Structured entity type that you define in this block dialog box. You can name entities, specify priorities, and specify attributes for the entity in the Define attributes section of the Entity Generator block. Attributes are data carried by entities. Creating a structured entity in this tab is a convenient way to create an entity without having to create an associated bus object in Simulink.

  • Bus object — Entity type that you define using Simulink bus objects. You can name entities, specify priorities, and specify attributes for the entity. To specify this entity type, you must have an existing bus object, created in Simulink, and use that bus object name as the name of the entity type. This bus object:

    • Must be a valid bus object with one or more bus elements at a single level.

    • Cannot contain variable-size elements. This limitation is also true for entities registered as bus objects through the Composite Entity Creator block.

Data and Role of Entity Attributes

You can optionally attach data to entities. Such data is stored in one or more attributes of an entity. You define names and numeric values for attributes. For example, if your entities represent a message that you are transmitting across a communication network, you might assign data called length that indicates the length of each particular message. You can read or change the values of attributes during the simulation.

Entities and attributes can be of any data type that Simulink supports, including enumerated types. For more information, see Data Types Supported by Simulink (Simulink). Entities and attributes cannot be a fixed-point data type.

Data types supported by MATLAB® but not supported by Simulink may not be passed between the Simulink model and event actions. You can use these data types in event actions as local variables.

You can optionally specify the structure of an entity using a Simulink bus object. This capability is useful when defining complex entity structures that need to be defined once, but used in multiple locations in a model. In addition, the MATLAB Discrete-Event System and Discrete Event Chart blocks require that you specify entities as bus objects. For more information on bus objects, see Specify Bus Properties with Bus Objects (Simulink).

Create Entities in a SimEvents Model

An Entity Generator block can be used to generate entities. By default, the block creates time-based entities. You can change the Time Source parameter to select the time source for the entity generation. You can create time-based entities using:

Create Time-Based Entities

Use the Entity Generation block to create time-based entities. The Entity Generation lets you specify a period at which it creates entities.

  1. Open the SimEvents block library. You can use the Simulink browser or type simevents at the MATLAB Command Window.

  2. Create a new model.

  3. From the SimEvents library, drag the Entity Generator block to the new model.

  4. From the SimEvents library, drag the Entity Queue block to the new model.

    • Connect the Entity Generator block to the input of the Entity Queue.

    • In the Entity Queue block, select Number of entities departed, d.

  5. From the Simulink Sinks library, drag a Scope block to the new model. Connect the Scope block to the d port of the Entity Queue block.

  6. From the SimEvents library, drag an Entity Terminator block to the new model. Connect the output of the Entity Queue block to the input of the Entity Terminator block.

Upon simulation, the scope displays the entities that depart the queue.

Note

You cannot connect a scope to a SimEvents line, as denoted by the thick double arrow line.

Create Randomized Entities

Use the Entity Generation block to create time-based entities. The Entity Generation lets you specify a randomization operation (such as the MATLAB rand function) to create entities at random times.

  1. Open the SimEvents block library. You can use the Simulink browser or type simevents at the MATLAB Command Window.

  2. Create a model.

  3. From the SimEvents library, drag the Entity Generator block to the new model.

    1. Double-click the block and set the Time source parameter to MATLAB action.

    2. In the Intergeneration time action parameter, enter a call to a randomizer function, such as rand. For example:

      dt = rand(1,1);

  4. From the SimEvents library, drag the Entity Queue block to the new model.

    • Connect the Entity Generator block to the input of the Entity Queue

    • In the Entity Queue block, select Number of entities departed, d.

  5. From the Simulink Sinks library, drag a Scope block to the new model. Connect the Scope block to the d port of the Entity Queue block.

  6. From the SimEvents library, drag an Entity Terminator block to the new model. Connect the output of the Entity Queue block to the input of the Entity Terminator block.

Upon simulation, the scope displays the entities that depart the queue.

See Also

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

Related Examples

More About