Statecharts for the many: Statecharts for the many: Algebraic State - - PowerPoint PPT Presentation

statecharts for the many statecharts for the many
SMART_READER_LITE
LIVE PREVIEW

Statecharts for the many: Statecharts for the many: Algebraic State - - PowerPoint PPT Presentation

Statecharts for the many: Statecharts for the many: Algebraic State Algebraic State Transition Diagrams Transition Diagrams Marc Frappier Marc Frappier GRIL Groupe de recherche en Groupe de recherche en GRIL ing nierie du


slide-1
SLIDE 1

1

Statecharts for the many: Statecharts for the many: Algebraic State Algebraic State Transition Diagrams Transition Diagrams

Marc Frappier Marc Frappier GRIL GRIL – – Groupe de recherche en Groupe de recherche en ing ingé énierie du logiciel nierie du logiciel

slide-2
SLIDE 2

2

Plan Plan

  • Statecharts and information system

Statecharts and information system specifications specifications

  • ASTD : Algebraic State Transition

ASTD : Algebraic State Transition Diagrams Diagrams

  • Semantics of ASTD

Semantics of ASTD

  • Conclusion

Conclusion

slide-3
SLIDE 3

3

Statecharts Statecharts

  • graphical notation

graphical notation

  • hierarchy + orthogonality

hierarchy + orthogonality

  • hierarchical states

hierarchical states

  • AND states (parallel)

AND states (parallel)

  • OR states (choice)

OR states (choice)

  • nice for single instance behaviour

nice for single instance behaviour

  • parameterized states in

parameterized states in Harel Harel’ ’s s seminal paper seminal paper (SCP 87) (SCP 87)

“never never” ” implemented or formalised implemented or formalised

slide-4
SLIDE 4

4

A library in statecharts A library in statecharts

slide-5
SLIDE 5

5

Problems Problems

  • nly describes behaviour of a single book
  • nly describes behaviour of a single book
  • how to deal with several books?

how to deal with several books?

  • put n copies of

put n copies of book

book in parallel

in parallel

  • not defined in statecharts or UML

not defined in statecharts or UML

  • available in ROSE RT, but it is not quite what we want here

available in ROSE RT, but it is not quite what we want here

  • can discard an unreturned book

can discard an unreturned book

  • could add a guard to

could add a guard to discard

discard

  • unnecessary complexity

unnecessary complexity

  • could make discard a transition from an inner state

could make discard a transition from an inner state

  • f
  • f loan

loan

  • introduce coupling between

introduce coupling between book

book and

and loan

loan

slide-6
SLIDE 6

6

Potential solutions Potential solutions

  • book knows about the structure of loan

book knows about the structure of loan

  • makes loan less reusable

makes loan less reusable

  • makes maintenance more difficult

makes maintenance more difficult

book Acquire Discard Renew Return Lend loan

slide-7
SLIDE 7

7

Adding members Adding members

slide-8
SLIDE 8

8

Problems Problems

  • a member can borrow several books in parallel

a member can borrow several books in parallel

  • can

can’ ’t t “ “easily easily” ” express that in statecharts or UML express that in statecharts or UML

  • State explosion

State explosion

  • two calls to loan

two calls to loan

  • ne in member, one in book
  • ne in member, one in book
  • they both get the

they both get the lend

lend event

event

  • OK if only one member

OK if only one member

  • KO if we have several members trying to borrow the same

KO if we have several members trying to borrow the same book book

  • could remove loan from member

could remove loan from member

  • must add guard to

must add guard to Unregister

Unregister to check for completed loan

to check for completed loan

  • loose visual ordering constraint

loose visual ordering constraint

slide-9
SLIDE 9

9

Potential solutions Potential solutions

  • remove loan from member

remove loan from member

  • loose visual ordering constraint between member

loose visual ordering constraint between member and loan and loan

  • replaced by a guard

replaced by a guard

  • need state variable

need state variable

member

slide-10
SLIDE 10

10

The single instance view: The single instance view: A weakness of statecharts A weakness of statecharts

  • both statecharts and UML state machines are

both statecharts and UML state machines are designed to represent a single instance designed to represent a single instance

  • eg

eg, controller, object of a class, etc , controller, object of a class, etc

  • they offer no convenient means to express

they offer no convenient means to express relationships between multiple instances relationships between multiple instances

  • in practice, designers only describe the single

in practice, designers only describe the single instance behaviour instance behaviour

  • leave it to the implementer to figure out the multiple

leave it to the implementer to figure out the multiple instance case instance case

slide-11
SLIDE 11

11

A solution: Process algebra A solution: Process algebra

  • CCS, CSP, ACP, LOTOS, EB

CCS, CSP, ACP, LOTOS, EB3

3, ...

, ...

  • algebra

