PowerPoint-presentatie

A Core Course on Modeling
Week 3- Time for Change
     Contents     
• Change needs Time
• Introduction to Processes
•States and State Charts
•Applying State Charts
• Time and State Transitions
•Partially Ordered Time
•Totally Ordered Time
•Totally Ordered Time; Equal Intervals
•Totally Ordered Time; Infinitesimal Intervals
•
Summary
•
References to lecture notes + book
•
References to quiz-questions and homework assignments (lecture notes)
1
A Core Course on Modeling
Week 3- Time for Change
     Contents     
Question:
• how to model systems …
• … that vary over time …
• … such that their behavior
•can be predicted,
•can be specified,
•can be verified,
•can be … ?
2
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Running example: 4-color ballpoint pen
Purpose: the model should …
• simulate a virtual 4-color ballpoint, or
• warn when one of the pens is about to run out, or
• train users to handle a 4-color ballpoint, or
• specificatin of a Photoshop plugin
3
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Running example: 4-color ballpoint pen
Step 1: conceptual model with properties:
myPen: fourCPen;
fourCPen:
[red: pen, green: pen, blue: pen, black: pen,
use: {TRUE,FALSE}];
pen:[level: {0…99}%,inOut: {in,out}]
myPen.use is true if there is a pen p with p.level>0 and p.inOut=out
4
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Describe processes: statecharts
Process = series of states
Red pen is out;
Red pen is out;
All four pens are in
other three pens
other three pens
and contain some ink red pen
are in; red pen
goes out
contains some ink
write
with red
pen
are in; red pen
contains less ink
5
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
•State = all properties in the conceptual model with their values
•State space = the collection of all states
•A behavior = a route through statespace
•A process = the collection of behaviors of a system
6
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Green pen is out;
other three pens
Red pen is out;
are in; red pen
other three pens
contains some ink
are in; red pen
contains some ink
Green pen is out;
other three pens
All four pens are in
Blue pen is out;
are in; green pen
and contains some ink
other three pens
are in; blue pen
contains some ink
contains some ink
Red pen is out;
Red pen is out;
other three pens
All four pens are in
other three pens
are in; red pen
and contain some ink
are in; red pen
contains less ink
All four pens are in
and contain some ink
contains some ink
Red pen is out;
other three pens
are in; red pen
contains no ink
7
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
A real-life example: controlling a parking garage
8
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
•With n quantities, each mi values,
nr states = i=1 … n mi
•Number of behaviors with p steps
= j=1 … p i=1 … n mi
•State and process explosion
9
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
For the 4-color ballpoint,
myPen:fourCPen;
fourCPen: [red: pen,green: pen,
blue: pen,black: pen,
use: {TRUE,FALSE}];
pen: [level:{0…99}%, inOut: {in,out}]
the state space contains
100 x 100 x 100 x 100 x 2 x 2 x 2 x 2
= 1600000000 states
Parking garage: 1080 states (including folded cars!)
10
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Idea: hiding and exposing
quantities or
values
11
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Individual properties:
use is visible
level is not visible
inOut … depends on purpose
make use an exposed quantity
make level a hidden quantity
make inOut exposed if color of a
pen matters; otherwise hidden
12
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
•Decrease amount of states:
•distinguish exposed and hidden quantities or values
•focus on the exposed ones
13
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Example: 4-color pen
Simples process description: just two states
myPen.use=TRUE
writing
myPen.use=FALSE
14
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Example: 4-color pen
The 2-state model is too naive:
• pen must be out to write
• only one pen out at a time
• ink only decreases if a pen is out
15
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Denote state and state transitions: statechart
red.inOut=out
red.inOut=out
red.level>0
red.level=0
black.inOut=out
green.inOut=out
black.level=0
green.level>0
red.inOut=in
green.inOut=in
blue.inOut=in
black.inOut=in
green.inOut=out
black.inOut=out
green.level=0
black.level>0
blue.inOut=out
blue.inOut=out
blue.level=0
blue.level>0
16
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Denote state and state transitions: statechart
red.inOut=out
black.inOut=
out
red.inOut=in
green.inOut=in
blue.inOut=in
black.inOut=in
green.inOut=out
blue.inOut=out
17
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Denote state and state transitions: statechart
red.level>0
red.level=0
green.level>0
green.level=0
blue.level>0
blue.level=0
black.level>0
black.level=0
18
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Now we have a state chart model. So what?
garage model was reduced to
3.3 x 106 states
… and could be analysed by
computer
19
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Now we have a state chart model. So what?
•predict: how will process run?
•specify: desired state, process
•verify: undesired state won’t occur
•analyse: no deadlocks?
•analyse: reachability
•analyse: correct order?
•analyse: only permitted transitions?
20
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Let’s start talking about time.
21
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
transition T1
state S0
state S1
transition T2
transition T3
state S2
state S3
22
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Flavours of time
partial order
for 0 pairs of T1, T2, earlier(T1,T2) or later(T1,T2)
total order
for all pairs of T1, T2, earlier (T1,T2) or later(T1,T2)
23
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Flavours of time
specify coin operated vending machine:
ealier(insertCoin,giveProduct)
earlier(makeChoice,giveProduct)
earlier(insertCoin,giveChange)
earlier(makeChoice,giveChange)
earlier(giveProduct,giveChange) ?
earlier(giveChange,giveProduct) ?
24
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Flavours of time (applications)
partial order
25
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Flavours of time (applications)
total order
for all pairs of T1, T2, earlier
(T1,T2) or later(T1,T2)
26
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Flavours of time (applications)
total order + equal intervals
27
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Flavours of time (applications)
total order + infinitesimal
intervals
28
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Causality:
Qcurr=F(Qprev,Pprev)
Forbidden: Qcurr=F(Qcurr,…)
29
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Causality:
Qcurr=F(Qprev,Pprev)
Forbidden: Qcurr=F(Qcurr,…)
F is a recursive function
30
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Arbitrary intervals
a 20 km march route;
15 control posts;
every post: a box of bananas;
a list of ‘efforts’ (kCal) between posts, {Ei}.
At which posts should you pick banana(s)?
31
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Arbitrary intervals
Qi=amount of kCal in stomach at post i, i > 0
Q0=amount of kCal in stomach at start.
Qi+1 = Qi - Ei (don’t eat);
Qi+1 = Qi – Ei + niB (eat n bananas at post i);
ni such that i, Qi+1 > 0, and as small as possible.
Qi+1 = Qi – Ei + niB; Qi – Ei + niB > 0,
so niB > Ei - Qi; ni = max(0,(Ei - Qi) / B), so
Qi+1 = Qi – Ei + B * max(0,(Ei - Qi) / B) or: Qi+1 = F(Qi,Pi)
32
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Equal intervals
a mass-spring system.
33
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Equal intervals
a mass-spring system.
K = ma
K = C(urest-u)
a = v’
v = u’
t = i
34
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Equal intervals
a mass-spring system.
K = ma
K = C(urest-u)
a = v’
v = u’
t = i
K(t)  Ki
a(t)  (v(t+)-v(t))/ = (vi+1 - vi) / 
v(t)  (u(t+ )-u(t))/ = (ui+1 - ui) / 
35
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Equal intervals
a mass-spring system.
K = ma
K = C(urest-u)
a = v’
v = u’
t = i
K(t)  Ki
a(t)  (v(t+)-v(t))/ = (vi+1 - vi) / 
v(t)  (u(t+ )-u(t))/ = (ui+1 - ui) / 
ui+1 = ui + vi
vi+1 = vi + ai
= vi + K/m
= vi +  C(urest-ui)
/m
36
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Equal intervals
a mass-spring system.
K = ma
K = C(urest-u)
a = v’
v = u’
t = i
37
K(t)  Ki
a(t)  (v(t+)-v(t))/ = (vi+1 - vi) / 
v(t)  (u(t+ )-u(t))/ = (ui+1 - ui) / 
ui+1 = ui + vi
vi+1 = vi + ai
= vi + K/m
= vi +  C(urest-ui)
/m
So Qcurr = F(Qprev, Pprev):
ucurr = F1(uprev,vprev) = uprev+vprev
vcurr = F2(vprev,uprev) = vprev+ C(urest-uprev)
/m, with given u0 and v0
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
38
Equal intervals
a mass-spring system with damping.
K = ma
K(t)  Ki
K = C(urest-u) - v
a(t)  (v(t+)-v(t))/ = (vi+1 - vi) / 
a = v’
v = u’
t = i
v(t)  (u(t+ )-u(t))/ = (ui+1 - ui) / 
ui+1 = ui + vi
vi+1 = vi + ai
= vi + K/m
= vi + (C(urest-ui) - vi ) /m
So Qcurr = F(Qprev, Pprev):
ucurr = F1(uprev,vprev) = uprev+vprev
vcurr = F2(vprev,uprev) = vprev+(C(urest-uprev)-vprev )/m, with given u0 and
v
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Equal intervals
a mass-spring system with damping.
39
39
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Infinitesimal intervals
a mass-spring system with damping.
40
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Infinitesimal intervals
a mass-spring system with damping.
K = K(t), u = u(t), K = C(urest-u) - v.
First try for  = 0:
u = urest+A sin(t/T)
u’’ = -T-2Asin(t/T)
Substitute back:
-mT-2Asin(t/T) = C(urest-urest-Asin(t/T),
mT-2 = C, or T = m/C ( =:T0)
41
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Infinitesimal intervals
a mass-spring system with damping.
K = K(t), u = u(t), K = C(urest-u) - v.
Next try for  0:
u = urest + A et
C(urest-u) - u’ = mu’’ and use u’ = Aet; u’’ = A2et.
C(urest-urest-Aet) - Aet = mA2et . Must hold for any t, so
C +  + m2 = 0, hence 1,2 = (- (2-4mC))/2m
Let 0 = (4mC).
For  = 0 critical damping;
for  < 0 oscillations; T=T0 /(1- (/0)2)
for  > 0 super critical damping
42
A Core Course on Modeling
Week 3- Time for Change
     Summary     
43
Purpose  exposed and hidden variables
Purpose  partial order or total order ?
If total order: unknown or known intervals? What determines (sampling) intervals?
If verification or specification: consider statecharts and process models
If simulation or prediction: use Qcurr=F(Qprev,Pprev)
interested in outcomes? 
use simplest possible numerical techniques,
small : accuracy   large : performance
interested in insight? 
try symbolic methods
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Equal intervals
Playing a CD: a series of 44100 samples/sec.
Playing the sound: take a sample Pi
Process the sound (e.g., Qi+1=Qi+(1-)Pi)
Output Qi+1 to the speaker
Qi+1 = F(Qi,Pi)
44
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Equal intervals
Playing a CD: a series of 44100 samples/sec.
the reconstructed signal
samples taken every 1/44100 sec
original sound
45
A Core Course on Modeling
Week 3- Time for Change
     Summary     
46
•
State = snapshot of a conceptual model at some time point;
•
State space = collection of all states;
•
Change = transitions between states; state chart = graph; nodes (states) and arrows (transitions);
•
Behavior = path through state space;
•
State space explosion: number of states is huge for non trivial cases
•
Projection: given a purpose, distinguish exposed and hidden properties or value sets;
•
Multiple flavors of time:
•
partially ordered time, e.g. specification and verification;
•
totally ordered time, e.g. prediction, steering and control;
•
A recursive function Qi+1 = F(Qi , Qi-1 , Qi-2, …. , Pi , Pi-1 , Pi-2 , …) to evaluate or unroll a behavio
•
equal intervals: closed form evaluation (e.g.,: periodic financial transactions; sampling);
•
equal, small intervals: approximation, sampling error (examples: moving point mass, … );
•
infinitesimal intervals: continuous time, differential equations (examples: mass-spring system)