PowerPoint-presentatie

Download Report

Transcript 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, say, as a plug-in in
Photoshop, or
•warn when one of the pens is about to run out, or
•train users to handle a 4-color ballpoint, or
•specification of a Photoshop plugin
3
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Running example: 4-color ballpoint pen
Is my 4CP ready for
writing ?
this pen
in or out?
What is the inkIslevel
in this
Step 1: conceptual model with properties:
pen (in percentile, so: level=0 means: ink
myPen:
fourCPen;
between 0.00
and 0.01 of maximum)?
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
intuition: describe a process by
relating states (=‘freezes’ or
‘snapshots’) of the system
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     
•State = all properties in
the conceptual model
with their values
Green pen is out;
•State space = the
collection of all states
•A behavior = a route
Green pen is out;
through statespace
other three pens
are in; green pen
•A process = the contains some ink
collection of behaviors of
Red pen is out;
a system
other three pens
Red pen is out;
are in; red pen
other three pens
contains some ink
are in; red pen
contains some ink
All four pens are in
Blue pen is out;
and contains some ink
other three pens
are in; blue pen
contains some ink
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     
•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 = collection of
behaviors of a system
•Examples from real life:
• parking garage: 1080 states
• after some approximations: 3.3 x 106 states
8
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 = collection of
behaviors of a system
•With n quantities, each assuming 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}];
red.level
green.level
blue.level
black.level
red.inOut
green.inOut
blue.inOut
black.inOut
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 …
Is this really necessary ??
10
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Let us look at individual
properties:
use is relevant
level is not relevant (not visible)
inOut is relevant … depends on
purpose
11
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Let us look at individual
properties:
use is relevant
level is not relevant (not visible)
inOut is relevant … depends on
purpose
make use an exposed quantity
make level a hidden quantity
make inOut exposed if color of a
pen matters; otherwise hidden
use is true if a pen p with
p.level>0 has p.inOut=out
12
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
•Partial remedy to decrease
amount of states: distinguish
exposed and hidden quantities or
values, and focus on the exposed
ones
• Exposed quantities or values:
externally visible or accessible
• Hidden quantities or values: internal
behaviour, may help explaining
seemingly uncausal exposed
behavior
13
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
•Partial remedy to decrease
amount of states: distinguish
exposed and hidden quantities or
values, and focus on the exposed
ones
• Which quantities need exposure:
depends on purpose of the model
• Which quantities may be hidden: as
much as possible to simplify model
14
A Core Course on Modeling
Week 3- Time for Change
Assume that
initially
there is one

 Introduction
to Processes     
pen out
Example: 4-color pen
15
The simplest process description contains merely two states,
only involving the most crucial exposed quantity: ‘use’:
myPen.use=TRUE
writing
myPen.use=FALSE
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Example: 4-color pen
The 2-state model is presumably too naive:
• does not take into account that a pen must be
out to write
• does not take into account that only one pen
can be out at a time
• does not take into account that ink only
decreases if a pen is out
need to denote a process without having to resort
to full state space
16
A Core Course on Modeling
state: red pen is out; no
state:
red3-pen
is out;
Week
Time
for Change
ink left in red pen
level>0 in red pen
     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
red pen, running out of ink: only
green.level>0
possible
when
out
red.inOut=in
black.level=0
green.inOut=in
clicking red pen, level>0
,
blue.inOut=in
in and out
black.inOut=in
black.inOut=out
black.level>0
clicking red pen, with no
green.inOut=out
ink, in and out
green.level=0
state: all pens are in (say
blue.inOut=out
blue.inOut=out
nothing about ink levels)
blue.level>0
blue.level=0
17
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
18
This
model behaves like a true 4Denote state and state transitions:
statechart
color ballpoint:
Using projection,
we
red.inOut=out
red.inOut=out
reduced multiple
states
red.level>0
red.level=0
• shows how eventually, every
with irrelevant differences
pen.level will become 0
black.inOut=out
green.inOut=out
to only one state
black.level=0
red.inOut=in
green.inOut=in
blue.inOut=in
black.inOut=in
black.inOut=out
• shows how ingreen.level>0
the use=FALSE
state, we can only click empty
pens in and out
green.inOut=out
• never more than 1 pen is out.
green.level=0
black.level>0
blue.inOut=out
• of the 16000000 states, we
blue.inOut=out
projected out only 9 relevant ones
blue.level=0
blue.level>0
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Projection: one conceptual model  different statecharts,
depending on the choice for exposed quantities
red.inOut=out
black.inOut=
out
Purpose: just clicking
behavior is interesting
red.inOut=in
green.inOut=in
blue.inOut=in
Only exposed
quantities are the
‘inOut’ properties
blue.inOut=out
black.inOut=in
green.inOut=out
19
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
20
Projection: one conceptual model  different statecharts,
depending on the choice for exposed quantities
red.level>0
Purpose: warn user
when pen runs out
Only exposed
quantities are the
level properties
None of the simplified
red.level=0 statecharts shows relations
between ‘level’ and ‘inOut’
green.level>0
Carefully select exposed
green.level=0 quantities. Balance
simplicity  expressive
power (given the purpose)
blue.level>0
blue.level=0 Advanced: hierarchical
states, conditional
transitions, orthogonal
regions
black.level>0
black.level=0
(see lecture series ‘process
modeling’)
A Core Course on Modeling
Week 3- Time for Change
     Introduction to Processes     
