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
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:
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 (
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
Variable-size signals or variable-size arrays
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.
Add an attribute to the table.
Rename the attribute and specify its properties.
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 and .
The table displays the attributes you added manually. Use it to set these attribute properties.
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
entity.Attribute1 = 5;
Suppose that you want to modify the attribute of an entity after it has been served.
In a new model, from the SimEvents® library, drag the Entity Generator, Entity Server, and Entity Terminator blocks and connect them.
Double-click Entity Generator block and, in the Entity type tab, add three attributes to the attributes table.
Double-click on the second and third attributes in the Attribute Name column and rename them Attribute2 and Attribute3, respectively.
In the Entity Server block, click the Event actions tab.
Click Service complete, and enter MATLAB code to manipulate the entity attributes you added in the Entity Generator block:
Click OK. The Entity Server block displays the event action language.
To see the action, in the model, hover over the Entity Server block event action icon block.
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.
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:
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:
The event that has the earliest time executes first.
If two entities have events occurring at the same time, the event with the entity of higher priority occurs first.
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.
- Working with Entity Attributes and Entity Priorities
- Serve High-Priority Customers by Sorting Entities Based on Priority