Simulating a statechart model means to execute it, raise events manually, have time-based and other events being triggered automatically, and observe the model’s behavior.
You can run multiple state machines in parallel and even multiple instances of the same state machine.
An introduction to simulation is given in section "Simulating the light switch model".
You have several options to start a statechart simulation.
The most direct way is to start the simulation based on the statechart model file.
Selecting Run As → Statechart Simulation in the context menu
In order to re-run the simulation you have most recently executed, simply
[Ctrl+F11]on the keyboard
To be exact, this operation does not necessarily re-run the last
simulation, but rather the last executed
launch. So if, for example, you first run a statechart simulation followed by running a Java program, then upon pressing
[Ctrl+F11] that Java program is executed once again, not the statechart simulation.
Let’s consider a scenario where you want to execute a simulation that you have run before, but not as the most recently executed launch. So you cannot use the procedure described in section "Repeating the last simulation".
However, as long as you haven’t launched too many other programs in between, chances are good to find your simulation in the history.
Try the following:
When a statechart is simulated for the first time, a launch configuration is automatically created. A launch configuration describes the parameters used for a particular launch. In case of a statechart simulation, it describes which statechart is to be simulated and the simulation mode (event-driven or cycle-based). For details on how to create and modify a launch configuration, see section "Configuring a simulation".
To execute an existing launch configuration, proceed as follows:
The SC Simulation perspective provides selected views that are most useful when running a statechart simulation.
When a simulation starts, the perspective usually changes to the SC Simulation perspective. If this doesn’t happen, you can manually engage the SC Simulation perspective as follows:
Alternatively, you can do the following:
By default, the SC Simulation perspective shows the following views:
The SC Simulation perspective also includes the statechart editor. In a running simulation, the statechart editor highlights active states by coloring their backgrounds.
When a transition is taken, the transition arc leading from the source state to the target state flashes briefly in the transition highlighting color. After that, the target state becomes active and changes its background to the state highlighting color. The source state’s background color becomes normal again.
The SC Simulation perspective
The Simulation view is used to manually raise events and to inspect and modify variables of a running simulation. By default, that view is located on the right-hand side of the SC Simulation perspective, see figure "Simulation view" for an example.
The Simulation view groups events and variables by their interfaces. The unnamed interface appears as default in the interface list. Click on the small triangle left from an interface’s name to show or hide that interface’s contents, i.e., events and variables.
The simulation view also displays time events, provided the statechart uses time constructs like after or every. Press or release the "show time events" button to toggle between displaying and not displaying time events. You can click on a time event to raise it, i.e., you don’t have to wait for 24 hours to elapse in real time until the "after 24 * 60 * 60 s" transition fires.
You can have multiple simulation instances running at the same time. They may simulate the same or different statecharts. Use the simulation view’s drop-down menu to switch between simulation instances.
A digital clock right from the drop-down menu displays the virtual time elapsed in the simulation. It pauses while the simulation is suspended.
The Simulation view
Depending on your screen resolution and font size settings, you might not be able to spot the Simulation view by its name, because the tab containing it is quite narrow and might not provide enough space for displaying the title. Hover over the tabs to reveal their respective titles in a pop-up window.
Figure "The SC Simulation perspective" is demonstrating this: The user has hovered the mouse pointer over a tab that just displays the first letters of its title. However, a pop-up window right under the pointer shows the tab’s full title „Simulation”.
You can interact with a running simulation by manually raising events and by inspecting and modifying variables. You can do so at any point in time, but in most cases you will do it while the simulation „sits idle” at its active state and waits for an event to trigger a transition.
To raise an event, proceed as follows:
To inspect a variable’s value, proceed as follows:
Watch the displayed values change as the simulation progresses and actions in states or transitions are executed that modify the variables' contents.
To manually modify a variable’s value, proceed as follows:
[Enter]. The new value is assigned to the variable and replaces the former value.
Section "Creating and executing a launch configuration" describes how to start an existing launch configuration.
The present section describes how to create and configure a new launch configuration for a statechart simulation.
New_configurationto something sensible, e.g.,
Please note: Besides the Main tab described above, a statechart simulation launch configuration also has a tab named Common. This tab is a common standard to all types of launch configurations, and it is described in the Eclipse documentation.
In addition to creating new launch configurations, you can also duplicate or delete launch configurations in the Run configurations dialog. Right-click on a launch configuration and select Duplicate or Delete from the context menu.
YAKINDU Statechart Tools' Professional Edition includes two simulator features that increase your productivity considerably when debugging statecharts:
Throughout this chapter we will be using the light switch statechart as an example. It models a lamp which can be turned on and off and also supports various brightness values.
If you press the pressLightOn button, the lamp turns on at its lowest brightness value. If you operate pressLightOn repeatedly, each time the lamp becomes brighter until it reaches its maximum brightness. Pressing the pressLightOff button immediately turns off the light completely. The brightness can only be raised as long as it hasn’t yet reached its maximum value of five. After that, the guard condition disallows to raise it any further.
Here’s the light switch example’s statechart followed by its definition section:
The light switch sample statechart
interface: in event pressLightOn in event pressLightOff interface Lamp: var brightness: integer
Breakpoints allow for automatically suspending the simulation when a certain element of the state machine is activated. Optionally, a halting condition can be specified to better control the behavior of a breakpoint. Breakpoints can be set on transitions or states. If a state or transition with a breakpoint is reached, the simulation pauses, and the current state of variable values can be examined in the simulation view. It is possible to change variable values and to trigger events that will be raised when the simulation run is manually resumed.
To make use of breakpoints, the statechart simulation needs to be executed in debug mode. You have already seen how to start a statechart simulation in run mode. For using breakpoints and snapshots, however, the debug mode is needed.
Starting a simulation in debug mode
Setting a breakpoint
States and transitions with a breakpoint are labeled with a symbol. Figure "Breakpoints on transition and state" shows an example.
Breakpoints on transition and state
If the simulation runs into a state with a breakpoint, the state’s entry actions, if any, are executed. After that, execution of the state machine is suspended. The state is highlighted by a small green border.
Highlighting a suspended state
If the simulation runs into a transition with a breakpoint, execution of the state machine is suspended. The transition is highlighted by drawing the transition arc in green. The transition’s actions, if any, are executed when the state machine is resumed.
Highlighting a suspended transition
In order to continue from a breakpoint, you have two options:
The breakpoints view shows a list of all breakpoints. The respective breakpoint name identifies the state or transition in question. See figure "Breakpoints view" for an example.
You can use the breakpoints view for disabling, enabling, and removing breakpoints as well as for defining conditional breakpoints.
The Breakpoints view
A breakpoint is either enabled or disabled.
Figure "Breakpoints view" shows an enabled and a disabled breakpoint in the statechart editor and in the breakpoints view, respectively.
You can instruct the statechart simulation to skip all breakpoints by clicking on the button in the breakpoints view. The button will appear „pressed”, and while it is, the „skip breakpoints” functionality is engaged. That means, the simulation will not suspend at any breakpoint.
This is different from disabling all breakpoints, in that each breakpoint keeps its state of being enabled or disabled. Once you disengage the skip breakpoints functionality by clicking on the button again, the simulation will suspend again at enabled breakpoints and will not suspend at disabled breakpoints.
In order to remove some breakpoints, select these breakpoints in the breakpoints view, then click on the button. The selected breakpoints will be removed.
To remove all breakpoints, click on the button
A conditional breakpoint has an associated condition and suspends the simulation only if
In order to attach a condition to a breakpoint, proceed as follows:
[Ctrl+Space]. The expression you entered into the text field is validated automatically. In the example shown in figure "Breakpoints view", the transition suspends the simulation only if the variable brightness has a value of 4.
In the suspended status of a statechart simulation, you can change variable values using the simulation view. When continuing execution – see section Continuing the simulation – you can observe how your state machine behaves with those modified values.
If you click on an event’s name in the simulation view to raise that event in normal simulation, i.e., while execution isn’t suspended, the state machine processes that event and takes the corresponding transition, if any.
However, while the simulation is suspended, you can raise multiple events, without instant execution. Once execution resumes, the state machine’s behavior depends on its execution scheme:
Let’s have a look at an example. Please note that this example uses the cycle-based execution scheme! This is important, because in the the event-driven case the state machine’s behavior would be different.
Let’s consider that you want to press the "light on" and "light off" buttons at the same time and want to observe what happens. Figure "Raising multiple events simultaneously" shows the scenario:
Raising multiple events simultaneously 
Raising multiple events simultaneously 
Both events are raised and will be handled by the state machine during the next run-to-completion step. The latter will be performed as soon as the user clicks on the step-over button or the resume button .
Please note: Under the even-driven execution scheme, multiple events are never processed at the same time. Each event triggers a separate RTC.
Please note: While the execution is still suspended, you can „unraise” an already raised event by clicking on the event symbol a second time. The blue triangle will disappear, and upon continuation of the simulation the event will not be handled.
It is important to understand that in the event-driven execution scheme there is a queue of events, while in the cycle-based scheme there isn’t. If in the latter case multiple events occur simultaneously, they are all present at the same time, and the state machine has to figure out which event should trigger which transition. For example, what should the light switch state machine do, if it is in the LightOn state and both events, pressLightOn and pressLightOff, have been raised simultaneously?
The answer is transition priorities. The state machine always consults the active state’s transitions in a well-defined order, it fires the first matching transition it encounters, and it forgets about the rest. Transition priorities are specified in the corresponding property of the respective state, see figure "Transition priorities". You can change these priorities, and thus the order the transitions are being checked, by selecting a transition and moving it up or down by clicking on the respective button.
The first transition whose condition is fulfilled will be executed. Under the cycle-based execution scheme, all remaining events are quashed. In the light switch example as shown in figure "Transition priorities", the pressLightOff event would „win” and trigger a transition from the LightOn to the LightOff state, while the pressLightOff event would be discarded.
The snapshot feature allows to store and restore the state of a simulation run. A snapshot comprises all active states of the state machine as well as all variable values at the time of snapshot creation.
This feature is especially useful when testing complex state machines in which a number of steps need to be taken before reaching a certain situation you want to investigate. Using snapshots, you can store this desired situation once and then simply restore it anytime and as often as you like, without having to repeat all the tedious steps to reach that situation from scratch. Depending on the complexity of your use case, using snapshots can be a huge time-saver.
To create a snapshot of the current statechart simulation, proceed as follows:
A freshly taken snapshot
The snapshots view consists of two parts.
Inspecting snapshot details: variables overview [left], states overview [right]
To restore a snapshot for execution, proceed as follows:
Please note: When the semantics of the underlying state machine have been changed, it might not be possible to restore a snapshot, e.g., when the active state has been deleted.
The label of a snapshot can be changed as follows:
[Return], or click anywhere outside the editable field.