Now we have a state chart model. So
what?
•predict: see when/if a particular state occurs
(or: a state with a certain property), or examine
the properties of a given (future) state
•specify: give desired properties of some final
state
•verify: check that a certain state cannot occur
•analyse if there no are deadlocks (=dead end
routes)
•analyse if states that should be reached can be
reached
•analyse if states that should be reached in
some order are reached in that order
•analyse if occurring transitions are permitted
(while monitoring a system)
21
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Flavours of time
•Transitions happen instantaneous (take no time)
•States may last
•States and Transitions alternate
22
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Flavours of time
•partial order
for zero or more pairs of transitions T1, T2, you can specify
or verify earlier(T1,T2) or later(T1,T2)
application: specification or verification – e.g.,
manufacturing, control, parallel calculations, …
•total order
for all pairs of transitions T1, T2, you can determine earlier
(T1,T2) or later(T1,T2)
application: prediction or documentation (logging) – e.g.,
physics, material engineering, …
23
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Flavours of time
example of partial order:
specify coin operated vending machine:
ealier(insertCoin,giveProduct)
earlier(makeChoice,giveProduct)
earlier(insertCoin,giveChange)
earlier(makeChoice,giveChange)
earlier(giveProduct,giveChange) ?
earlier(giveChange,giveProduct) ?
these transitions are not ordered
 no total order
24
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Flavours of time (applications)
•partial order
specification or verification – see earlier sheets
•total order
time table problems, scheduling, games,
protocols, …
•total order + equal intervals
compound interest, clocks with counting
mechanism (pendulum, tuning fork and
electronic clocks)
•total order + infinitesimal intervals
lumped physical quantities (not fundamental physics!)
25
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
26
Causality forbids that something depends on its
future.
Any quantity’s value in the current state can only
depend on the previous state(s):
Qcurr=F(Qprev,Pprev)
Since dependency works from ‘previous’ to
‘current’, Qprev and Pprev have no dependence on
Qcurr.
So we won’t have Qcurr=F(Qcurr,…)
If we stick to these rules, we can
straightforwardly evaluate F for each of the
quantities Q, and the order of evaluation doesn’t
matter.
Various forms of perpetuum
mobiles assume some
circular causality.
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
27
Causality forbids that something depends on its
future.
Any quantity’s value in the current state can only
depend on the previous state(s):
Qcurr=F(Qprev,Pprev)
Since dependency works from ‘previous’ to
‘current’, Qprev and Pprev have no dependence on
Qcurr.
So we won’t have Qcurr=F(Qcurr,…)
F is called a recursive function: it calculates Q
taking an earlier value of Q as argument.
… so let’s look at some
examples
Various forms of perpetuum
mobiles assume some
circular causality.
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Arbitrary intervals: consider a leisure sports
event:
•a 20 km march route;
•15 control posts, to be visited in right order
(no shortcuts!  total order, no partial order!!!)
•every post features a box full of bananas
•a list of ‘efforts’ (kCal) between subsequent
posts (uphill, downhill, rough road, …), {Ei}
•question: at which posts should you pick
banana(s) (each containing B kCal)?
28
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Arbitrary intervals: consider a leisure sports
event:
Qi=amount of kCal in stomach at post i, i > 0
Q0=amount of kCal in stomach at start
Qi+1=Qi-Ei if you don’t eat
max(0,…):
… : rounding
you can’t
up:eat
you
a don’t
Qi+1=Qi-E
i+niB if you eat n bananas at post i
negative
want to
amount
eat a fraction
of bananas
of a
What is ni? Answer: ni should be such that Qi+1>0,
banana
and as small as possible (weight!)
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)
29
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Equal intervals: a mass-spring
t  i
system. From physics, we know K=ma
order of K(t)  K
-v and a=u’’.
where K=C(urest-u)Remember:
i
evaluation F1, F2 is
Write v=u’, then a=v’.
irrelevant
u(t)  ui
Here, K=K(t), u=u(t). Let us
approximate by sampling. For  0: u’(t)  (u(t+)-u(t))/ = (u -u )/
i+1 i
So again Qcurr=F(Qprev,Pprev):
ucurr=F1(uprev,vprev)=uprev+vprev
vcurr=F2(vprev,uprev)=
=vprev+( C(urest-uprev)-vprev) /m,
with suitable u0 and v0
v’(t) (v(t+)-v(t))/ = (vi+1-vi)/
u(t+)=
So ui+1= ui+vi
=u(i+)
vi+1= vi+ai =
=u((i+1))
= vi+Ki/m =
=ui+1,
= vi+ (C(urest-ui)-vi) /m
and similar for v
30
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Equal intervals: a mass-spring
WARNING:
31
t  i
system. From physics, we know K=ma
where K=C(urest-u) -v and a=u’’.
K(t)  Ki
Write
a=v’.same as =small. The substitutions for u’(t)
  v=u’,
