Main Content

Working with Entity Attributes and Entity Priorities

You can attach data to an entity using one or more entity attributes. Each attribute has a name and a numeric value. You can read or change the values of attributes during the simulation.

For example, suppose your entities represent a message that you are transmitting across a communication network. You can attach the length of each particular message to the message itself using an attribute named length.

You can use attributes to describe any measurable property of an entity. For example, you could use attribute values to specify:

  • Service time to be used by a downstream server block

  • Switching criterion to be used by a downstream switch block

You can also set entity priorities which is used to prioritize events

Attach Attributes to Entities

To attach attributes to an entity, use the Entity Generator block. You can attach attributes such as:

  • Constant values

  • Random numbers

  • Elements of either a vector in the MATLAB® workspace or a vector that you can type in a block dialog box

  • Values of an output argument of a MATLAB function

  • Values of a signal

  • Outputs of a function defined in Simulink® or Stateflow® environment.

These lists summarize the characteristics of attribute values for structured entity types.

Attribute values must be:

  • Real or complex

  • Arrays of any dimension, where the dimensions remain fixed throughout the simulation

  • All built-in data types (double, single, int8, uint8, int16, uint16, int32, and uint32)

  • Enumerations

For a given attribute, the characteristics of the value must be consistent throughout the discrete-event system in the model. Attribute values can not be:

Not Permitted as Attribute Values

  • Structures

  • Buses

  • Variable-size signals or variable-size arrays

  • Frames

Set Attributes

To build and manage the list of attributes to attach to each departing entity, use the controls under the Define attributes section of the Entity Generator block. Each attribute appears as a row in a table.

Using these controls, you can:

  • Manually add an attribute.

  • Modify an attribute that you previously created.

The buttons under Set Attribute perform these actions.

Square button with green plus symbol

Add an attribute to the table.

Rename the attribute and specify its properties.

Square button with red cross symbol

Remove the selected attribute from the attribute table.

When you delete an attribute this way, no confirmation appears and you cannot undo the operation.

You can also organize the attributes by clicking Up button and Down button.

The table displays the attributes you added manually. Use it to set these attribute properties.


Attribute Name

The name of the attribute. Each attribute must have a unique name.

Double-click the existing name, and then type the new name.

Attribute Initial Value

The value to assign to the attribute.

Double-click the value, and then type the value you want to assign.

Write Functions to Manipulate Attributes

To manipulate attributes using MATLAB code, use the Event actions tab of a block. To access the attribute, use the notation entityName.attributeName. For example:

entity.Attribute1 = 5;

Suppose that you want to modify the attribute of an entity after it has been served.

  1. In a new model, from the SimEvents® library, drag the Entity Generator, Entity Server, and Entity Terminator blocks and connect them.

    Simple block diagram showing an Entity Generator block connected to an Entity Server block that, in turn, connects to an Entity Terminator block.

  2. Double-click Entity Generator block and, in the Entity type tab, add three attributes to the attributes table.

  3. Double-click on the second and third attributes in the Attribute Name column and rename them Attribute2 and Attribute3, respectively.

    Block Parameters dialog box of the Entity Generator block with the Entity type tab highlighted. Here, the Entity type is set to Structured, Entity priority is set to 300, and Entity type name is set to Entity. Three attributes are listed in the Define attributes window: Attribute1, Attribute2 and Attribute3.

  4. In the Entity Server block, click the Event actions tab.

  5. Click Service complete, and enter MATLAB code to manipulate the entity attributes you added in the Entity Generator block:

    Block Parameters dialog box of the Entity Server block with the Event actions tab highlighted. In the Event actions pane on the left, Service Complete is selected. The Service complete action code is typed out in the text window on the right: entity.Attribute3=entity.Attribute1+entity.Attribute3.

    Click OK. The Entity Server block displays the event action language.

  6. To see the action, in the model, hover over the Entity Server block event action icon.

    Simple block diagram with mouse hovering over the Entity Server block event action icon: an ellipsis contained within curly brackets. The tooltip displays the Service complete action code.

Use Attributes to Route Entities

Suppose entities represent manufactured items that undergo a quality control process and a packaging process. Items that pass the quality control test proceed to one of three packaging stations, while items that fail the quality control test proceed to one of two rework stations. You can model the decision-making process by using these switches:

  • An Entity Output Switch block that routes items based on an attribute that stores the results of the quality control test

  • An Entity Output Switch block that routes passing-quality items to the packaging stations

  • An Entity Output Switch block that routes failing-quality items to the rework stations

You can use the block Switching criterion parameter From attribute option to use an attribute to select the output port. For an example, see Model Traffic Intersections as a Queuing Network.

Entity Priorities

SimEvents uses entity priorities to prioritize events. The smaller the priority value, the higher the priority.

You specify entity priorities when you generate entities. In the Entity Generator block, in the Entity Type tab, the Entity priority specifies the priority value of the generated entity.

You can later change entity priorities using an event action. For example, in the Entity Generator block Event actions tab, you can define an event action to change the entity priority during simulation using code such as:

entitySys.priority=MATLAB code

The entity priorities have a role in prioritization of events in the Event Calendar which schedules events to be executed.

In SimEvents, the Event Calendar sorts events based on their times and associated entity priorities as follows:

  1. The event that has the earliest time executes first.

  2. If two entities have events occurring at the same time, the event with the entity of higher priority occurs first.

  3. If both entities have the same priority, either event may be served first. To service the entities in a deterministic order, change one of the entity priorities.

For example, assume a forward event is associated with an entity that exits block A and enters block B. The priority of this event is the priority of the entity being forwarded. If there are two entities trying to depart a block at the same time, the entity with the higher priority departs first.

For more information about Event Calendar and debugging SimEvents models, see Debug SimEvents Models.

See Also

| |

Related Examples

More About