article

Paul Toone avatar image
0 Likes"
Paul Toone posted

Key Concepts About Event-Listening   

Events are the most common way to link to a process flow from a simulation model. For example, you can set an activity in your process flow to listen for an item to enter a processor. Every time an item enters the processor, it would then kick off a series of activities that perform custom logic, perhaps to dynamically determine the processing time for that type of item. If you were not using a process flow to do this, you'd need to manually write code for the OnEntry trigger of the processor instead.

The two activities that can listen for events are:

  • Event-Triggered Source - This activity will listen for a specific event to occur in the simulation model. When that event occurs, it will create one or more new tokens and send the tokens to the next activity in the process flow. You should use an event-triggered source if you want the triggering event to initiate the process flow. See Event-Triggered Source for more information about this activity.
  • Wait for Event - After this activity receives a token, it will hold the token while it listens for a specific event to occur in the simulation model (or in the process flow). When that event occurs, it will release the token to the next activity in the process flow. If needed, you can also make the Wait for Event act like a Decide activity. In other words, the Wait for Event activity could possibly send the token to different activities next based on certain conditions in the simulation model. See Wait for Event for more information about this activity.

This topic will discuss event-listening key concepts as they relate to process flow in more detail. It includes the following topics:

Requirements for Event Listening

The event-listening activities (the Event-Triggered Source and the Wait for Event activity) have two properties that are required in order to listen to events:

  1. Object - You need to determine which object the activity should listen to. An activity could possibly listen to:
    • An object in the model.
    • An activity in the Process Flow.
    • The current instance object (See Process Flow Instances for more information.)
    • A group of objects. In this case, the activity will listen to the defined event on all members of the group.

  2. Event - You need to determine which event on that object will trigger the activity. Be aware that you can listen to more than one event on an object. There are two different types of events:
    • Standard Events - Normal events that are fired during the simulation. such as an item entering a fixed resource in the simulation model or a token entering an activity in a process flow.

  3. Value Change Events - Events that happen when some value in the model (usually a statistical value) changes.

See Event Types for more information about the two different types of events and the properties associated with them.

Sometimes the Object and Event Might Be the Same

