Figure 6.9 shows how a state diagram can be optimized using an exit action. The original state diagram has subdiagrams that are structurally isomorphic to Subdiagram 1 and Subdiagram 2. Theorem 6.6.1 gives conditions for forming exit actions. Note that the conditions used in the
Figure 6.9: An optimization of a state diagram using an exit action
theorem were denoted byc4 andc5 earlier in this chapter. Definitions 6.3.3 and 6.3.4 are also needed.
Theorem 6.6.1 For a plain state diagramG, exit actions can be added to each subdiagramG0, structurally isomorphic to either Subdiagram 1 or Subdiagram 2, without violating Rule 6.1.1 if and only ifc4holds. Exit actions can be added toG0satisfying Rules 6.1.1 and 6.1.2 if and only if
bothc4andc5hold.
Leta1, . . . , am be the longest sequence of normal actions as described inc4. These actions are all moved tos1as exit actions and removed from everys00 ∈Sn(s1). Consider a statesa ∈ Sn(s1)
for whichc5 does not hold. In that case, a new statesn is created, actionsa1, . . . am are copied into it, and every entering transition(si, ej, sa), si 6=s1ofsais changed to entersn, i.e. transition
(si, ej, sn)is created. In addition, an automatic transition (sn, N U LL, sa) is added. Finally, if
s00 ∈Sn(s1)has no actions left aftera1, . . . am have been moved tos1, and there is an automatic transition, say(s00, N U LL, sm), thens00and(s00, N U LL, sm)are removed and all transitions en- terings00are changed to entersm.
Proof 6.6.1 First we show that conditionsc4 andc5 are needed. Ifc4 is not true, there are two states, saysf andsg, inSn(s1)so that the first actions of their action sequences differ. It is then impossible to form an exit action for states1without violating Rule 6.1.1. Suppose then that there existsf ∈ Sn(s1)andsp ∈ S so that sp =6 s1and there is a transition(sp, ep0, sf), e0p ∈ E in the original state diagram. An exit action can then be formed without violating Rule 6.1.1 only by copying the actions of statesf and either moving them to statesp or to a new state that is created between statessp andsf. In both cases, Rule 6.1.2 would be violated. We still need to show that the conditions16∈Sn(s1)of Definition 6.3.3 is required. Ifs1∈Sn(s1), then states1would also have actionsa1, . . . , am, and there would be a self transition, say(s1, f, s1). This means that the actionsa1, . . . , amare executed before eventf is received. The Rule 6.1.1 requires then that if the exit actions are formed, then the actionsa1, . . . , ammust also remain as normal actions ins1. In that case, the state diagram would not allow the following path, consisting of actions and events, any longer:a1, . . . , am, f, a1, . . . , am, e, a1, . . . , am.
Next we will show that the conditionsc4 andc5 are sufficient. No entering transition of states1 has any effect on forming exit actions unless it is leaving states1. Leaving transitions of states that do not belong toSn(s1)and which are entered from states that belong toSn(s1)by at least one transition (e.g., states3in the case of Subdiagram 2) have no influence on forming exit actions
for states1. The same applies to the transitions that enter these states, except possibly the leaving transitions of states1or state s2. If c5 holds, all entering transitions of states in Sn(s1)leave state s1. Thus, leaving transitions of any s0 ∈ Sn(s1)cannot then enter any state in Sn(s1) (which possibly will be removed). Hence, such transitions are meaningless when forming exit actions for states1. Ifc5 does not hold and there is a transition(s0, e0, s00), s0, s00 ∈Sn(s1), then actionsa1, . . . , amare executed twice when traversing along a path forms1tos00using(s0, e0, s00). That requires coping actions a1, . . . , am and hence violating Rule 6.1.2. Finally, conditionc4 guarantees that all leaving transitions of states1enter a state, actions of which can be moved to states1. Other kind of leaving transitions of states1would make it impossible to form an exit action for states1without violating Rule 6.1.1.
At the beginning of this chapter it was concluded that optimization algorithms replace only those normal actions that run to completion without interruption of any event; actions to be replaced are from states that have an automatic transition as the only leaving transition. Even though all states inSn(s1)are considered in Theorem 6.6.1, it is required that one of them belongs to a subdiagram that is structurally isomorphic to either Subdiagram 1 or Subdiagram 2. Lets0 ∈Sn(s1)be such a state. Then the actionsa1, . . . , am to be moved tos1are always non-interruptible ones, since either there are still normal actions ins0, which are automatically executed after am, or there is an automatic transition leading out ofs0, again causing some actions to be automatically executed afteram. This implies thata1, . . . , am indeed need to run to completion without interruption of any event. Non-interruptible actions may appear also in other kinds of state diagrams. Figure 6.10, for example, shows a state diagram in which actionb1cannot be interrupted by any event and can hence be replaced by an exit action. This transformation combines information and hence clarifies the contents of the state diagram. However, it does not change the size of the state diagram. Hence, such transformations are recommended only if adding the exit action combines information, (i.e., there are at least two states whose actions are replaced by the exit action. The next theorem relaxes the rules for adding exit actions.
Theorem 6.6.2 For a plain state diagramG, exit actions can be added to each subdiagram G0 without violating Rule 6.1.1 if and only ifc7holds. Exit actions can be added toG0satisfying both
Rules 6.1.1 and 6.1.2 if and only if bothc7andc8hold
The proof of the Theorem 6.6.2 is similar to Proof 6.6.1. Note that Theorem 6.6.2 still guarantees that actionsa1, . . . am, m ≥ 1, cannot be interrupted by any event, and can hence be moved to sas exit actions. It is also worth noting that rules for forming internal and entry actions cannot be loosened similarly; they can be added only for subdiagrams that are structurally isomorphic to either Subdiagram 1 or Subdiagram 2.