algebra

  • perators to combine process expressions
  • perators to combine process expressions
  • sequence, choice, interleave, synchronisation, guard, ...

sequence, choice, interleave, synchronisation, guard, ...

  • quantification

quantification

  • perators are the essence of abstraction
  • perators are the essence of abstraction
  • combine small units to build large units

combine small units to build large units

  • perators foster abstraction by masking internal details
  • perators foster abstraction by masking internal details
slide-12
SLIDE 12

12

A Process expression for books A Process expression for books

book(b : BookId ) = Acquire(b,_)

  • loan( _, b)¯
  • Discard(b)

Sequential composition Kleene closure matches any value

slide-13
SLIDE 13

13

A process expression for loans A process expression for loans

loan(mId:Member, IDbId:BookID ) = nbLoans(mId) < maxNbLoans(mId)  Lend(mId, bId)

  • Renew(bId)¯
  • Return(bId)

guard

slide-14
SLIDE 14

14

A process expression for members A process expression for members

member(m : MemberId ) = Register(m, _, _)

  • ( 8 b : BookId : loan( m, b)¯ )
  • Unregister(m)

interleave quantification

  • ver all books
slide-15
SLIDE 15

15

Interleave quantification Interleave quantification

8 x : {1,2,3} : P(x) = P(1) 8 P(2)8P(3)

slide-16
SLIDE 16

16

Main process expression Main process expression

main = ( 8 b : BookId : book(b)¯) 7 ( 8 m : MemberId : member(m)¯)

Synchronisation over common actions

slide-17
SLIDE 17

17

Synchronisation over common Synchronisation over common actions actions

a(1) • b(1) • c(1) 7

|x : T : a(x) • b(x) • c(2)

= a(1) • b(1) • STOP

quantified choice

slide-18
SLIDE 18

18

ASTD ASTD

  • Algebraic State Transition Diagrams

Algebraic State Transition Diagrams

  • ASTD = statecharts + process algebra

ASTD = statecharts + process algebra

  • graphical notation

graphical notation

  • power of abstraction

power of abstraction

  • statecharts become elementary process

statecharts become elementary process expressions expressions

  • combine them using operators

combine them using operators

  • formal semantics

formal semantics

  • perational semantics
  • perational semantics
slide-19
SLIDE 19

19

ASTD Operators ASTD Operators

: sequence

: sequence

  • |

| : choice : choice

  • |x

|x : quantified choice : quantified choice

¯ : Kleene closure

: Kleene closure

 : guard

: guard

  • |[ A ]|

|[ A ]|: parallel composition with synchronisation on : parallel composition with synchronisation on A A

8 interleave,

interleave, 7 parallel composition parallel composition

8x, |[ ]|x : quantified version

  • ASTD call

ASTD call : allows recursive calls : allows recursive calls

slide-20
SLIDE 20

20

A book ASTD A book ASTD

final state

  • perators

applied from left to right initial state final transition: can trigger only if its source is in a final state

slide-21
SLIDE 21

21

Closure applied to an ASTD Closure applied to an ASTD

¯ means execute the

ASTD an arbitrary number of times, including 0

when the ASTD is in a

final state, it can start again from its initial state

example traces are

empty trace e1,e2,e2,...,e1,e1,e2, ...

slide-22
SLIDE 22

22

The closure ASTD type The closure ASTD type

¯ denotes the type constructor for a closure

body is an ASTD (of any type)

(¯, body )

slide-23
SLIDE 23

23

The closure state type The closure state type

¯0 is the closure state

type constructor

started? is a boolean

value that indicates if its component has started its first iteration

s is the state of its

component

( ¯0 ,started?, s )

slide-24
SLIDE 24

24

States of a closure States of a closure

  • initial state

initial state

  • is the initial state of its component

is the initial state of its component

  • final states

final states

  • its initial state

its initial state

  • final states of its component

final states of its component

function that defines the initial state of an ASTD closure ASTD closure initial state function that determines if a state is final

slide-25
SLIDE 25

25

Final state Final state

  • an ASTD does not terminate when its current

an ASTD does not terminate when its current state is final state is final

  • a final state simply

a final state simply enables enables transitions of another transitions of another ASTD within a ASTD within a

  • closure

closure

  • sequence

sequence

slide-26
SLIDE 26

26

A member ASTD A member ASTD

slide-27
SLIDE 27

27

A loan ASTD A loan ASTD

slide-28
SLIDE 28

28

The main ASTD The main ASTD

n-ary operator

  • perands of ||
slide-29
SLIDE 29

29

Power of abstraction Power of abstraction

  • suppose you have two statecharts,

suppose you have two statecharts, a a and and b b

  • you want to compose them as follows

you want to compose them as follows

  • execute

execute a a an arbitrary number of times an arbitrary number of times

  • then execute

then execute b b an arbitrary number of times an arbitrary number of times

  • then start over again, an arbitrary number of times

