statechart for the washing machine - ut · statechart for the washing machine 1 state modeling ......

Post on 03-Apr-2018

219 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Statechart for the washing machine

State modeling -- Luciano García-Bañuelos 1

!""

#$%&

!"#$%&'()*+",-.

!"#$/01/*&2.

'!()

!"#$%&'()*3&2+4.

!"#$+)&3*.

*#+'&

!"#$%&'()*!3,&2.

!"#$/01/*"0).

$*(#+

!"#$%&'()*!35.

!"#$+)&3*.

$*,

/"643 /"643

+),3)7/%,2834'0%,39

,:)43$*;<.

,:)43$*;<$1&2.

,:)43$*=$1&2.

7/%,2>?+0/43$!4%&@,)49

,:)43$*=$1&2.7/%,28+0/43$!4%&@,)49A%&'()*"::.

,:)43$*B<$1&2.A

%&'()*"::.

+),3)7/%,28!4%&@,)4

"3$/%,28+0/43$!4%&@,)49

A/%,2$8$34'0%,3

1"!47/%,28+0/43$!4%&@,)49A

/%,2$8$34'0%,31"!47/%,2834'0%,39A/%,2$8$!4%&@,)4

1"!47/%,28!4%&@,)49A/%,2$8$+0/43$!4%&@,)4

State explosion and history

State modeling -- Luciano García-Bañuelos 2

!""

!"#$%&'&()*"!&+,

#$%&

!"#$'-./)+%"01,

!"#$2342+-5,

'!()

!"#$'-./)+6-5%&,

!"#$%)-6+,

*#+'&

!"#$'-./)+!60-5,

!"#$2342+"3),

$*(#+

!"#$'-./)+!67,

!"#$%)-6+,

$*,

2"8&6 2"8&6

%)06)92'05:6&.3'06;

0<)&6$+=>,

0<)&6$+=>$4-5,

0<)&6$+?$4-5,

92'05@A%32&6$!&'-(0)&;

0<)&6$+?$4-5,92'05:%32&6$!&'-(0)&;B'-./)+"<<,0<)&6$+C>$4-5,B

'-./)+"<<,

%)06)92'05:!&'-(0)&

"6$2'05:%32&6$!&'-(0)&;

What if the “power” button can be clicked at anytime?

What if we want to come back to the same state we left?

State explosion

State modeling -- Luciano García-Bañuelos 3

  If we consider that each attribute in a class defines at least two possible states (e.g. boolean values)

  If we have “n” classes with “m” attributes each (let’s assume that all classes have the same number of attributes)   Possible states: 2nm

  What if the state space of each variable > 2 ?

Composite states

State modeling -- Luciano García-Bañuelos 4

!""

!"#$% !"#$%

!#

&"'()$*$+,-"&$./

$%&'

&"'(*012,.)"34/

&"'(!56!.07/

(!)*

&"'(*012,.%07)$/

&"'(),0%./

+$#('

&"'(*012,.&%307/

&"'(!56!."5,/

%+)$#

&"'(*012,.&%8/

&"'(),0%./

%+,

),3%,9!*37:%$15*3%;

3<,$%(.=>/

3<,$%(.=>(607/

3<,$%(.?(607/

9!*37@A)5!$%(&$*0+3,$;

3<,$%(.?(607/9!*37:)5!$%(&$*0+3,$;B*012,."<</3<,$%(.C>(607/B

*012,."<</

),3%,9!*37:&$*0+3,$

"%(!*37:)5!$%(&$*0+3,$;

The transition can be fired from any internal state

Contour transitions

State modeling -- Luciano García-Bañuelos 5

!"#$%&' %"("%)"

*+%,&%-

*.%)$ )"/+!- $0.%-

)$+1

!"

#$%&

!"

#$%&

'

(

) (

2&%3%&!)4.)).+!

The event “stop” will move to state “first” independently of the current

nested state

History

State modeling -- Luciano García-Bañuelos 6

  Return to a previously visited hierarchical state   Shallow history: just the current level

  Deep history: includes all nested states

  Some times it is useful to clear history   clear-history(state) clh(state)   clear-history(state*) clh(state*)

H

H*

History

State modeling -- Luciano García-Bañuelos 7

!""

!"#$%

!#

&"'()$*$+,-"&$./

$%&'

&"'(*012,.)"34/

&"'(!56!.07/

(!)*

&"'(*012,.%07)$/

&"'(),0%./

+$#('

&"'(*012,.&%307/

&"'(!56!."5,/

%+)$#

&"'(*012,.&%8/

&"'(),0%./

%+,

),3%,9!*37:%$15*3%;

