Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Invoking modifiers using triggers and predicates.

STEM TOP BAR.gif

Back

The combination of modifiers, triggers, and predicates in STEM are used to dynamically modify some aspect of a scenario while it's running. As a motivating example, imagine a real world example of a pandemic flu outbreak. When an outbreak is detected (i.e., a some critical mass of new cases show up in hospitals), public health officials typically implement a "social distancing" policy in an attempt to curb the spread of the disease. This includes measures to reduce contacts between humans by for instance closing schools or work locations. Social distancing essentially reduces the transmission rate by some degree after an initial condition is met.

STEM allows you to use modifiers to change a scenario (while it's running) after a "predicate" (condition) is satisfied. The combination of a predicate and (any number) of modifiers to invoke are contained inside a Trigger, and the Trigger can be dragged into the scenario it's acting upon.

Step 1) First, use the STEM toolbar icon "New Trigger" to bring up the wizard used to define a new trigger (see Figure 1). You must give it a name (any name).

NewTrigger.png

Figure 1. Defining a new Trigger

Step 2) Now we need to define the Predicate representing the conditions to be satisfied for the trigger to "fire" (resulting in applying all modifiers that are part of the trigger). Use the STEM "New Predicate" toolbar icon which brings up the wizard used to define a new Predicate. Give it a name (any name).

NewPredicate.png

Figure 2. Defining a new Predicate

Step 3) Next, to set the condition to be satisfied for this Predicate, open up the Predicate you just created, right-click on it and select "New Child". In the sub-menu that pops up, there are a number of options, but in this case we will simply define that the predicate is satisfied after a certain amount of time has progressed in the simulation. Select "Elapsed Time Test".

CreatePredicateCondition.png

Figure 3. Defining a new Predicate

Step 4) A child will be created on your predicate, and if you open the Properties view (if it is not already open) and select the child, you can fill in the actual number of days you want to use (see Figure 4). In this case we determine that the predicate is true (satisfied) after 15 days of simulated time.

FillingPredicateValue.png

Figure 4. Using the Properties view to fill in the actual number of days into the simulation that the trigger is satisfied.

Step 5) Create a modifier to be invoked by the trigger. You can follow the instructions in the tutorial on Experiments to learn how to create a modifier. For triggers however, you want to select a "single-value" type modifier (not range) as in the screen shot in Figure 5.

NewModifierForTrigger.png

Step 6) Drag that modifier and your new predicate into the trigger you created. In Figure 6, we show a predicate and modifier inside a trigger.

Trigger.png

Figure 6. A trigger with a predicate and modifier

Step 7) Finally, you can drag the trigger into your Scenario (Figure 6). In this case, when the scenario containing the trigger is running, it will evaluate the predicate associated with the scenario in each step of the simulation. If the predicate is satisfied, it will invoke all the modifiers part of the trigger. So in this case, if the modifier reduces the transmission rate of the disease by 20 %, that will happen after 15 days of simulated time.

ScenarioWithTrigger.png

Figure 7. A Scenario containing our newly defined trigger

Back to the top