18.01.2013 Views

Probabilistic And Stochastic UML Statecharts - Software Modeling ...

Probabilistic And Stochastic UML Statecharts - Software Modeling ...

Probabilistic And Stochastic UML Statecharts - Software Modeling ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Probabilistic</strong> <strong>And</strong> <strong>Stochastic</strong><br />

<strong>UML</strong> <strong>Statecharts</strong><br />

Speaker: Abdallah Salim<br />

Tutor: Dr. David N. Jansen<br />

Chair for <strong>Software</strong> <strong>Modeling</strong> and Verification<br />

RWTH Aachen, Germany<br />

SS 2007


Overview<br />

An introduction to <strong>Statecharts</strong><br />

StoCharts<br />

Syntax<br />

Semantics<br />

Case Study: A Beverages dispenser<br />

Conclusion<br />

2


The <strong>UML</strong> perspective - A scenario<br />

Name: Mr Troy aka Mr T<br />

Age: 29<br />

Position: <strong>Software</strong> Engineer<br />

T<br />

T seems to have an idea !<br />

3<br />

Name: Mr McNamara aka Mr M<br />

Age: 27<br />

Position: Visual designer<br />

M


The <strong>UML</strong> perspective - Getting the message across<br />

Mr. T has a great<br />

design idea<br />

What do<br />

you think<br />

M ?<br />

T M<br />

***<br />

but ...<br />

4<br />

Mr. M doesn’t seem to<br />

understand T’s design<br />

What is<br />

that T ?


Mr. T has an idea in<br />

his head<br />

***<br />

The <strong>UML</strong> perspective - The Problem<br />

T<br />

***<br />

but ...<br />

5<br />

Mr. M forms a<br />

completely different<br />

one in his head<br />

M<br />

ooo<br />

This is ...<br />

NOT good


Mr. T redesigns with<br />

<strong>UML</strong>....<br />

<strong>UML</strong><br />

The <strong>UML</strong> perspective - Enter <strong>UML</strong><br />

T<br />

Ok what<br />

about this ?<br />

<strong>UML</strong><br />

Why does Mr M get<br />

it ?<br />

<strong>UML</strong> provides a<br />

Lingua franca that<br />

promotes<br />

communication<br />

between designers<br />

Lingua franca =<br />

Common Language<br />

6<br />

I see it<br />

now !<br />

Mr. M gets it !!!<br />

M<br />

<strong>UML</strong>


Introducing StoCharts - An Intuition<br />

StoChart Example: 6 wins the game<br />

5/6 / player.not six<br />

Rolling<br />

End of roll<br />

P<br />

Won<br />

after(EXP[3sec])<br />

/ player.stop rolling<br />

1/6 / player.six<br />

7<br />

(1) Dice starts rolling<br />

(takes some time to stop:<br />

3 sec)<br />

(2) Nondeterministic choice<br />

- Dice cannot be read<br />

- Dice can be read<br />

(3) <strong>Probabilistic</strong> choice<br />

- {1,2,3,4,5} face-up<br />

(start rolling again)<br />

- 6 face-up<br />

(game over)<br />

⊥<br />

: No need to wait to take edge


=><br />

Some Distinctions - <strong>Probabilistic</strong> choice<br />

(Example: Throwing a fair coin)<br />

<strong>Probabilistic</strong> choice:<br />

It is not clear which possibility out of a discrete set a<br />

system may take.<br />

So what does “not clear” mean ?<br />

- Prediction: 50% of the time heads/tails will<br />

occur.<br />

- BUT impossible to predict the actual outcome for<br />

each toss i.e., whether it’s a head or a tail.<br />

8


=><br />

Some Distinctions - <strong>Stochastic</strong> timing<br />

(Example: Video Streaming)<br />

Client<br />

Video displayed<br />

Video request<br />

Stream<br />

buffered<br />

<strong>Stochastic</strong> timing ?<br />

- Some time needed to schedule video packets (server).<br />

- Some time for video to be displayed (client).<br />

9<br />

Webserver<br />

Scheduling of video<br />

packets