3<,$%(.=>/

3<,$%(.=>(607/

3<,$%(.?(607/

9!*37@A)5!$%(&$*0+3,$;

3<,$%(.?(607/9!*37:)5!$%(&$*0+3,$;B*012,."<</3<,$%(.C>(607/B

*012,."<</

),3%,9!*37:&$*0+3,$

"%(!*37:)5!$%(&$*0+3,$;

-

!"#$%

Deep vs Shallow history

State modeling -- Luciano García-Bañuelos 8

!

"

#

$ %

&

' (

)

!"#$%"

&'$#"

!

"*

#

$ %

&

' (

)

!"#$%"

&'$#"

Completing transitions

State modeling -- Luciano García-Bañuelos 9

  Triggered by a completion event   generated automatically when an immediately nested state

machine terminates

!"##$%%$&'

()*+,-.

()*+,-.

!"##$%%,/

No explicit event

Triggering rules

State modeling -- Luciano García-Bañuelos 10

  Two or more transitions may have the same event trigger   inner transition takes precedence   if no transition is triggered, event is discarded

!"#$%

&''$%(

&''$%)

! " "

Order of activities in nested models

State modeling -- Luciano García-Bañuelos 11

  Same approach as for the simple case

!"#$%&!"'(

!"

!"#$%&!"'((

!""

!)*+,$-

!.$/0%&!.'1

!#

!.$/0%&!.'1(

!#"

*#.#$'1

Execution sequence:

exS11 exS1 actEenS2 initS2 enS21

Orthogonal states

State modeling -- Luciano García-Bañuelos 12

  Multiple simultaneous perspectives on the same entity

!"# $%&'&(%')*+'+,-

(.%)/

'/,)+

0#+%0##

1220

0%(.

Orthogonal regions

State modeling -- Luciano García-Bañuelos 13

  Combine multiple simultaneous descriptions

!"# $%&'&(%')*+'+,-

(.%)/

'/,)+

0#+%0##

1220

0%(.

!"#$%

&%'$(

)*(#)**

+,,)

)#!"

-.* /#0&0!#&$1(&('2

Parallelism in Statecharts

State modeling -- Luciano García-Bañuelos 14

  All mutually orthogonal regions detect the same events and respond to them “simultaneously”   usually reduces to interleaving of some kind

!""#

#$%&

!"#$%&'

'()*+,-*-./ 0$1*1%$*+,-*-./

+*234$5$1)

".-+*2

!"#$%&'

Synchronization

State modeling -- Luciano García-Bañuelos 15

  Concurrent orthogonal regions/states can be synchronized by transition guards

!

"

!"#$%&'(&)#

# *

%

)

+

$ $

This transition can only be fired when A.C is in M state

Splitting of control: Forks

State modeling -- Luciano García-Bañuelos 16

  Forks allow to split the control into concurrent paths   It ensures the concurrent activation of state activities

  Note that the control paths are synchronized implicitly, i.e. completion transitions

!"##$%&'(

)*+,)$-("%-"./-012

)*+,"3"4#./5)12

"6$##$%&

!"#$%

7"/)89*7"-"#

Merging of control and exceptions

State modeling -- Luciano García-Bañuelos 17

  UML provides a notation for specifying the merging of control in a explicit way

  Note that the escaping branch is similar to raising an exception

!"#$%&&'()

*%"'+,'()--

#.

"%$%'!/0%(/

&%(/ $#(+'"1%2

!"#$

'(3"#45%1

!%"&'"#$

&6'!!'()

$67")'()

Class aggregation and their state diagrams

State modeling -- Luciano García-Bañuelos 18

  A state diagram is a collection of state diagrams   Class aggregation will

usually require to combine the state diagrams of all parts

  The whole can be thought as a set of orthogonal regions

top related