Activity Diagram Solver Examples
In this topic we run through some simple examples of where and how to apply Solvers in Activity diagram simulations. This includes using scripts in Action Effects, as well as in ControlFlow Guards. The images in this topic show Octave Solver examples; however, the same script can be used for MATLAB by replacing the Octave Solver with the MATLAB Solver.
Initializing the Solver
The script to initialize a Solver in an Activity diagram can be placed in the Effect of an Action, usually the Effect of the first Action exiting the ActivityInitial.
Assigning Values and Executing Commands
To assign a value, use the octave.set() or matlab.set() functions. For Activity diagrams the function can be placed in the Effect of an Action.
When executing MATLAB or Octave commands using the .exec() function, the commands can again be placed in the Action's Effect.
For conditional branching in a StateMachine, the condition can be placed in the Guard of a ControlFlow and contain a script that calls any MATLAB or Octave function. For example:
To return the results from external function calls you use the Solver's .get() function. There are three key options for how the results are then delivered from the script to the user:
- Win32 display
The Trace() command is useful when initially writing and debugging a simulation, as it allows you to check the results of your script at different stages. The results are output in the Simulation window.
Octave and MATLAB have a strong emphasis on generating plots, as this is a key method of outputting results. To generate a plot you use the Solver's .exec() function to call a plot generation.
Holding the Plot
When executing a plot in a simulation, if the simulation is not paused the plot will only be briefly visible. For Activity diagrams there are two options for pausing the flow while the plot is being viewed:
- Using the uiwait function in Octave or MATLAB, setting it in the Effect of the Action. Here is an example using Octave:
- Set an Action of type AcceptEvent to pause simulation after the plot is generated, which requires a reference to an Activity Trigger to be set on the AcceptEvent. This can be created and referenced using the button, which displays the 'Select Trigger' dialog. Click on the
to create the Trigger.
To progress past the AcceptEvent you:
- Drag the Trigger (Resume) from the Browser onto the Simulation Events window
- Double-click on that transition
Using the Win32 Interface
When using the Win32 interface, broadly the steps to perform are:
- Create a Win32 dialog.
- Set a script line to open it.
- Get a value from a field in the dialog.
- Pass that value to the Solver.
- Use a button to trigger the plot.
These are the steps to configure a Win32 interface:
- Create a ‘Starter Win32 Model’ using the 'Create from Pattern' tab (Model Wizard) ( ).
- Change the name of the <<Win32 Screen Dialog>> to 'ScreenA'.
- Change the name of ‘Edit Control A’ to something more meaningful such as ‘finish’.
on State1 to add a call to open the dialog, in the Entry Operation's script:
To get a valid user input value, the user must click on the, so from the OK button you need to Broadcast an event for a Trigger to start the process. To receive the Trigger you set a Signal and a Transition to be triggered by that Broadcast.
See the steps to create and set the Trigger and Signal 'End', as shown in Holding the Plot earlier. In this case we are setting the same thing, but for a new Trigger called 'Plot'. This illustration is sending a BroadcastSignal(‘Plot’) using the OnClick Tagged Value on a button.
On the ControlFlow exiting StartSolver there is now an Action 'AcceptEvent'. This is set to be triggered as shown:
On the Properties window 'Trigger' tab you create a Trigger, set the Trigger-Type to 'Signal' and create a Signal for it. For more detail see the Win32 User Interface Simulation Help topic.
Theis configured in the same way as the OK button (with a Broadcast signal) and Trigger references are set on the AcceptEventCancel to use the 'cancel' Trigger/Signal.
Running the Simulation
To run the simulation:
- Select the Simulate ribbon
- Click on 'Run Simulation > Start'
When you enter a value and click on the, this returns: