Hierarchy and Concurrency in Finite State Machines

Introduction
Semantics
Extending CHMs with time
Hierarchy and Concurrency in Finite State
Machines
G. Caravagna
[email protected]
Automata Theory
FSMs are useful to represent the flow of control
and are amenable to formal analysis such as model checking
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Index
1
Introduction
Finite State Machine
Adding Hierarchy and Concurrency
2
Semantics
Semantics of CHSMs
3
Extending CHMs with time
CHTTAs
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Finite State Machine
Adding Hierarchy and Concurrency
Index
1
Introduction
Finite State Machine
Adding Hierarchy and Concurrency
2
Semantics
Semantics of CHSMs
3
Extending CHMs with time
CHTTAs
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Finite State Machine
Adding Hierarchy and Concurrency
Finite State Machine (FSM)
Definition (FHM)
The canonical definition is a 5-tuple: hQ, Σ, q i , q f , →i
a finite set of states Q
a finite alphabet Σ
an initial state q i ∈ Q
a final state q f ∈ Q
a set of transitions →⊆ Q × Σ × Q
i.e.
M = h{0, 1}, {a, b}, 0, 1, {(0, a, 1), (1, b, 1)}i
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Finite State Machine
Adding Hierarchy and Concurrency
Accepting Run in a FSM
Given a word on Σ: ρ = σ0 σ1 . . . σn , it’s accepting run is the
sequence
σ0
σ1
σn
q0 → q1 → . . . qn → qn+1
such that
q0 = q i , qn+1 = q f
∀0 ≤ i ≤ n. (qi , σi , qi+1 ) ∈ →
Language accepted by a FSM is
L(M) = {w ∈ Σ∗ | w has an accepting run in M}
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Finite State Machine
Adding Hierarchy and Concurrency
Accepted Language, an example
M = h{0, 1}, {a, b}, 0, 1, {(0, a, 1), (1, b, 1)}i
a
0
a
b
1
b
b
0 → 1 → 1 → 1 ∈ L(M) = {ab∗ }
Automata are FSM !!
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Finite State Machine
Adding Hierarchy and Concurrency
Accepted Language, an example
M = h{0, 1}, {a, b}, 0, 1, {(0, a, 1), (1, b, 1)}i
a
0
a
b
1
b
b
0 → 1 → 1 → 1 ∈ L(M) = {ab∗ }
Automata are FSM !!
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Finite State Machine
Adding Hierarchy and Concurrency
Index
1
Introduction
Finite State Machine
Adding Hierarchy and Concurrency
2
Semantics
Semantics of CHSMs
3
Extending CHMs with time
CHTTAs
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Finite State Machine
Adding Hierarchy and Concurrency
Intuition
What we mean with
concurrency a composition of machines which synchronize on
transitions labeled with common alphabet symbols
hierarchy a state of a machine can be another machine
(superstate)
Mk
M1
M2
...
Mn
M
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Finite State Machine
Adding Hierarchy and Concurrency
Concurrent Hierarchical State Machine (CHM)
Definition (CHM)
base case Any FSM is a CHM
concurrency If M1 , M2 , . . . , Mn are CHMs, then
Mk = M1 k M2 k . . . k Mn
is a CHM
hierarchy If M = {M1 , M2 , . . . , Mn } are CHMs and N is a
FSM with states Q, then
(N, M, µ : Q 7→ M)
is a CHM
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Finite State Machine
Adding Hierarchy and Concurrency
Sample: the power of hierarchy
Suppose HSM = ”CHM without concurrency”. Say Σ = {σ} and
build a sequence of Mi , . . . , Mn where Mi is a HSM.
M1 is a FSM with L(M1 ) = {σ}.
Mj>1 is a HSM with
L(Mj ) = L(Mj−1 ) · σ · L(Mj−1 )
such that:
Mj has two superstates 0, 1 mapped to Mj−1
?
L(Mj ) = {s} where |s| = 2j − 1
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Finite State Machine
Adding Hierarchy and Concurrency
Sample: the power of hierarchy
Suppose HSM = ”CHM without concurrency”. Say Σ = {σ} and
build a sequence of Mi , . . . , Mn where Mi is a HSM.
M1 is a FSM with L(M1 ) = {σ}.
Mj>1 is a HSM with
L(Mj ) = L(Mj−1 ) · σ · L(Mj−1 )
such that:
Mj has two superstates 0, 1 mapped to Mj−1
?
L(Mj ) = {s} where |s| = 2j − 1
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Finite State Machine
Adding Hierarchy and Concurrency
Special cases of FSM
Acceptors and transducers
Automata for regular languages
Moore and Mealy Machines
Place/Transition Petri Nets
Statecharts and UML
Labeled Transition Systems
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Index
1
Introduction
Finite State Machine
Adding Hierarchy and Concurrency
2
Semantics
Semantics of CHSMs
3
Extending CHMs with time
CHTTAs
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Building [[ ]]
We map each CHM M in a FSM [[M]]
[[ ]] : CHM 7→ FSM
def
L(M ∈ CHM) = L([[M]])
Semantics will be given in terms of a FSM!
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Building [[ ]]
Definition ([[M]])
base case Any FSM M = hQ, Σ, q i , q f , →i has semantic
def
[[M]] = M
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Building [[ ]]
Definition ([[M]])
conc. Any CHM Mk = M1 k M2 k . . . k Mn such that
def
[[Mi ]] = hQi , Σi , qii , qif , →i i has semantic
def
[[Mk ]] = [[M1 ]] × [[M2 ]] × . . . × [[Mn ]]
Qk = Q1 × · · · × Qn
Σk = Σ1 ∪ · · · ∪ Σn
qki = hq1i , · · · , qni i and qkf = hq1f , · · · , qnf i
what about transitions ?
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Building [[ ]]
Definition ([[M]])
conc. Any CHM Mk = M1 k M2 k . . . k Mn such that
def
[[Mi ]] = hQi , Σi , qii , qif , →i i has semantic
def
[[Mk ]] = [[M1 ]] × [[M2 ]] × . . . × [[Mn ]]
Qk = Q1 × · · · × Qn
Σk = Σ1 ∪ · · · ∪ Σn
qki = hq1i , · · · , qni i and qkf = hq1f , · · · , qnf i
what about transitions ?
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Building [[ ]]
Definition ([[M]])
conc. [[M]] has a σ-transition from hq1 , · · · , qn i to
hw1 , · · · , wn i iff
σ ∈ Σi =⇒ (qi , σ, wi ) ∈→i
qi = wi otherwise
Which language are we defining?
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Sample 1/3
0
a
1
b
0
b
1
a
Q1 = {0, 1}
Q2 = {0, 1}
Σ1 = {a, b}
...
→1 = {(0, a, 1), (1, b, 1)}
Σ2 = {a, b}
...
→2 = {(0, a, 0), (0, b, 1)}
Parallel composition is
Qk = Q1 × Q2 = {00, 01, 10, 11}
00
f
q i = 00
q = 11
k
k
→k = {(00, a, 01), (10, b, 11)}
L1 = ab∗
a
01
(0, a, 0) 6∈→1
Σk = Σ1 ∪ Σ2 = {a, b}
a
10
L2 = a∗ b
Lk = ab
G.Caravagna
b
(1, b, 1) ∈→1
(0, b, 1) ∈→2
11
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Sample 2/3
a
a
1
0
1
0
c
L1 = (ac)∗
L2 = (ab)∗
b
Parallel composition is
00
b
c
10
01
a
b
c
11
Lk = (a(bc|cb))∗
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Building [[ ]]
Definition ([[M]])
hier. Any CHM M = (N, M, µ) with N top-level FSM, has
QH = {(q, w )} were q ∈ QN and w ∈ [[µ(q)]]
ΣH = ΣN ∪ Σ[[µ(q)]] for each q ∈ QN
i = (q i , [[µ(q i )]]) and q f = (q f , [[µ(q f )]])
qH
N
N
H
N
N
what about transitions ?
We have two kind of transitions !
for top-level machine
for hierarchical machines
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Building [[ ]]
Definition ([[M]])
hier. Any CHM M = (N, M, µ) with N top-level FSM, has
QH = {(q, w )} were q ∈ QN and w ∈ [[µ(q)]]
ΣH = ΣN ∪ Σ[[µ(q)]] for each q ∈ QN
i = (q i , [[µ(q i )]]) and q f = (q f , [[µ(q f )]])
qH
N
N
H
N
N
what about transitions ?
We have two kind of transitions !
for top-level machine
for hierarchical machines
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Building [[ ]]
Definition ([[M]])
conc. (Top-level transition) for each (q, σ, w ) ∈→N
f
i
( (q, q[[µ(q)]]
), σ, (w , q[[µ(w
)]] ) ) ∈→H
q
σ
w
N
µ
µ
(q,
µ(q)
)
σ
(w,
µ(w)
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
)
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Building [[ ]]
Definition ([[M]])
conc. (Hierarchial transition) for each (w , σ, w 0 ) ∈→[[µ(q)]]
when q ∈ QN
( (q, w ), σ, (q, w 0 ) ) ∈→H
q
N
µ
w
(q, w)
σ
G.Caravagna
σ
(q, w0 )
w0
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
Semantics of CHSMs
Sample 3/3
A
a
B
b
L1 = ab∗
L2 = a∗ b
b
A
a
B
µ
µ
σ
0
(0, A)
1
a
τ
(0, B)
b
σ
LH = L1 · σ · (L2 · τ )+
= ab∗ σ(a∗ (bτ )∗ )∗ b
(1, A)
a
b
(1, B)
τ
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
CHTTAs
Index
1
Introduction
Finite State Machine
Adding Hierarchy and Concurrency
2
Semantics
Semantics of CHSMs
3
Extending CHMs with time
CHTTAs
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
CHTTAs
What we model
ACID transactions
atomic
locks on resources
roll-back
long-running transactions
sequential, parallel tasks
sub-tasks
deadline
compensations
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
CHTTAs
Long-running transactions
composed by atomic activities Ai
not allowed partial execution
all activities Ai have a compensation (atomic) activity Bi
”Bi repairs from the effects of successful execution of Ai ”
i.e. Sequential Transactions
A1 , . . . , An such that Ai+1 starts when Ai is committed.
Scenario:
- or A1 , . . . , An is executed.
- or A1 , . . . , A1 , Bi , . . . , B1 is executed for i < n.
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
CHTTAs
What we use
Communicating Hierarchical Transaction-based Timed Automata
Definition (CHTTA)
informally are extensions of CHMs with:
different terminal states
commit state
abort state
different communication mechanisms
private channels (restrictions)
read/write actions
explicit notion of time
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
CHTTAs
SOS rules
Some interesting rules of the SOS semantics are
(q, α, φ, B, q 0 ) ∈ δ
v |= φ q 0 ∈
/S
α
(hA, µi , (q, v )) →(hA, µi , (q 0 , v [B]))
(q, α, φ, B, q 0 ) ∈ δ
q0 ∈
/S
v |= φ
Init(µ(q)) = (c, v 0 )
α
(hA, µi , (q, v )) →(hA, µi , (q 0 .c, v [B].v 0 ))
a!
a?
00
(A1 , (c1 , v )) →(A1 , (c10 , v 0 )) (A2 , (c2 , v 0 )) →(A2 , (c2 , v 00 ))
τ
00
(A1 k A2 , (c1 ; c2 , v )) →(A1 k A2 , (c10 ; c2 , v 00 ))
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
CHTTAs
Sample Webserver 1/4
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
CHTTAs
Sample Webserver 2/4
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
CHTTAs
Sample Webserver 3/4
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
CHTTAs
Sample Webserver 3/4
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
CHTTAs
Sample Webserver: Model Checking
G.Caravagna
Hierarchy and Concurrency in Finite State Machines
Introduction
Semantics
Extending CHMs with time
CHTTAs
References I
R. Alur, S. Kannan and M. Yannakakis
”Communicating Hierarchical State Machines”.
LNCS, 1644: p.169–??, 1999
R. Lanotte, A. Maggiolo-Schettini, P. Milazzo, A. Troina
”Modeling Long-Running Transactions with Communicating
Hierarchical Timed Automata”.
LNCS, 4037: p.108–122, 2006
G.Caravagna
Hierarchy and Concurrency in Finite State Machines