Updating Diagrams
Overview
This step involves replacing functionality for the start and stop racing actions. When delegating for an action, it is important to keep in mind that Behavior Execution Engine will ignore any of the delegated action’s owned actions. For our model, this means the implementation details of the Racer diagram are no longer necessary, and can be deleted.
Prerequisites
| Prerequisite | Description |
|---|---|
| Behavior Execution Engine Installation | You must have installed Behavior Execution Engine. |
| Tutorial Project | You must start this section with the Behavior Execution Engine simulation project from the previous section. |
Instructions
Updating the Diagrams
- Open the
Racerdiagram. - Delete the
updateRaceFinishedassignment action that thestopRacingaction owns. - Delete the
Racerdiagram.
Updating the Tortoise Diagram
The tortoise diagram for this tutorial will turn out very similar to the previous model, with one significant exception. No longer are the Looping state and related guards necessary to handle the evaluation of the distance covered. Instead, you can use a simple –change event trigger—(link) to trigger upon the conditional satisfaction of “when my distance covered is greater than the race distance” during the simulation. Using a change event trigger combined with comparative operators enables us to implement more dynamically updating event detection that can precisely determine when the tortoise crosses the threshold (based on the race distance and running speed).
- Open the
Tortoisediagram. - Delete the
Loopingstate. -
Draw a transition from
Running the racetoFinished the raceand give it the namerunning to finished.-
Create a trigger action.
- Set the trigger kind for the Trigger Expression to be
when. - Set the expression to be
distanceCovered >= race.distance.
- Set the trigger kind for the Trigger Expression to be
- Set the effect action to
Racer::stopRacing.
-
Create a trigger action.
Updated Tortoise Diagram
Now, when you finish the backing code later in the tutorial, you will have created a more efficient and precise means of asking Behavior Execution Engine if the tortoise has finished the race. Notably, even though the mechanism for moving through the race has changed, the determination of winning or losing did not.
Updating the Hare Diagram
The majority of the Hare’s behaviors will also stay the same. However, the having the value for the distance covered as a delegated ScalarValue results in a more streamlined interior sequence for “Running the Race”. We are going to change how the hare determines if he wants to rest. For this iteration, the hare is more cautious and wants to get to the halfway point in the race before considering if he wants to rest or not. Only then will he look back to see if he is ahead of the tortoise.
- Open the
HareDiagram. - Delete the
Loopingstate. -
Draw a transition from
RunningtoConsidering restingand give it the namerunning to considering.-
Create a trigger action.
- Set the trigger kind for the Trigger Expression to be
when. - Set the expression to be
distanceCovered >= race.distance / 2.
- Set the trigger kind for the Trigger Expression to be
-
Create a trigger action.
- Set the guard to be
distanceCovered > tortoise.distanceCovered. - Delete the
updateIsNappingassignment action that thestartNappingaction owns. - Delete the
updateIsNappingassignment action that thestopNappingaction owns. - Delete the
updateHasTakenANapassignment action that thestopNappingaction owns. - Create a comment owned by the
Harepart with the bodyDelegated Actions. - Draw an annotation arrow from
Delegated ActionstostartNappingand tostopNapping.
Initial Updates to the Hare Diagram
Annotations are not necessary for execution, but they do make for a good marker for other modelers to visually understand that they should not be altering the annotated elements.
Updating the Use Case Diagram to Reflect Changes
Having changed your part definitions, you now need to update the parts accordingly. Now that we are not hindered by checking the distance covered every second and polluting the console log, let’s also give the parts more interesting and realistic values to use for the simulation. Since we will be demonstrating working with units in the delegate module, we can play around with varying unit types.
- Open the Use Case diagram.
- Delete the orphaned
checkInRateredefined attribute fromanimalRace. - Change the
distanceattribute on the partanimalRaceto5 [km]. - Change the
topSpeedattribute on the parttheHareto11 [‘m/s’]. - Change the
restDurationattribute on the parttheHareto90 [min]. - Change the
startingDelayattribute on the parttheHareto20 [min].
Updated Instance Diagram
Now that you have updated the instances, you are ready to move to the next stage and start playing with some code. You may have noticed that these steps mostly removed elements from the model including the value expression for the racer’s distance covered. You are going to handle the implementation of that ScalarValue for the racers in the delegate code; therefore, you can leave value undefined.
Next Section >