0 is then
not the
u(t)
we
ui saw in the previous
and
v’(t)
are
approximations
only.
As
Here, K=K(t), u=u(t). Let us
approximate
by sampling.
For  0:
sampling example,
aliasing
errors
are
when =the
u’(t)
worse
(u(t+)-u(t))/
(ui+1-ui)/
sampled signal changes rapidly, compared to the sampling
v’(t) (v(t+)-v(t))/ = (vi+1-vi)/
So
again
Q
=F(Q
,P
):
curr
prev
prev
rate.
ucurr=F1(uprev,vprev)=uprev+vprev
So ui+1= ui+vi
Concrete: unless  is much smaller than the period of the
vi+1= vi+ai =
vcurr=F2(vprev,uprev)=
oscillation (=m/C), the approximations are bad – with the risk
= vi+Fi/m =
of =v
instability.
prev+( C(urest-uprev)-vprev) /m,
with suitable u0 and v0.
= vi+ (C(urest-ui)-vi) /m
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
Infinitesimal intervals: the massspring system revisited. From physics,
we know K=ma where K=C(urest-u) and
a=u’’.
Sometimes, the numerical solution
(sampling) is not acceptable – given
the purpose
Interested in outcome?  use better
numerical methods
Interested in insight?  try to use
symbolic methods, i.e.: analysing
differential equations
Only possible in very few special cases
In particular: linear (sets of) DE’s.
32
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
By
substituting uintervals:
= Aet intothe massInfinitesimal
With damping:
spring system revisited. From physics,
werest
know
K=ma where
K=C(urest-u) and
C(u
-u)-u’=mu’’
and using
a=u’’.
try u=urest+Aet,
u’=Aet; u’’=A2et.
then C++m2=0, or
Here, K=K(t), u=u(t). Let us try a
solution
the
t)-form
C(u
-u of
-Ae
Aet=mA2et
rest
u=u
rest
+A sin(t/T)
33
1,2=(- (2-4mC))/2m
Mustrest
hold for any t, so indeed
Let 0=(4mC).
u’’= -AT-2sin(t/T)
2
C +  + m =0
For  = 0 critical damping;
Substitute back:
for  < 0 oscillations; T=T0/(1- ( /0)2)
-mAT-2sin(t/T)=C(urest-urest-Asin(t/T),
for  > 0 super critical damping
mT-2=C, or T= m/C ( =:T0)
(further details: lectures ‘dynamical systems
A Core Course on Modeling
Week 3- Time for Change
     Summary     
34
From purpose, propose clever exposed and hidden variables
From purpose, determine what time-concept you need: partial order or total
order
If total order: unknown or known intervals? What determines (sampling) intervals?
If emphasis on verification or specification: consider statecharts and process
models
If emphasis on simulation or prediction: use Qcurr=F(Qprev,Pprev)
interested in outcomes? 
use simplest possible numerical techniques,
be aware for accuracy (perhaps decrease   performance !!)
interested in insight? 
try symbolic methods
 is (close to) 0, we get the
A Core Course onIfModeling
Week 3- Time for Changeoriginal samples; if  is closer
to 1, Qi+1 is more similar to Qi,
     Time and State

so noTransitions
fast changes in
Q:
frequencies
are
Equal intervals: playing a CD.higher
Sound on
a CD is represented
as a
low-pass filtering
series of 44100 samples/sec ofreduced:
the amplitude.
Playing the sound: take a sample Pi
Do a calculation to process the sound (e.g., Qi+1=Qi+(1-)Pi)
Next, output Qi+1 to the speaker. So again Qi+1=F(Qi,Pi)
35
A Core Course on Modeling
Week 3- Time for Change
     Time and State Transitions    
36
Equal intervals: playing a CD. Sound
on a CD
is represented
as a a
A remedy
to aliasing,
is to apply
series of 44100 samples/sec of thelow-pass
amplitude.
filter on the input signal. This
Playing the sound: take a sample Pisi also a dynamic system of the form
Qcurr=F(Qprev,Pprev) (details fall beyond the
Do a calculation to process the sound
(e.g.,
i+1=Qi+(1-)Pi)
scope
of thisQlecture)
Next, output Qi+1 to the speaker. So again Qi+1=F(Qi,Pi)
the reconstructed signal
samples taken every 1/44100 sec
original sound
The reconstructed sound will contain a pitch that was not
present initially!! (sampling  aliasing)
A Core Course on Modeling
Week 3- Time for Change
     Summary     
37
•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 behavior;
•
equal intervals: closed form evaluation (e.g.,: periodic financial transactions
sampling);