then start over again, an arbitrary number of times

  • can

can’ ’t do it in statecharts without peeking into t do it in statecharts without peeking into a a and and b b’ ’s s structure with guards structure with guards

  • introduce a dependency between the compound and

introduce a dependency between the compound and the components the components

slide-30
SLIDE 30

30

Power of abstraction Power of abstraction

sequential composition

slide-31
SLIDE 31

31

The sequence ASTD type The sequence ASTD type

  • denotes the sequence ASTD type constructor

denotes the sequence ASTD type constructor

  • left

left and and right right are are ASTDs ASTDs

(, left, right)

slide-32
SLIDE 32

32

The sequence state type The sequence state type

0 denotes the sequence

state type constructor

side denotes the current

side of the sequence

left right

s denotes the state of the

side component

(0, side, s)

slide-33
SLIDE 33

33

State transitions State transitions

(0,left,1) (0,left,2) (0,right,4)

slide-34
SLIDE 34

34

State transitions State transitions

(0,left,1) (0,left,2) (0,left,2)

slide-35
SLIDE 35

35

State transitions State transitions

(0,left,(¯0,ÿstarted, 1)) (0,right,(¯0,started, 4)) (0,right,(¯,started, 4))

slide-36
SLIDE 36

36

Initial and final states of a sequence Initial and final states of a sequence ASTD ASTD

slide-37
SLIDE 37

37

Operational semantics Operational semantics

  • first used by Milner for CCS

first used by Milner for CCS

  • transitions

transitions

  • ASTD a can execute

ASTD a can execute s s from state s and move to from state s and move to state s state s’ ’

slide-38
SLIDE 38

38

Operational semantics Operational semantics

  • transitions defined by a set of inference rules

transitions defined by a set of inference rules

  • rules for each operator

rules for each operator

  • allows non

allows non-

  • determinism

determinism

  • if several transitions can fire from s, then one is

if several transitions can fire from s, then one is nondeterministically nondeterministically chosen chosen

  • no priority

no priority

slide-39
SLIDE 39

39

Inference rules Inference rules

  • first rules deals with environment, noted

first rules deals with environment, noted ([ ]) ([ ]), to , to manage variables introduced by manage variables introduced by

  • quantifications

quantifications

  • process parameters

process parameters

slide-40
SLIDE 40

40

Automaton inference rules Automaton inference rules

execute an automaton transition

similar to traditional d of an automaton

execute a transition

  • f the component
slide-41
SLIDE 41

41

Closure inference rules Closure inference rules

execute from the initial state of the component execute the component when started

slide-42
SLIDE 42

42

Sequence inference rules Sequence inference rules

execute on left execute on right when left is final execute the right component

slide-43
SLIDE 43

43

Choice: initial and final states Choice: initial and final states

Choice state (|0,side,s)

slide-44
SLIDE 44

44

Choice inference rules Choice inference rules

execute the first component from its initial state execute the second component from its initial state execute the first component when it has been selected execute the second component when it has been selected

slide-45
SLIDE 45

45

Choice example Choice example

(|0,¶,¶)

e1 e2 e3 e4

(|0,fst,2) (|0,fst,3) (|0,snd,5) (|0,snd,6)

slide-46
SLIDE 46

46

Integration with the business class Integration with the business class diagram diagram

book member

Register Unregister Lend Renew Return Acquire Discard ListBook

loan

bookId title memberId name nbLoans maxNbLoans date 1 *

borrower

slide-47
SLIDE 47

47

State variables State variables

  • the system trace is the only state variable

the system trace is the only state variable

  • entity attributes are functions on this trace

entity attributes are functions on this trace

  • attributes can be used anywhere in

attributes can be used anywhere in ASTDs ASTDs

  • guard, quantification sets, ...

guard, quantification sets, ...

nbLoans nbLoans(mId : (mId : MemberId MemberId) = ) = Register Register( (mId mId, _ ) : 0, , _ ) : 0, Lend Lend(mId (mId, _) : 1 + , _) : 1 + nbLoans nbLoans(mId), (mId), Return Return(bId (bId) : ) : if if borrower borrower(bId (bId) = ) = mId mId then then nbLoans nbLoans(mId) (mId) -

  • 1,

1, Unregister Unregister( (mId mId, _ ) : , _ ) : ^ ^; ;

slide-48
SLIDE 48

48

Conclusion Conclusion

  • process algebra operators can improve the

process algebra operators can improve the expressiveness of statecharts expressiveness of statecharts

  • complete, precise models of information systems

complete, precise models of information systems

  • not just single instance scenarios, but also multiple instance

not just single instance scenarios, but also multiple instance scenarios scenarios

  • future work

future work

  • tools for animation

tools for animation

  • model checking

model checking

  • code generation

code generation