lecture 19 hierarchical state machines iii
play

Lecture 19: Hierarchical State Machines III 2015-01-29 Prof. Dr. - PowerPoint PPT Presentation

Software Design, Modelling and Analysis in UML Lecture 19: Hierarchical State Machines III 2015-01-29 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal 19 2015-01-29 main Albert-Ludwigs-Universit at Freiburg, Germany Contents


  1. Software Design, Modelling and Analysis in UML Lecture 19: Hierarchical State Machines III 2015-01-29 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal – 19 – 2015-01-29 – main – Albert-Ludwigs-Universit¨ at Freiburg, Germany

  2. Contents & Goals Last Lecture: • Initial and Final State • Composite State Semantics started This Lecture: • Educational Objectives: Capabilities for following tasks/questions. • What does this State Machine mean? What happens if I inject this event? • Can you please model the following behaviour. • What does this hierarchical State Machine mean? What may happen if I inject this event? • What is: AND-State, OR-State, pseudo-state, entry/exit/do, final state, . . . – 19 – 2015-01-29 – Sprelim – • Content: • Composite State Semantics cont’d • The Rest 2 /28

  3. Composite States (formalisation follows [Damm et al., 2003]) – 19 – 2015-01-29 – main – 3 /28

  4. A Partial Order on States The substate- (or child- ) relation induces a partial order on states : • top ≤ s , for all s ∈ S , • s ≤ s ′ , for all s ′ ∈ child ( s ) , • transitive, reflexive, antisymmetric, • s ′ ≤ s and s ′′ ≤ s implies s ′ ≤ s ′′ or s ′′ ≤ s ′ . s ′ s s 1 s ′ s ′ s ′ 1 2 3 – 18 – 2015-01-22 – Shierstm – s 2 – 19 – 2015-01-29 – Shierstm – s 3 s ′′ s ′′ s ′′ 1 2 3 14 /30 4 /28

  5. Least Common Ancestor and Ting • The least common ancestor is the function lca : 2 S \ {∅} → S such that • The states in S 1 are (transitive) children of lca ( S 1 ) , i.e. lca ( S 1 ) ≤ s , for all s ∈ S 1 ⊆ S, • lca ( S 1 ) is minimal, i.e. if ˆ s ≤ s for all s ∈ S 1 , then ˆ s ≤ lca ( S 1 ) • Note : lca ( S 1 ) exists for all S 1 ⊆ S (last candidate: top ). s ′ s – 18 – 2015-01-22 – Shierstm – – 19 – 2015-01-29 – Shierstm – s 1 s ′ s ′ s ′ 1 2 3 s 2 s 3 s ′′ s ′′ s ′′ 1 2 3 15 /30 5 /28

  6. Least Common Ancestor and Ting • Two states s 1 , s 2 ∈ S are called orthogonal , denoted s 1 ⊥ s 2 , if and only if • they are unordered, i.e. s 1 �≤ s 2 and s 2 �≤ s 1 , and • they “live” in different regions of an AND-state, i.e. ∃ s, region ( s ) = { S 1 , . . . , S n } ∃ 1 ≤ i � = j ≤ n : s 1 ∈ child ∗ ( S i ) ∧ s 2 ∈ child ∗ ( S j ) , s ′ s s 1 s ′ s ′ s ′ 1 2 3 s 2 – 18 – 2015-01-22 – Shierstm – – 19 – 2015-01-29 – Shierstm – s 3 s ′′ s ′′ s ′′ 1 2 3 16 /30 6 /28

  7. Least Common Ancestor and Ting • A set of states S 1 ⊆ S is called consistent , denoted by ↓ S 1 , if and only if for each s, s ′ ∈ S 1 , • s ≤ s ′ , or • s ′ ≤ s , or • s ⊥ s ′ . s ′ s s 1 s ′ s ′ s ′ 1 2 3 s 2 – 18 – 2015-01-22 – Shierstm – – 19 – 2015-01-29 – Shierstm – s 3 s ′′ s ′′ s ′′ 1 2 3 17 /30 7 /28

  8. Legal Transitions A hiearchical state-machine ( S, kind , region , → , ψ, annot ) is called well-formed if and only if for all transitions t ∈→ , (i) source and destination are consistent, i.e. ↓ source ( t ) and ↓ target ( t ) , (ii) source (and destination) states are pairwise orthogonal, i.e. • forall s, s ′ ∈ source ( t ) ( ∈ target ( t ) ), s ⊥ s ′ , (iii) the top state is neither source nor destination, i.e. • s 1 • • top / ∈ source ( t ) ∪ source ( t ) . E/ • s 5 s 2 • • Recall: final states are E/ s 3 F/ not sources of transitions. s 6 – 18 – 2015-01-22 – Shierstm – s 8 G/ – 19 – 2015-01-29 – Shierstm – F/ s 4 Example : [ true ] / F/ s 7 18 /30 8 /28

  9. The Depth of States • depth ( top ) = 0 , • depth ( s ′ ) = depth ( s ) + 1 , for all s ′ ∈ child ( s ) Example : • s 1 • E/ • s 5 s 2 • E/ s 3 F/ s 6 s 8 G/ F/ s 4 – 19 – 2015-01-29 – Shierstm – [ true ] / F/ s 7 9 /28

  10. Enabledness in Hierarchical State-Machines • The scope (“set of possibly affected states”) of a transition t is the least common region of source ( t ) ∪ target ( t ) . • Two transitions t 1 , t 2 are called consistent if and only if their scopes are orthogonal (i.e. states in scopes pairwise orthogonal). – 19 – 2015-01-29 – Shierstm – 10 /28

  11. Enabledness in Hierarchical State-Machines • The scope (“set of possibly affected states”) of a transition t is the least common region of source ( t ) ∪ target ( t ) . • Two transitions t 1 , t 2 are called consistent if and only if their scopes are orthogonal (i.e. states in scopes pairwise orthogonal). • The priority of transition t is the depth of its innermost source state, i.e. prio ( t ) := max { depth ( s ) | s ∈ source ( t ) } • A set of transitions T ⊆→ is enabled in an object u if and only if • T is consistent, • T is maximal wrt. priority, – 19 – 2015-01-29 – Shierstm – • all transitions in T share the same trigger, • all guards are satisfied by σ ( u ) , and • for all t ∈ T , the source states are active, i.e. source ( t ) ⊆ σ ( u )( st ) ( ⊆ S ) . 10 /28

  12. Transitions in Hierarchical State-Machines • Let T be a set of transitions enabled in u . ( cons , Snd ) • Then ( σ, ε ) − − − − − − → ( σ ′ , ε ′ ) if • σ ′ ( u )( st ) consists of the target states of t , i.e. for simple states the simple states themselves, for composite states the initial states, • σ ′ , ε ′ , cons , and Snd are the effect of firing each transition t ∈ T one by one , in any order , i.e. for each t ∈ T , • the exit transformer of all affected states, highest depth first, • the transformer of t , – 19 – 2015-01-29 – Shierstm – • the entry transformer of all affected states, lowest depth first. � adjust (2.), (3.), (5.) accordingly. 11 /28

  13. The Concept of History, and Other Pseudo-States – 19 – 2015-01-29 – main – 12 /28

  14. History and Deep History: By Example What happens on... • S/ susp s 0 R s / • R s ? R d / R s / R d / s 0 , s 2 A/ act • R d ? s 0 , s 2 H H ∗ • B/ • A, B, C, S, R s ? s 1 s 2 C/ s 0 , s 1 , s 2 , s 3 , susp , s 3 F/ s 3 • A, B, C, S, R d ? s b s 0 , s 1 , s 2 , s 3 , susp , s 3 D/ • s 4 • A, B, C, D, E, S, R s ? s 0 , s 1 , s 2 , s 3 , s 4 , s 5 , susp , s 3 E/ – 19 – 2015-01-29 – Shist – s 5 • A, B, C, D, E, S, R d ? s 0 , s 1 , s 2 , s 3 , s 4 , s 5 , susp , s 5 13 /28

  15. Junction and Choice t 1 c a / ] d 1 g [ • Junction ( “static conditional branch” ): • [ g d ] 2 / a • good : abbreviation c t 2 • unfolds to so many similar transitions with different guards, the unfolded transitions are then checked for enabledness • at best, start with trigger, branch into conditions, then apply actions • Choice: ( “dynamic conditional branch” ) Note: not so sure about naming and symbols, e.g., I’d guessed it was just the other way round... ;-) – 19 – 2015-01-29 – Shist – 14 /28

  16. Junction and Choice t 1 c a / ] d 1 g [ • Junction ( “static conditional branch” ): • [ g d ] 2 / a • good : abbreviation c t 2 • unfolds to so many similar transitions with different guards, the unfolded transitions are then checked for enabledness • at best, start with trigger, branch into conditions, then apply actions • Choice: ( “dynamic conditional branch” ) • evil : may get stuck • enters the transition without knowing whether there’s an enabled path • at best, use “else” and convince yourself that it cannot get stuck – 19 – 2015-01-29 – Shist – • maybe even better: avoid Note: not so sure about naming and symbols, e.g., I’d guessed it was just the other way round... ;-) 14 /28

  17. Entry and Exit Point, Submachine State, Terminate • Hierarchical states can be “folded” for readability. (but: this can also hinder readability.) • Can even be taken from a different state-machine for re-use. S : s – 19 – 2015-01-29 – Shist – 15 /28

  18. Entry and Exit Point, Submachine State, Terminate • Hierarchical states can be “folded” for readability. (but: this can also hinder readability.) • Can even be taken from a different state-machine for re-use. S : s • Entry/exit points , • Provide connection points for finer integration into the current level, than just via initial state. • Semantically a bit tricky: • First the exit action of the exiting state, • then the actions of the transition, • then the entry actions of the entered state, • then action of the transition from the entry point to an internal state, – 19 – 2015-01-29 – Shist – • and then that internal state’s entry action. • Terminate Pseudo-State • When a terminate pseudo-state is reached, the object taking the transition is immediately killed. 15 /28

  19. Deferred Events in State-Machines – 19 – 2015-01-29 – main – 16 /28

  20. Deferred Events: Idea For ages, UML state machines comprises the feature of deferred events . The idea is as follows: • Consider the following state machine: E/ F/ s 1 s 2 s 3 • Assume we’re stable in s 1 , and F is ready in the ether. • In the framework of the course , F is discarded . • But we may find it a pity to discard the poor event and may want to remember it for later processing, e.g. in s 2 , – 19 – 2015-01-29 – Sdefer – in other words, defer it. General options to satisfy such needs: • Provide a pattern how to “program” this (use self-loops and helper attributes). • Turn it into an original language concept. ( ← OMG’s choice) 17 /28

Recommend


More recommend