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

  1. Open the Racer diagram.
  2. Delete the updateRaceFinished assignment action that the stopRacing action owns.
  3. Delete the Racer diagram.

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).

  1. Open the Tortoise diagram.
  2. Delete the Looping state.
  3. Draw a transition from Running the race to Finished the race and give it the name running to finished.
    1. Create a trigger action.
      1. Set the trigger kind for the Trigger Expression to be when.
      2. Set the expression to be distanceCovered >= race.distance.
    2. Set the effect action to Racer::stopRacing.

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.

  1. Open the Hare Diagram.
  2. Delete the Looping state.
  3. Draw a transition from Running to Considering resting and give it the name running to considering.
    1. Create a trigger action.
      1. Set the trigger kind for the Trigger Expression to be when.
      2. Set the expression to be distanceCovered >= race.distance / 2.
  4. Set the guard to be distanceCovered > tortoise.distanceCovered.
  5. Delete the updateIsNapping assignment action that the startNapping action owns.
  6. Delete the updateIsNapping assignment action that the stopNapping action owns.
  7. Delete the updateHasTakenANap assignment action that the stopNapping action owns.
  8. Create a comment owned by the Hare part with the body Delegated Actions.
  9. Draw an annotation arrow from Delegated Actions to startNapping and to stopNapping.

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.

  1. Open the Use Case diagram.
  2. Delete the orphaned checkInRate redefined attribute from animalRace.
  3. Change the distance attribute on the part animalRace to 5 [km].
  4. Change the topSpeed attribute on the part theHare to 11 [‘m/s’].
  5. Change the restDuration attribute on the part theHare to 90 [min].
  6. Change the startingDelay attribute on the part theHare to 20 [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 >