In some cases, the event will be the same as the object. For example, you may connect directly to a node in the tree such as a user command (do this by pressing the button and then clicking on the Code field in the user command's properties window). In this case the Object field will be a reference to the node, while the Event field will say Same as Object.

Setting up Event-Listening on an Activity

To set up event-listening on an activity:

  1. Make sure that the object you want to listen to (such as a processor or another activity) has been added to your simulation model or process flow.
  2. You might also want to split the center pane so that it is split between the simulation model and the process flow tab. (See Navigating in Process Flow - Rearranging Process Flow Tabs for more information.)
  3. With the process flow tab active, add a Wait for Event or Event-Triggered Soruce to the process flow.
  4. Click the activity's icon to open its properties, as shown in the following image:

  5. First, you'll select the object that the activity will listen to. Next to the Object box, click the Sampler button to enter sampling mode.
  6. Click the object you want to listen to. This will open a menu that will list all of the possible events available for that object.
  7. Select the appropriate event from the menu. That event will now appear in the Event box in the activity's properties.
  8. Based on the type of event you selected, some additional properties will now be available in the activity's properties. See Event Types and Related Properties for more information about these properties.

The following image shows an example of this step-by-step process using an Event-Triggered Source that will listen for the On Setup Finish event for a processor.

Shortcut for Adding Events
There is a faster way to add an event to an Event-Triggered Source or Wait for Event activity. When you first add one of those activities to your process flow, you'll notice that an Exclamation icon next to the activitiy. If you click on this icon, you will enter sampling mode. In sampling mode, you can click object that you want the activity to listen to. This shortcut is the same as clicking the Sampler button in steps 5 and 6.

Listening to Events on a Flowitem or Token

It's often useful to listen to events on flowitems or tokens. Perhaps the path of a flowitem or token is not known or you want to reduce the number of events to listen to.

Flowitems have the following events:

  • On Entering - Fired when the flowitem enters a fixed resource or is loaded by a task executer object.
  • On Exiting - Fired when the flowitem exits a fixed resource or is unloaded by a task executer object.

Tokens have the following events:

  • On Entering - Fired when the token enters an activity.
  • On Exiting - Fired when the token exits an activity.
  • On Manual Release - Fired when the token is manually released from an activity using the releasetoken() command.
  • On Asset Allocated - Fired when the token allocates a shared asset. This may be acquiring a resource, entering a zone being pushed onto a list or creating a backorder when pulling from a list.
  • On Asset Deallocated - Fired when the token deallocates a shared asset. This may be releasing a resource, exiting a zone being pulled from a list, or completing a backorder.
  • On Label Value Change Fired when a label value changes. This is only available if a label is stored as a Tracked Variable. See Value Change Listening below for more information.

Listening for an event on a flowitem or token can be achieved through the following steps:

  1. Reference the flowitem/token - In order to listen to an event on a flowitem or token, you'll need to create a reference to it. This is most often done by storing a reference on a label through an Assign Labels or an Event-Triggered Source listening. You can also reference the flowitem/token through code. Flowitems can be easily referenced through the Create Object activity.
  2. Run the model - Run the model in order to get a flowitem or token that can be referenced. This can be ANY flowitem/token.
  3. Sample the flowitem/token - Use the or click on the sampler for the Object property to enter sample mode. Click on the flowitem/token and select the desired event to listen to. This will populate the Object and Event boxes.
  4. Update the object reference - When sampling a flowitem/token, the full path to that object will be displayed in the Object box. This path will not be valid when the model runs. Instead we want to use the referenced flowitem/token from step 1. If your reference is stored on a label then you can reference the label using the syntax Label: item

Value Change Listening

It can be useful to wait for a value on a label to change. This can be done by adding a Tracked Variable to a label and then listening to OnLabelValueChange. Once a token has a tracked variable set as one of its labels, click on the Event Sampler or and hover over the token to get the option of Token: On Label Value Change. For more information, see the Tracked Variables as Labels from the Assign Labels activity.

Event-Triggered Source
If using an Event-Triggered Source, there is no token entering the activity and the event listening is only set up on model reset, so you are not able to use an Event-Triggered Source to listen to token/flowitem events.

Examples of Event-Listening Scenarios

The following sections give examples of different scenarios in which you might listen for events.

Example 1 - Static Object Reference, OnExit Event

Imagine you have a single queue in your model and you want to run a process flow every time a flowitem leaves the queue. To build this scenario, you'd need to do the following:

  1. Build your simulation model, making sure to include the queue.
  2. Create a process flow. Make sure the process flow is a General type.
  3. Begin the process flow with an Event-Triggered Source activity.
  4. Now link the Event-Triggered Source to the queue. In Quick Properties, next to the Object box, click the Sampler button and select the queue in the simulation model.
  5. A menu will appear listing all the possible events for the queue. Select Queue1: On Exit.
  6. Build the rest of the logic of the process flow by adding more activities after the Event-Triggered Source.

When the simulation model runs, any time a flowitem leaves the queue, the Event-Triggered Source will create a new token and release it to the next downstream activity in the process flow.

Example 2 - Dynamic Object Reference (Instance Object), OnLoad Event

Imagine you want to create a task sequence for loading and unloading flowitems. Perhaps you want to build one task sequence that will then be used by several different operators at different workstations. The task sequence will begin when they load a flowitem. To build this scenario, you'd need to do the following:

  1. Build your simulation model, making sure to add at least two operators and some different processors (the workstations). Make sure that each processor is connected to an operator with a center port connection.
  2. Create a new process flow. Make sure the process flow is a Task Executer type.
  3. Begin the process flow with an Event-Triggered Source activity.
  4. In Quick Properties, leave the Object box set to current (No Instance). This setting will ensure that the object can change dynamically to be whatever operator is using the task sequence in a given instance.
  5. Next to the Event box, click the Sampler button and click one of the operators in the simulation model.
  6. A menu will appear listing all the possible events for the operator. Select On Load.
  7. Build the rest of the loading task sequence in the process flow by adding Load and Unload activities and any other tasks in between.
  8. Now attach the operators to the Task Executer process flow. Click on a blank space in the process flow to ensure nothing is selected.
  9. In Quick Properties, under Attached Objects, click the Sampler button and click one of the operators in the simulation model. Add all the other operators using this method until they are all attached to the process flow.
  10. Lastly, open the Properties dialog box for all the processors in the simulation model. In the Flow tab, check the Use Transport check box so that the processors will use the operators connected to their center port.

When the simulation model runs, the operators will use the task sequence in this process flow whenever their OnLoad command is called by a processor in the simulation model.

Example 3 - Object Group, OnExit Event

Imagine you have several queues in your model and you want an Event-Triggered Source to create a token any time a flowitem exits from any of the queues. You could possibly add them to a group and then listen to the entire group. To build this scenario, you'd need to do the following:

  1. Build your simulation model, making sure to include several queues.
  2. Right-click on one of the queues to open a menu. Point to Object Groups, then select Add to New Group. This will create a group called Group1 and assign the queue to that group.
  3. Now you'll add the other queues to this group. Right-click another queue to open a menu. Point to Object Groups, then select Group1. Repeat this step until you've added all the queues.
  4. Create a process flow. Make sure the process flow is a General type.
  5. Begin the process flow with an Event-Triggered Source activity.
  6. Now link the Event-Triggered Source to the group. In Quick Properties, next to the Object box, click the arrow to open a menu. Point to Group, then select Group1.
  7. Build the rest of the logic of the process flow by adding more activities after the Event-Triggered Source.
  8. Next to the Event box, click the Sampler button and click one of the queues in the simulation model.
  9. A menu will appear listing all the possible events for the queue. Select On Exit.
  10. Add the rest of the process flow activities as needed.

When the simulation model runs, the Event-Triggered Source will create a token any time a flowitem leaves the queues in the group.

Example 4 - Dynamic Object (Flowitem), OnExiting Event

Imagine you want to create a process flow that will listen for flowitems exiting any fixed resource. One problem you might encounter is that there might be multiple items in a fixed resource at the same time (such as a queue or a conveyor). You'll want to make sure it only releases the token that matches the flowitem it is associated with. You don't want to release the other tokens that are associated with flowitems that are still inside the queue or conveyor. To build this scenario, you'd need to do the following:

  1. Build your simulation model, starting with a source and making sure there is a conveyor somewhere downstream in the model.
  2. Create a new process flow. Make sure the process flow is a General type.
  3. Begin the process flow with an Event-Triggered Source activity. Now you'll change the settings so that the Event-Triggered Source will create a new token every time the source creates a flowitem in the simulation model.
  4. In Quick Properties, next to the Object box, click the Sampler button and select the source in the simulation model.
  5. A menu will appear listing all the possible events for the source. Select Source: On Creation.
  6. Now you'll assign each token a label named item that tracks the flowitem's unique ID. Notice that the Label Assignment table has now become available in Quick Properties. In the cell that is on the Created Item row underneath the Label Name column, type item. This will assign the token an item label that tracks the created item's ID.
  7. Add any other additional activities to your process flow as needed. Somewhere in the process flow, add a Wait for Event activity.
  8. In Quick Properties, in the Object box type Label: item. This setting will listen for the item label tokens and will track the flowitems that are associated with that label.
  9. Now make sure the Toolbox is open in the left pane and that the FlowItem Bin is expanded.
  10. In the Quick Properties for the Wait for Event activity, next to the Event box, click the Sampler button and click the Box in the FlowItem Bin. This will open a menu that will list all of the possible events available for flowitems.
  11. Select On Exiting from the menu. That event will now appear in the Event box in the activity's properties.
  12. Add the rest of the process flow activities as needed.

Now when a token enters the Wait for Event activity, it will only release the specific token that is associated with a specific flowitem.

flexsim users manualuser manuals
5 |100000

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

Article

Contributors

paul.t contributed to this article

Navigation

FlexSim 2016.1