    Next: 2.5.12 An example of Up: 2.5 More Examples Previous: 2.5.10 An example of   Contents

## 2.5.11 An example of ITF and OTF transition priorities

The following is a model (prio1_b.des) that tests the ITF (Inner Transition First) and OTF (Outer Transition First) transition priorities:

```STATECHART:
A [DS] [ITF]
A1 [DS] [OTF]
A11 [DS] [RTO]

TRANSITION:
S: A
N: A
E: e
O: [DUMP("transition from A")]

TRANSITION:
S: A.A1
N: A.A1
E: e
O: [DUMP("transition from A.A1")]

TRANSITION:
S: A.A1.A11
N: A.A1.A11
E: e
O: [DUMP("transition from A.A1.A11")]
```

The following is the simulation result of prio1_b.des:

```['A.A1.A11'] > e
transition from A.A1
['A.A1.A11'] > exit
```

In this model, a conflict on event e is deliberately created. All the three transitions are able to handle event e when it is received: one transition from A, one from A.A1 and the other from A.A1.A11. State A is set to be ITF, so the transition from A.A1 and the transition from A.A1.A11 have higher total priority than the transition from A. State A.A1 is set to be OTF, so the transition from A.A1 has higher total priority than the transition from A.A1.A11. (The OTF property of A.A1 does not affect state A.) At last, state A.A1.A11 is set to be RTO. This means transitions within its scope has a reverse ordering than its parent state, so the transition ordering of this state is equivalent to ITF. However, there is only one transition within its scope, so this property does not affect the result.

As a result, the second transition has the highest total priority. It is triggered when event e is received. Its output prints out the state where it is from: A.A1.

If a top-level state (like A in the above example) has not explicitly specified its transition priority, it is set to OTF by default. This behavior can be changed by reverting the global flag InnerTransitionFirst under the OPTIONS descriptor. More about global options are discussed later.

Because of this global option always presents, the behavior of a component is protected whether it is imported into an importation state with ITF property or an importation state with OTF property. The following model (prio1_a.des) imports prio1_b.des:

```IMPORTATION:
b = prio1_b.des

STATECHART:
A [DS] [OTF] [b]
B [ITF]
B1 [RTO] [DS]
B11 [DS] [b]

TRANSITION:
S: A
N: B
E: e
O: [DUMP("A-B")]

TRANSITION:
S: B
N: A
E: e
O: [DUMP("B-A")]
```

The simulation result is as following:

```['A.A.A1.A11'] > e
A-B
['B.B1.B2.A.A1.A11'] > e
transition from A.A1
['B.B1.B2.A.A1.A11'] > exit
```

In this example, two more transitions participate in the conflict of event e. The A state of prio1_a.des is set to be OTF, so the first transition in the main model has higher priority than the b component in its state A. This results in the first transition (A-B) in the main model being triggered when event e is received for the first time. In state B, the transition has lower total priority than the transitions in the component imported into B.B1.B11. As a result, when event e is received for the second time, the transition in the component is triggered (a self-loop on state B.B1.B2.A.A1.A11).    Next: 2.5.12 An example of Up: 2.5 More Examples Previous: 2.5.10 An example of   Contents
Thomas Huining Feng
2004-04-05