Paul Toone avatar image
Paul Toone posted


Labels are also a key concept to understand in building models in FlexSim. They are very similar to the itemtype value in that they store data on objects that can be used in making decisions in the model. However, there are some key differences, listed below:

  • Each label has a name that is defined by you the modeler.
  • Unlike itemtype, which is specific to flowitems, labels can be defined on objects as well as flowitems (e.g. Sources, Queues or Processors).
  • An object can have as many labels as you choose to give it.
  • Labels can have number, string, or pointer values, whereas the itemtype can only have a number value. Labels can even hold lists or tables of values.
  • With labels, you must explicitly add the label to the object through its properties window, unlike the itemtype value, which is automatically included with every flowitem.
  • When adding a label to a flowitem in the Flowitem Bin, the label is specific to that flowitem class. This means that if you add a label to the Pallet flowitem class, only flowitems that are created from that Pallet class will have that label on them.


For flowitems, the value you specify for labels will be the default value for all flowitems that are created, but you can change that value on each flowitem as it progresses through your model. For FlexSim objects' labels, the label's value will remain the same unless you either have logic within the object that changes the label's value.

Label values will not reset on their own unless you check the Automatically Reset Labels button in the label tab page. Alternatively, you can add code or a picklist option to the object's OnReset trigger to reset the label value. Both options will set the label back to an initial value when you press the Reset button to reset a model.


You can get to the FlowItem Bin either through the User Toolbar or through the Toolbox. To add labels to flowitems, go to the FlowItem Bin, select the flowitem class that is being created by your Source (Box in this example), and edit the labels from the Quick Properties view. Alternatively, you can press the properties button (our double click the box) to display the Flowitems properties and edit the labels tab. You can add string or number labels to your objects.

The process works similar for other FlexSim objects. You can edit their labels from the Quick Properties window, or double-click on the object and edit and go to the labels tab. Specify each label's name in the row headers column on the left, and its value to the right of its name.

Let's extend the example model mentioned in the Itemtype section to use labels. Let's say for example that each "copy" customer that comes into the post office has a certain number of copies that need to be made, and that the service time for that customer is dependent on the number of copies needed. A customer that needs 1000 copies will take longer to service than a customer that needs 1 copy. As before, the itemtype value of each flowitem, or customer, reflects the category of customer, either "package" or "copy", but now for "copy" customers we need to add a label that tells us how many copies that customer needs. Again, to add a label to a flowitem, go to the Flowitem Bin, then select the flowitem class and click on Properties. Here we would add a number label ("Add Number Label") and give it a name like "numOfCopies". As the default value we would leave it at 0 and set the value in the Source's exit trigger.

Once the label has been added in the Flowitem Bin, we can set the label's value when each flowitem exits the Source. In the example the copy customers will need a random number of copies between 1 and 1000. To implement this, you would modify the Exit Trigger of the Source as follows:

setitemtype(item, bernoulli(60,1,2));  if(getitemtype(item)==2)  setlabel(item, "numOfCopies", duniform(1,1000));

As described previously, the setitemtype command sets the itemtype of the item to a 60/40 split between 1 and 2. Now we add an "if statement". This if statement basically says: if the itemtype of the exiting flowitem is 2 (it is a copy customer), then set the value of the flowitem's label named "numOfCopies" to a random number between 1 and 1000. The setlabel command sets a label value and takes 3 parameters. The first parameter is the object whose label we want to set (item, or the flowitem that is exiting). The second parameter is the name of the label ("numOfCopies"). This parameter needs to be in quotes since it is a string parameter.

The third parameter is the value to set the label to (duniform(1,1000)). The duniform command returns a value from a discrete uniform distribution. It takes 2 parameters, namely the minimum and maximum value, and returns a random number between those two values, uniformly distributed, meaning every value between the min and max is just as likely to be returned as any other value between the min and max. The "discrete" part means that the command will only return 1,2,3, etc, as opposed to the uniform() command, which may return values like 1.5 or 2.5. Since there will never be a customer that needs 1.5 copies made, we use the duniform() command.

Note that by adding the "numOfCopies" label in the Flowitem Bin, every flowitem that is created from that flowitem class will have that "numOfCopies" label on it. Even package customers will have that label, but our logic will simply not look at the label if it is a package customer.

Now that we have set up our label and set its initial value, we can define logic to make decisions based on the value of that label in the model. For a copy customer, for example, we can change the service time based on the number of copies that the customer needs. For each copy customer, the service time can be a base of 5 minutes as before, plus an additional 5 seconds for each copy that needs to be made. To make this change, you would again go to the Processor's Process Time field and change it to the following:

if(getitemtype(item)==1)  return 3;  else return 5 + (getlabel(item, "numOfCopies")*(5.0/60.0));

As before we use an if statement to give itemtype 1 (package customers) a service time of 3 minutes. In the else portion (copy customers), though, we return the expression: 5 + (getlabel(item, "numOfCopies")*(5.0/60.0)). This is the base service time of 5 minutes plus the number of copies that the customer needs (getlabel(item, "numOfCopies")) times five seconds (5.0/60.0). Remember that we have defined our model in minutes, so if one FlexSim time unit is equal to one minute, then five seconds is equal to 5/60 minutes or time units.

Note on the division operator: In the above example I use the expression 5.0/60.0 instead of 5/60. It is important to make this distinction because C++ sees the two division expressions differently. With 5/60, C++ sees this as the integer 5 divided by the integer 60. Thus, an integer divided by an integer must also be an integer, or 0. With 5.0/60.0, however, C++ sees it as the division of two floating point numbers, and thus the result is a fraction between 0 and 1. On the other hand, FlexScript, which is not strongly typed like C++, actually interprets the expression 5/60 as the division of 2 floating point numbers, meaning you would be fine using 5/60 in FlexScript. However, in the few situations such as this where FlexScript's implementation deviates from the C++ implementation, we encourage you to write code that is cross-compatible with FlexScript and C++, and thus the correct expression would be 5.0/60.0. For more information on integer vs. floating point division, refer to the topic on writing logic in FlexSim.

So again, just as with the itemtype value, we can use labels to store data on flowitems (or objects), and then we can access that data to make decisions in the model.

flexsim users manual
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.



paul.t contributed to this article


FlexSim 2016.1