– 10 – 2015-12-03 – main –
Software Design, Modelling and Analysis in UML
Lecture 10: State Machines Overview
2015-12-03
- Prof. Dr. Andreas Podelski, Dr. Bernd Westphal
Albert-Ludwigs-Universit¨ at Freiburg, Germany
Lecture 10: State Machines Overview 2015-12-03 Prof. Dr. Andreas - - PowerPoint PPT Presentation
Software Design, Modelling and Analysis in UML Lecture 10: State Machines Overview 2015-12-03 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal 10 2015-12-03 main Albert-Ludwigs-Universit at Freiburg, Germany Contents &
– 10 – 2015-12-03 – main –
Albert-Ludwigs-Universit¨ at Freiburg, Germany
– 10 – 2015-12-03 – Sprelim –
2/33
Last Lecture:
This Lecture:
– 10 – 2015-12-03 – main –
3/33
– 10 – 2015-12-03 – Selements –
4/33 (Note: “Exceptions prove the rule.”)
– 10 – 2015-12-03 – Selements –
5/33
– 10 – 2015-12-03 – Selements –
5/33
– 10 – 2015-12-03 – Selements –
6/33
– 10 – 2015-12-03 – Selements –
7/33
– 10 – 2015-12-03 – Selements –
8/33
– 10 – 2015-12-03 – Selements –
9/33
Exist
Directions
– 10 – 2015-12-03 – main –
10/33
– 10 – 2015-12-03 – Stron –
11/33
Task: develop a video game. Genre: Racing. Rest: open, i.e. Degrees of freedom: Exemplary choice: 2D-Tron
arcade
hardware capabilities...)
2D
minimal: main menu and game
– 10 – 2015-12-03 – Stron –
12/33
2D-Tron
Main External inputs
Game Logic
(Physics) Engine
Output
(from ASCII to bitmap; native or via API)
notify update ? ?
– 10 – 2015-12-03 – Stron –
13/33
Main External inputs Game Logic (Physics) Engine Output notify update ? ?
Tron Joystick? . . . Keyboard? Control Player
colour score direction speed
Gameplay Render OpenGL? . . . aalib? AI? Segment
x0, y0 x1, y1 colour
Engine
areawidth areaheight
1..∗ notify update 0..∗ head world 1..∗ Conventions:
– 10 – 2015-12-03 – main –
14/33
– 10 – 2015-12-03 – Sbehav –
15/33
Have: Means to model the structure of the system.
Want: Means to model behaviour of the system.
that is, to describe sets of sequences σ0, σ1, · · · ∈ Σω
– 10 – 2015-12-03 – Sbehav –
16/33
Example: Pre-Image Image (the UML model is supposed to be the blue-print for a software system). A description of behaviour could serve the following purposes:
“System definitely does this”
“This sequence of inserting money and requesting and getting water must be possible.” (Otherwise the software for the vending machine is completely broken.)
“System does subset of this”
“After inserting money and choosing a drink, the drink is dispensed (if in stock).” (If the implementation insists on taking the money first, that’s a fair choice.)
“System never does this”
“This sequence of getting both, a water and all money back, must not be possible.” (Otherwise the software is broken.)
Note: the latter two are trivially satisfied by doing nothing...
– 10 – 2015-12-03 – Sbehav –
17/33
UML provides two visual formalisms for constructive description of behaviours:
We (exemplary) focus on State-Machines because
transition-system-like to petri-net-like...
s1 s2 s3
/n := ∅ F/x := 0
s1 s2
/p ! F
– 10 – 2015-12-03 – Sbehav –
18/33
N S W E
CD, SM S = (T, C, V, atr ), SM M = (ΣD
S , AS , →SM )
ϕ ∈ OCL expr CD, SD S , SD B = (QSD, q0, AS , →SD, FSD) π = (σ0, ε0)
(cons0,Snd0)
− − − − − − − − →
u0
(σ1, ε1)· · · wπ = ((σi, consi, Sndi))i∈N G = (N, E, f)
OD
– 10 – 2015-12-03 – main –
19/33
– 10 – 2015-12-03 – Sstmover –
20/33
s1 s2 s3
/n := ∅ F/x := 0
Brief History:
introduces in particular hierarchical states.
nowadays also in Matlab/Simulink, etc.
(not the official name, but understood: UML-Statecharts)
Note: there is a common core, but each dialect interprets some constructs subtly different Crane and Dingel (2007). (Would be too easy otherwise. . . )
– 10 – 2015-12-03 – Sstmover –
21/33 Syntax: (i) UML State Machine Diagrams. (ii) Def.: Signature with signals. (iii) Def.: Core state machine. (iv) Map UML State Machine Diagrams to core state machines. Semantics: The Basic Causality Model (v) Def.: Ether (aka. event pool) (vi) Def.: System configuration. (vii) Def.: Event. (viii) Def.: Transformer. (ix) Def.: Transition system, computation. (x) Transition relation induced by core state machine. (xi) Def.: step, run-to-completion step. (xii) Later: Hierarchical state machines.
Model Instances
N S W E
CD, SM S = (T, C, V, atr ), SM M = (ΣD
S , AS , →SM )
ϕ ∈ OCL expr CD, SD S , SD B = (QSD, q0, AS , →SD, FSD) π = (σ0, ε0)
(cons0,Snd0)
− − − − − − − − →
u0
(σ1, ε1)· · · wπ = ((σi, consi, Snd i))i∈N G = (N, E, f)
Mathematics
OD
✔
✔
✔ ✔ ✔ ✔ ✔
– 10 – 2015-12-03 – main –
22/33
– 10 – 2015-12-03 – Sstmsyn –
23/33
S = (T, C, V, atr , E ), E a set of signals, is called signature (with signals) if and only if (T , C ∪ E , V, atr) is a signature (as before). Note: Thus conceptually, a signal is a class and can have attributes of plain type, and participate in associations.
– 10 – 2015-12-03 – Sstmsyn –
24/33
x : Int
c
0..1
– 10 – 2015-12-03 – Sstmsyn –
25/33
Definition. A core state machine over signature S = (T, C, V, atr , E ) is a tuple M = (S, s0, →) where
→ ⊆ S × (E ∪ { })
× Expr S
guard
× ActS
action
×S is a labelled transition relation. We assume a set Expr S of boolean expressions over S (for instance OCL, may be something else) and a set ActS of actions.
– 10 – 2015-12-03 – Sstmsyn –
26/33
UML state machine diagram SM: s1 s2 annot annot ::=
[ guard ] / [action]
(default: true, assumed to be in ExprS )
(default: skip, assumed to be in ActS ) maps to M(SM) =
S
, s1
, (s1, event, guard, action, s2)
– 10 – 2015-12-03 – Sstmsyn –
27/33
Reconsider the syntax of transition annotations: annot ::=
[ guard ] / [action]
What if things are missing?
/
E /
/ act
E / act
In the standard, the syntax is even more elaborate:
attribute v of u is assigned the corresponding attribute of E.
– 10 – 2015-12-03 – Sstmsyn –
28/33
In the following, we assume that
a set SM of state chart diagrams (each comprising one state machine SM).
C ∈ C (S ) has a state machine SMC and that its class CSMC is C. If not explicitly given, then this one: SM0 := ({s0}, s0, (s0, , true, skip, s0)). We will see later that this choice does no harm semantically. Intuition 1: SMC describes the behaviour of the instances of class C. Intuition 2: Each instance of class C executes SMC.
Note: we don’t consider multiple state machines per class. We will see later that this case can be viewed as a single state machine with as many AND-states.
– 10 – 2015-12-03 – main –
32/33
– 10 – 2015-12-03 – main –
33/33 Ambler, S. W. (2005). The Elements of UML 2.0 Style. Cambridge University Press. Crane, M. L. and Dingel, J. (2007). UML vs. classical vs. rhapsody statecharts: not all models are created equal. Software and Systems Modeling, 6(4):415–435. Dobing, B. and Parsons, J. (2006). How UML is used. Communications of the ACM, 49(5):109–114. Harel, D. (1987). Statecharts: A visual formalism for complex systems. Science of Computer Programming, 8(3):231–274. Harel, D., Lachover, H., et al. (1990). Statemate: A working environment for the development
OMG (2011a). Unified modeling language: Infrastructure, version 2.4.1. Technical Report formal/2011-08-05. OMG (2011b). Unified modeling language: Superstructure, version 2.4.1. Technical Report formal/2011-08-06.