Evaluation Order for Outgoing Transitions

What Does Ordering Mean for Outgoing Transitions?

When multiple transitions originate from a single source (such as a state or junction), a Stateflow® chart must determine in which order to evaluate those transitions. Order of evaluation depends on:

    Note:   You can order transitions only within their type (inner, outer, or default). For more information, see Transition Flow Chart Types.

Outgoing transitions are assigned priority numbers based on order of evaluation. The lower the number, the higher the priority. The priority number appears on each outgoing transition.

Because evaluation order is a chart property, all outgoing transitions in the chart inherit the property setting. You cannot mix explicit and implicit ordering in the same Stateflow chart. However, you can mix charts with different ordering in the same Simulink® model.

Detection of Transition Shadowing

Transition shadowing occurs when a chart contains multiple unconditional transitions that originate from the same state or the same junction. To avoid transition shadowing, ensure that no more than one unconditional transition exists for each group of outgoing transitions from a state or junction.

You can control the behavior of the Stateflow diagnostic that detects transition shadowing. On the Diagnostics > Stateflow pane of the Configuration Parameters dialog box, set Transition shadowing to none, warning, or error. For information about other diagnostics, see Diagnostics Pane: Stateflow.

Explicit Ordering of Outgoing Transitions

By default, a Stateflow chart orders outgoing transitions explicitly based on evaluation priorities you set.

How Explicit Ordering Works

When you open a new Stateflow chart, all outgoing transitions from a source are automatically numbered in the order you create them, starting with the next available number for the source.

You can change the order of outgoing transitions by explicitly renumbering them. When you change a transition number, the Stateflow chart automatically renumbers the other outgoing transitions for the source by preserving their relative order. This behavior is consistent with the renumbering rules for Simulink ports.

For example, if you have a source with five outgoing transitions, changing transition 4 to 2 results in the automatic renumbering shown.

Automatic Renumbering of Transitions During Explicit Reordering

Order Transitions Explicitly

To use explicit ordering for transitions, perform these tasks:

  1. Enable Explicit Ordering at the Chart Level

  2. Set Evaluation Order for Transitions Individually

Enable Explicit Ordering at the Chart Level.  To enable explicit ordering for transitions:

  1. Right-click inside the top level of a chart and select Properties from the context menu.

    The Chart properties dialog box appears.

  2. Select the User specified state/transition execution order check box.

  3. Click OK.

Set Evaluation Order for Transitions Individually.  

  1. Right-click a transition and select Execution Order.

      Note:   If you select Execution Order while the chart is in implicit ordering mode, the only option available is Enable user-specified execution order for this chart. This option opens the Chart properties dialog box where you can switch to explicit ordering mode, as described in Order Transitions Explicitly.

    A context menu of available transition numbers appears, with a check mark next to the current number for this transition.

  2. Select the new transition number.

    The chart automatically renumbers the other transitions for the source by preserving the relative transition order.

  3. Repeat this procedure to renumber other transitions as needed.

Another way to access the transition order number is through the properties dialog box.

  1. Right-click a transition and select Properties.

    The properties dialog box for the transition appears.

  2. Click in the Execution order box.

    A drop-down list of valid transition numbers appears.

  3. Select the new transition number and click Apply.

      Note:   If explicit ordering mode is enabled, the chart assigns the new number to the current transition and automatically renumbers the other transitions. If the chart is in implicit ordering mode, an error dialog box appears and the old number is retained.

Implicit Ordering of Outgoing Transitions

How Implicit Ordering Works

For C charts in implicit ordering mode, a Stateflow chart evaluates a group of outgoing transitions from a single source based on these factors (in descending order of priority):

  1. Hierarchy (see Order by Hierarchy)

  2. Label (see Order by Label)

  3. Angular surface position of transition source (see Order by Angular Position of Source)

    Note:   Implicit ordering creates a dependency between design layout and evaluation priority. When you rearrange transitions in your chart, you can accidentally change order of evaluation and affect simulation results. For more control over your designs, use the default explicit ordering mode to set evaluation priorities.

Order by Hierarchy

A chart evaluates a group of outgoing transitions in an order based on the hierarchical level of the parent of each transition. The parent of a transition is the lowest level or innermost object in the Stateflow hierarchy that contains all parts of the transition, including any source state or junction and the endpoint object. For a group of outgoing transitions from a single source, the transition whose parent is at a higher hierarchical level than the parents of all other outgoing transitions is first in testing order, and so on.

Example of Ordering by Hierarchy.  

  • The parent of the transition from state A1 to state B is the chart.

  • The parent of the transition from state A1 to state A2 is the state A.

  • An event occurs while state A1 is active.

Because the chart is at a higher level in the hierarchy than state A, the transition from state A1 to state B takes precedence over the transition from state A1 to state A2.

Order by Label

A chart evaluates a group of outgoing transitions with equal hierarchical priority based on the labels, in the following order of precedence:

  1. Labels with events and conditions

  2. Labels with events

  3. Labels with conditions

  4. No label