Some Distinctions - <strong>Probabilistic</strong> vs (non)<br />

deterministic Phenomena<br />

<strong>Probabilistic</strong> (Examples: Weather predictions - Probability of<br />

rain, snow etc; Rolling of dice in a board game)<br />

Deterministic (Example: Forced moves in chess)<br />

Nondeterministic (Examples: Free moves in chess and Tic Tac<br />

Toe)<br />

10


Some Distinctions - Non/Not determinism<br />

Nondeterministic Not determinstic<br />

Not deterministic Phenomena<br />

Only infers that a phenomenon is either probabilistic or<br />

nondeterministic (and nothing more !!)<br />

An unfortunate terminology but<br />

one we have to live with :-(<br />

11


Some Distinctions - System vs Environment randomness<br />

Environment randomness<br />

Environment randomness (Example: Reactive system - Bank<br />

ATM, Dispenser, etc)<br />

Intuition: System exposed to external random stimuli and<br />

reacts.<br />

System reaction is NOT random<br />

12


Some Distinctions - System randomness<br />

Requirement : Modems must transmit on different frequencies<br />

modem 1 modem 2<br />

Notation:<br />

- Hj : “Heads” for modem j (1


Overview<br />

An introduction to <strong>Statecharts</strong><br />

StoCharts<br />

Syntax<br />

Semantics<br />

Case Study: A Beverages dispenser<br />

Conclusion<br />

14


=><br />

=><br />

<strong>UML</strong> Extensions - P-<strong>Statecharts</strong> & StoCharts<br />

We can extend <strong>UML</strong> <strong>Statecharts</strong>: 2 fold Extension<br />

Extension 1: <strong>Probabilistic</strong> choice<br />

(Example: Heads/Tails choice on a coin toss)<br />

Extension 2: <strong>Stochastic</strong> timing<br />

(Example: Timing in a Drink dispenser)<br />

<strong>Statecharts</strong> + Extension 1<br />

= <strong>Probabilistic</strong> <strong>Statecharts</strong> (aka P-<strong>Statecharts</strong>)<br />

<strong>Statecharts</strong> + Extension 1 + Extension 2<br />

= <strong>Stochastic</strong> <strong>Statecharts</strong> (aka StoCharts)<br />

15


<strong>UML</strong> Extensions - Random probability<br />

distributions<br />

DET [x min]<br />

A deterministic distribution with a duration of x minutes<br />

EXP [x min]<br />

A negative exponential distribution with a mean of x minutes<br />

UNIF [x min, y min]<br />

A uniform distribution in the interval from x to y minutes<br />

16


1.00<br />

0.75<br />

0.50<br />

0.25<br />

0<br />

<strong>UML</strong> Extensions - Random probability<br />

Prob. DET[5min]<br />

Discrete<br />

function<br />

0 1 2 3 4 5 6 7 8 9 10 11 12<br />

Prob.<br />

1.00<br />

0.75<br />

0.50<br />

0.25<br />

0<br />

Time [min]<br />

17<br />

Prob.<br />

1.00<br />

0.75<br />

0.50<br />

0.25<br />

0<br />

UNIF[5min,10min]<br />

0 1 2 3 4 5 6 7 8 9 10 11 12<br />

EXP[1min]<br />

0 1 2 3 4 5 6 7 8 9 10 11 12<br />

Time [min]<br />

Time [min]


<strong>UML</strong> Extensions - Statechart relations<br />

In a nutshell ...<br />

<strong>UML</strong> <strong>Statecharts</strong> are<br />

trivial P-<strong>Statecharts</strong><br />

<strong>UML</strong> <strong>Statecharts</strong> +<br />

<strong>Probabilistic</strong> choice =><br />

P-<strong>Statecharts</strong><br />

StoCharts<br />

P-<strong>Statecharts</strong><br />

<strong>UML</strong><br />

<strong>Statecharts</strong><br />

18<br />

<strong>UML</strong> <strong>Statecharts</strong> are<br />

trivial StoCharts<br />

P-<strong>Statecharts</strong> +<br />

<strong>Stochastic</strong> timing =><br />

StoCharts


Overview<br />

An introduction to <strong>Statecharts</strong><br />

StoCharts<br />

Syntax<br />

Semantics<br />

Case Study: A Beverages dispenser<br />

Conclusion<br />

19


A syntactical perspective - StoChart drawing<br />

Nodes<br />

C<br />

A<br />

B A<br />

Parent node C encloses its<br />

children A, B<br />

(Default node: A)<br />

20<br />

A C<br />

B E D<br />

F (AND) node partitioned by (OR)<br />

children A and C<br />

(Default nodes: B,D)<br />

F


A syntactical perspective - StoChart drawing<br />

Trivial P-edges<br />

X e[g]/A Y<br />

Verifying<br />

User<br />

X : Set of source nodes<br />

Y : set of target nodes<br />

e : event<br />

g : guard<br />

A : action set<br />

Here: Actions “A” have the form (send) j.e (send event e to the<br />

external component identified by j)<br />

Example (Router Login)<br />

Check password[password=”admin”]<br />

/User.Logged in<br />

21<br />

Showing<br />

Admin Page


A syntactical perspective - StoChart drawing<br />

Non trivial P-edges<br />

e[g]/<br />

X P<br />

Example (File downloading)<br />

Checking<br />

origin<br />

p/A<br />

Check country/<br />

.<br />

.<br />

.<br />

22<br />

R<br />

p’/A S p=p’ is also possible<br />

0.4/downloader.UK<br />

servers available<br />

P<br />

0.6/<br />

downloader.USA<br />

servers available<br />

X : Set of source nodes<br />

Y : set of target nodes<br />

e : event<br />

g : guard<br />

A : action set<br />

p,p’: Probabilities<br />

Showing<br />

UK<br />

Server 1<br />

Showing<br />

USA Server<br />

7


A syntactical perspective - System Perspective<br />

- Intuition: A system is a finite collection of<br />

intercommunicating StoCharts<br />

- Formally: Denotable by the set seen below.<br />

{SC i |1 ≤ i ≤ n,n ∈N}<br />

23


StoChart 4-Tuple<br />

Nodes i<br />

Events i<br />

Vars i<br />

PEdges i<br />

A syntactical perspective - StoChart<br />

SC i = (Nodes i,Events i,Vars i,PEdges i )<br />

A finite set of nodes structured in a tree<br />

A finite set of events<br />

A finite set of local variables<br />

A finite set of P-edges<br />

24


A syntactical perspective - StoChart Events<br />

SC i = (Nodes i,Events i,Vars i,PEdges i )<br />

A finite set of events (Signals that may trigger a state transition)<br />

pseudo event after(F) - stochastic random delays<br />

⊥∉Events i<br />

PSEvents i<br />

No event is required to trigger a P-edge<br />

Set of Pseudo events<br />

25


A syntactical perspective - StoChart Variables<br />

SC i = (Nodes i,Events i,Vars i,PEdges i )<br />

- Intuition: A finite set of local variables with an initial<br />

value that assigns initial values to variables<br />

- Formally: Denotable by the function below<br />

V 0 :Vars i → Z<br />

26


A syntactical perspective - StoChart P-edges<br />

P-edge 4-Tuple (X,e, g, P)<br />

A finite set of P-edges<br />

X ⊆ Nodes i<br />

e ∈Events i ∪ PSEvents i ∪ {⊥}<br />

g ∈Guards i<br />

A non-empty set of source state nodes<br />

27<br />

Triggering event that occurs<br />

A guard existing on the edge<br />

P denotes the possible actions and target state nodes (formal<br />

description needed)


A syntactical perspective - StoChart P-edges<br />

A formal description of P<br />

(X,e, g, P)<br />

P can be formally described by a probability measure in a discrete<br />

probability space<br />

Pow<br />

(Pow(Actions i ) × (Pow(Nodes i ) − {∅}), P)<br />

: Denotes a Power set<br />

28<br />

Ω<br />

Denoting the set of possible outcomes


A syntactical perspective - StoChart scopes<br />

Intuition: The scope of a P-edge is the smallest (in the parent-child<br />

hierarchy) OR-node containing both the source nodes and the target<br />

nodes<br />

H<br />

F<br />

E D<br />

A B<br />

C<br />

G<br />

29<br />

Scope(A->H) = root<br />

Scope(A->D) = G<br />

Scope(A->B) = C


Overview<br />

An introduction to <strong>Statecharts</strong><br />

StoCharts<br />

Syntax<br />

Semantics<br />

Case Study: A Beverages dispenser<br />

Conclusion<br />

30


IOSA 7-Tuple (L,l 0 ,T , A, I,O,Δ)<br />

L<br />

T<br />

A<br />

A semantical perspective - Automaton approach<br />

I<br />

O<br />

Δ<br />

A set L of locations with an initial location<br />

A set of timers (each possessing a cdf)<br />

An input transition relation<br />

A probabilistic output transition<br />

relation<br />

A delay transition relation<br />

31<br />

IOSA =<br />

<strong>Stochastic</strong> I/O-<br />

Automaton<br />

l 0 ∈L<br />

A set of actions partitioned into input-actions<br />

(from external environment) and output-actions (system intrinsic)


A semantical perspective - Automaton approach<br />

IOSA 7-Tuple (L,l 0 ,T , A, I,O,Δ)<br />

I<br />

An input transition relation<br />

I : L × A in → L<br />

32


A semantical perspective - Automaton approach<br />

IOSA 7-Tuple (L,l 0 ,T , A, I,O,Δ)<br />

O A probabilistic output transition relation<br />

O ⊆ L × P(A out × Pow(T ) × L)<br />

33


A semantical perspective - Automaton approach<br />

IOSA 7-Tuple (L,l 0 ,T , A, I,O,Δ)<br />

Δ<br />

A delay transition relation<br />

Δ ⊆ L × T × L<br />

34


A semantical perspective - Enabled Transitions<br />

IOSA 7-Tuple<br />

Transition<br />

o<br />

i<br />

d<br />

(L,l 0 ,T , A, I,O,Δ)<br />

35<br />

Enabled<br />

Always<br />

Only if Input action present<br />

(Input enabledness)<br />

Only if<br />

timer expires (reaches zero)<br />

o: output transition<br />

i: input transition<br />

d: delay transition


ATM request<br />

allow or deny<br />

withdraw<br />

A semantical perspective - IOSA example<br />

-> i<br />

i<br />

Bank<br />

o: output transition, i: input transition<br />

d: delay transition<br />

output transitions always enabled !<br />

input transition enabled<br />

i:request<br />

Idle<br />

i<br />

:request<br />

timer set timer has expired<br />

1<br />

Preparing o: set t Checking d:t<br />

Check<br />

t<br />

to check<br />

finished<br />

timeout ?<br />

i:withdraw<br />

i:withdraw<br />

Error<br />

i:withdraw<br />

i:withdraw<br />

o:<br />

No withdraw without<br />

positive verification !<br />

i:withdraw<br />

36<br />

Bank behavior being modeled !<br />

0.02, deny<br />

<strong>Probabilistic</strong> choice<br />

0.98, allow<br />

Check<br />

positive


Overview<br />

An introduction to <strong>Statecharts</strong><br />

StoCharts<br />

QoS Extensions<br />

Syntax<br />

Semantics<br />

Case Study: A Beverages dispenser<br />

Conclusion<br />

37


How does it work ?<br />

Drinks offered ?<br />

“Espresso” coffee and<br />

“oolong” tea.<br />

Payment ?<br />

A beverage dispenser - Intuition<br />

Money chips - 1 Chip<br />

per drink.<br />

38


A beverage dispenser - <strong>Modeling</strong> perspective<br />

What are we modeling ?<br />

The behavior of the system (system randomness), as seen<br />

by the customer.<br />

What we are not modeling<br />

The expected/desired behavior of the customer<br />

(environmental randomness) is NOT being considered here.<br />

39


A naive <strong>UML</strong> Statechart - Events<br />

Events are sent from the<br />

customer to the HBD.<br />

insert chip.<br />

select espresso.<br />

select oolong.<br />

HBD = Hot Beverages Dispenser<br />

40


select Espresso/<br />

customer.brew<br />

espresso<br />

A naive <strong>UML</strong> Statechart - Closer look<br />

Waiting<br />

for chip<br />

insert chip/<br />

Waiting<br />

for beverage selection<br />

HBD - Hot<br />

Beverages<br />

Dispenser<br />

select Oolong/<br />

customer.brew<br />

oolong<br />

41<br />

insert chip/:<br />

Intuition: In the event of a<br />

chip being inserted, the<br />

system evolves to its next<br />

state<br />

select oolong/customer.brew<br />

oolong:<br />

Intuition: In the event that<br />

oolong is selected, send the<br />

event “brew oolong” to the<br />

customer<br />

Analog for espresso


An improved <strong>UML</strong> Statechart - Closer look<br />

What’s wrong with our naive design ?<br />

Incomplete - Drinking<br />

what we paid for ?<br />

Completing the model<br />

“Placing” of cups in<br />

cup holder<br />

“Filling” of the cups<br />

“waiting” for<br />

someone (not a<br />

system) to remove<br />

the cup<br />

42<br />

remove cup/<br />

select Espresso/<br />

customer.brew<br />

espresso<br />

Filling cup<br />

with espresso<br />

cup full/customer.<br />

notify drink ready<br />

Waiting<br />

for chip<br />

Placing cup<br />

insert chip/<br />

Waiting for cup<br />

to be removed<br />

Improved<br />

HBD (IHBD)<br />

select Oolong/<br />

customer.brew<br />

oolong<br />

Filling cup<br />

with oolong<br />

cup full/customer.<br />

notify drink ready


Extending <strong>UML</strong> <strong>Statecharts</strong> - <strong>UML</strong> Limitations<br />

Limitations of the IHBD<br />

<strong>Modeling</strong> system<br />

requirements ?<br />

(1) No cups => coin<br />

returned to customer<br />

(2) Return a chip<br />

exactly after 10 seconds<br />

(“timeout”)<br />

(3) Brewing takes about<br />

5 seconds (“timeout”)<br />

Realisation: Impossible to model our<br />

requirements without extensions !!!<br />

43<br />

remove cup/<br />

select Espresso/<br />

customer.brew<br />

espresso<br />

Filling cup<br />

with espresso<br />

cup full/customer.<br />

notify drink ready<br />

Waiting<br />

for chip<br />

Placing cup<br />

insert chip/<br />

Waiting for cup<br />

to be removed<br />

Improved<br />

HBD (IHBD)<br />

select Oolong/<br />

customer.brew<br />

oolong<br />

Filling cup<br />

with oolong<br />

cup full/customer.<br />

notify drink ready


Extending <strong>UML</strong> <strong>Statecharts</strong> - <strong>Modeling</strong> requirements<br />

Requirements to be modeled<br />

(1) No cups => coin returned<br />

to customer<br />

(2) Return a chip exactly<br />

after 10 seconds<br />

(“timeout”)<br />

(3) Brewing takes about 5<br />

seconds (“timeout”)<br />

44<br />

1<br />

2<br />

3<br />

IHBD extended<br />

(probabilistic choice &<br />

stochastic timing)<br />

“<strong>Probabilistic</strong> choice”<br />

Enough cups vs not enough cups<br />

“<strong>Stochastic</strong> timing”<br />

after(DET [10s] ) /<br />

customer.return chip<br />

“<strong>Stochastic</strong> timing”<br />

after(EXP [5s] ) /<br />

customer.notify drink ready


Extending <strong>UML</strong> <strong>Statecharts</strong> - Birth of a StoChart<br />

Requirements to be modeled<br />

(1) No cups => coin<br />

returned to customer<br />

(2) Return a chip<br />

exactly after 10<br />

seconds (“timeout”)<br />

(3) Brewing takes<br />

about 5 seconds<br />

(“timeout”)<br />

(1)<br />

(2)<br />

(3)<br />

45<br />

<strong>Stochastic</strong> IHBD (S-IHBD)<br />

select Espresso/<br />

customer.brew<br />

espresso<br />

0.8/<br />

Filling cup<br />

with espresso<br />

after (EXP[5 s])/<br />

customer.<br />

notify drink ready<br />

Waiting<br />

for chip<br />

Placing cup<br />

insert chip/<br />

Waiting for cup<br />

to be removed<br />

0.2/<br />

P<br />

Out of cups<br />

after(DET[10s] /<br />

customer.return chip<br />

select Oolong/<br />

customer.brew<br />

oolong<br />

Filling cup<br />

with oolong<br />

after (EXP[5 s])/<br />

customer.<br />

notify drink ready<br />

remove cup/<br />

insert chip/<br />

customer.return chip


emove cup/<br />

Extending <strong>UML</strong> <strong>Statecharts</strong> - <strong>Statecharts</strong> compared<br />

select Espresso/<br />

customer.brew<br />

espresso<br />

Filling cup<br />

with espresso<br />

Waiting<br />

for chip<br />

Placing cup<br />

insert chip/<br />

cup full/customer.<br />

notify drink ready<br />

Waiting for cup<br />

to be removed<br />

select Oolong/<br />

customer.brew<br />

oolong<br />

Filling cup<br />

with oolong<br />

IHBD - without extensions.<br />

<strong>Modeling</strong> requirements<br />

involving <strong>Stochastic</strong> behavior<br />

not possible !<br />

<strong>Probabilistic</strong><br />

choice<br />

46<br />

select Espresso/<br />

customer.brew<br />

espresso<br />

0.8/<br />

Filling cup<br />

with espresso<br />

after (EXP[5 s])/<br />

customer.<br />

notify drink ready<br />

Waiting<br />

for chip<br />

Placing cup<br />

insert chip/<br />

Waiting for cup<br />

to be removed<br />

0.2/<br />

P<br />

Out of cups<br />

after(DET[10s] /<br />

customer.return chip<br />

select Oolong/<br />

customer.brew<br />

oolong<br />

Filling cup<br />

with oolong<br />

after (EXP[5 s])/<br />

customer.<br />

notify drink ready<br />

remove cup/<br />

insert chip/<br />

customer.return chip<br />

<strong>Stochastic</strong><br />

timing<br />

S-IHBD (IHBD with<br />

extensions).<br />

<strong>Modeling</strong> requirements<br />

involving <strong>Stochastic</strong> behavior<br />

now becomes possible !!


Overview<br />

An introduction to <strong>Statecharts</strong><br />

StoCharts<br />

QoS Extensions<br />

Syntax<br />

Semantics<br />

Case Study: A Beverages dispenser<br />

Conclusion<br />

47


What have we learnt ?<br />

- Awareness of real <strong>UML</strong> limitations and the need to extend them.<br />

- Extending <strong>UML</strong> <strong>Statecharts</strong> with :<br />

- <strong>Probabilistic</strong> choice (P-<strong>Statecharts</strong>).<br />

- <strong>Stochastic</strong> timing (StoCharts).<br />

- Informal and formal syntax of StoCharts ( with examples ).<br />

- Informal semantics : <strong>Stochastic</strong> Input/Output Automata (IOSA).<br />

- Application of <strong>UML</strong> extensions: Case study of beverage dispenser.<br />

48


Some useful reading<br />

Martin Fowler. <strong>UML</strong> Distilled: A Brief Guide to the<br />

standard Object <strong>Modeling</strong> Language, Third edition.<br />

Addison-Wesley Professional, 3rd edition, 2003.<br />

David N. Jansen. Extensions of <strong>Statecharts</strong> with<br />

Probability, Time, and <strong>Stochastic</strong> Timing. PhD thesis,<br />

Universiteit Twente, Bern, 2003.<br />

Scott Kim. Interdisciplinary cooperation. In Brenda Laurel,<br />

editor, the Art of Human Computer Interface Design,<br />

pages 31-44, Addison Wesley, 1990.<br />

49


Thank you<br />

for your attention !

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!