Order by Angular Position of Source

A chart evaluates a group of outgoing transitions with equal hierarchical and label priority based on angular position on the surface of the source object. The transition with the smallest clock position has the highest priority. For example, a transition with a 2 o'clock source position has a higher priority than a transition with a 4 o'clock source position. A transition with a 12 o'clock source position has the lowest priority.

    Note:   These evaluations proceed in a clockwise direction around the source object.

Example of Angular Ordering for a Source State.  

  • For each outgoing transition from state A, the parent is the chart and the label contains a condition. Therefore, the outgoing transitions have equal hierarchical and label priority.

  • The conditions [C_one == 1] and [C_two == 2] are false, and the condition [C_three == 3] is true.

The chart evaluates the outgoing transitions from state A in this order.

PhaseChart evaluates transition to...Condition is...Transition occurs?
1State BFalseNo
2State CFalseNo
3State DTrueYes

Example of Angular Ordering for a Source Junction.  

  • For each outgoing transition from the junction, the parent is the chart and the label contains a condition. Therefore, the outgoing transitions have equal hierarchical and label priority.

  • The conditions [C_one == 1] and [C_two == 2] are false, and the conditions [C_three == 3] and [C_four == 4] are true.

  • The junction source point for the transition to state E is exactly 12 o'clock.

The chart evaluates the outgoing transitions from the junction in this order.

PhaseChart evaluates transition to...Condition is...Transition occurs?
1State BFalseNo
2State CFalseNo
3State DTrueYes

Since the transition to state D occurs, the chart does not evaluate the transition to state E.

Using Implicit Ordering for Transitions

To use implicit ordering for transitions in a C chart, follow these steps:

  1. Right-click inside the top level of the chart and select Properties from the context menu.

  2. In the Chart properties dialog box, clear the User specified state/transition execution order check box.

  3. Click OK.

What Happens When You Switch Between Explicit and Implicit Ordering

If you switch to implicit ordering mode in a C chart after explicitly ordering transitions, the transition order resets to follow the implicit rules. Similarly, if you switch back to explicit ordering mode, without changing the chart, you can restore the previous explicit transition order. All existing transitions in a chart retain their current order numbers until you explicitly change them.

    Note:   If you change back to explicit ordering after modifying the chart, you might not be able to restore the previous explicit transition order.

Transition Testing Order in Multilevel State Hierarchy

How Multilevel Transition Testing Order Works

By default, charts use explicit ordering for transitions. In this mode, you have explicit control over the testing priority, as described in Explicit Ordering of Outgoing Transitions.

If you use implicit ordering for transitions, the following testing order applies. For each group of transitions that originate from the same state, tiebreaking criteria apply in this order: hierarchy, label, and angular position.

Testing OrderChart ActionOrder by HierarchyOrder by LabelOrder by Angular Position
1

Tests transitions that originate from the highest-level active state (superstate).

  1. Outer transitions

  2. Inner transitions

  1. Events and conditions

  2. Events

  3. Conditions

  4. No label

The transition with the smallest clock position has the highest priority.

A transition with a 12 o'clock source position has the lowest priority.

2

Tests transitions that originate from the next lower-level active state.

  1. Outer transitions that cross the border of the highest-level active state (superstate)

  2. Outer transitions that stay within the parent of the state

  3. Inner transitions

3

Repeats step 2 until transition testing is complete.

The following chart shows the behavior of multilevel transition testing. Assume that the Super1.Sub1.Subsub1 state is active.

Because the chart uses implicit ordering, the following transition testing order applies:

This priority... Applies to the label...For this transition...
1[a < 0]Super1 to Super2.B
2[i > 0]Super1 to Super1.Sub1
3[b > 0]Super1.Sub1 to Super2.A
4[i < 0]Super1.Sub1 to Super1
5[c > 0]Super1.Sub1.Subsub1 to Super2.A
6[d > 5]Super1.Sub1.Subsub1 to Super1.Sub2
7[c < 0]Super1.Sub1.Subsub1 to Super1.Sub1.Subsub2

Example Model with Multilevel Transition Testing

Suppose that you open the sf_debouncer model and reach the point in the simulation where the Debounce.On state is active.

Because the chart uses implicit ordering, the following transition testing order applies:

This priority... Applies to the label...For this transition...
1after(0.3, sec)Debounce to Off.Fault
2after(0.1, sec)Debounce.On to On
3[sw < 0]Debounce.On to Debounce.Off

Now suppose that the transition from Debounce.On to Debounce.Off occurs.

Because the chart uses implicit ordering, the following transition testing order applies:

This priority... Applies to the label...For this transition...
1after(0.3, sec)Debounce to Off.Fault
2after(0.1, sec)Debounce.Off to Off
3[sw > 0]Debounce.Off to Debounce.On

For more information on how this model works, see Key Behaviors of Debouncer Chart.

Was this topic helpful?