46
1 A Core Course on Modeling 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) Week 3- Time for Change

A Core Course on Modeling

  • Upload
    abedi

  • View
    35

  • Download
    0

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: A Core Course on Modeling

1

A Core Course on Modeling

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)

Week 3- Time for Change

Page 2: A Core Course on Modeling

2

A Core Course on Modeling

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 … ?

Week 3- Time for Change

Page 3: A Core Course on Modeling

3

A Core Course on Modeling

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

Week 3- Time for Change

Page 4: A Core Course on Modeling

4

A Core Course on Modeling

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

Week 3- Time for Change

Page 5: A Core Course on Modeling

5

A Core Course on Modeling

Describe processes: statecharts

Process = series of states

All four pens are in

and contain some ink

Red pen is out;

other three pens

are in; red pen

contains some ink

Red pen is out;

other three pens

are in; red pen

contains less ink

red pen goes out

write with red pen

Introduction to Processes

Week 3- Time for Change

Page 6: A Core Course on Modeling

6

A Core Course on Modeling

•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

Introduction to Processes

Week 3- Time for Change

Page 7: A Core Course on Modeling

7

A Core Course on Modeling

All four pens are in

and contain some ink

Red pen is out;

other three pens

are in; red pen

contains some ink

Red pen is out;

other three pens

are in; red pen

contains less ink

Green pen is out;

other three pens

are in; green pen

contains some ink

All four pens are in

and contains some ink

Blue pen is out;

other three pens

are in; blue pen

contains some ink

Green pen is out;

other three pens

are in; red pen

contains some ink

Red pen is out;

other three pens

are in; red pen

contains some ink

All four pens are in

and contain some ink

Red pen is out;

other three pens

are in; red pen

contains no ink

Introduction to Processes

Week 3- Time for Change

Page 8: A Core Course on Modeling

8

A Core Course on Modeling

Introduction to Processes

Week 3- Time for Change

A real-life example: controlling a parking garage

Page 9: A Core Course on Modeling

9

A Core Course on Modeling

Introduction to Processes

Week 3- Time for Change

•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

Page 10: A Core Course on Modeling

10

A Core Course on Modeling

Introduction to Processes

Week 3- Time for Change

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!)

Page 11: A Core Course on Modeling

11

A Core Course on Modeling

Introduction to Processes

Week 3- Time for Change

Idea: hidingIdea: hiding and exposing and exposing

quantities orquantities or

valuesvalues

Page 12: A Core Course on Modeling

12

A Core Course on Modeling

make use an exposed quantity

make level a hidden quantity

make inOut exposed if color of a pen matters; otherwise hidden

make use an exposed quantity

make level a hidden quantity

make inOut exposed if color of a pen matters; otherwise hidden

Introduction to Processes

Week 3- Time for Change

Individual properties:

use is visiblelevel is not visibleinOut … depends on purpose

Individual properties:

use is visiblelevel is not visibleinOut … depends on purpose

Page 13: A Core Course on Modeling

13

A Core Course on Modeling

•Decrease amount of states:

•distinguish exposed and hidden quantities or values

•focus on the exposed ones

Introduction to Processes

Week 3- Time for Change

Page 14: A Core Course on Modeling

14

A Core Course on Modeling

Example: 4-color pen

Simples process description: just two states

myPen.use=TRUE myPen.use=FALSEwriting

Introduction to Processes

Week 3- Time for Change

Page 15: A Core Course on Modeling

15

A Core Course on Modeling

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

Introduction to Processes

Week 3- Time for Change

Page 16: A Core Course on Modeling

16

A Core Course on Modeling

Denote state and state transitions: statechart

red.inOut=out

red.level>0

red.inOut=out

red.level=0

green.inOut=out

green.level>0

green.inOut=out

green.level=0

blue.inOut=out

blue.level>0

blue.inOut=out

blue.level=0

black.inOut=out

black.level>0

black.inOut=out

black.level=0

red.inOut=in

green.inOut=in

blue.inOut=in

black.inOut=in

Introduction to Processes

Week 3- Time for Change

Page 17: A Core Course on Modeling

17

A Core Course on Modeling

black.inOut=

out

blue.inOut=out

green.inOut=out

red.inOut=out

red.inOut=in

green.inOut=in

blue.inOut=in

black.inOut=in

Introduction to Processes

Week 3- Time for Change

Denote state and state transitions: statechart

Page 18: A Core Course on Modeling

18

A Core Course on Modeling

red.level>0

green.level>0

blue.level>0

black.level>0

red.level=0

green.level=0

blue.level=0

black.level=0

Introduction to Processes

Week 3- Time for Change

Denote state and state transitions: statechart

Page 19: A Core Course on Modeling

19

A Core Course on Modeling

Now we have a state chart model. So what?

Introduction to Processes

Week 3- Time for Change

garage model was reduced to garage model was reduced to 3.3 x 103.3 x 1066 states states

… … and could be analysed by and could be analysed by computercomputer

Page 20: A Core Course on Modeling

20

A Core Course on Modeling

•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?

Introduction to Processes

Week 3- Time for Change

Now we have a state chart model. So what?

Page 21: A Core Course on Modeling

21

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Let’s start talking about time.

Page 22: A Core Course on Modeling

22

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

state S0

state S1

state S2

state S3

transition T1

transition T2

transition T3

Page 23: A Core Course on Modeling

23

A Core Course on Modeling

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)

Time and State Transitions

Week 3- Time for Change

Page 24: A Core Course on Modeling

24

A Core Course on Modeling

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) ?

Time and State Transitions

Week 3- Time for Change

Page 25: A Core Course on Modeling

25

A Core Course on Modeling

Flavours of time (applications)

partial order

Time and State Transitions

Week 3- Time for Change

Page 26: A Core Course on Modeling

26

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Flavours of time (applications)

total order

for all pairs of T1, T2, earlier (T1,T2) or later(T1,T2)

Page 27: A Core Course on Modeling

27

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Flavours of time (applications)

total order + equal intervals

Page 28: A Core Course on Modeling

28

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Flavours of time (applications)

total order + infinitesimal intervals

Page 29: A Core Course on Modeling

29

A Core Course on Modeling

Causality:

Qcurr=F(Qprev,Pprev)

Forbidden: Qcurr=F(Qcurr,…)

Time and State Transitions

Week 3- Time for Change

Page 30: A Core Course on Modeling

30

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Causality:

Qcurr=F(Qprev,Pprev)

Forbidden: Qcurr=F(Qcurr,…)

F is a recursive function

Page 31: A Core Course on Modeling

31

A Core Course on Modeling

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)?

Time and State Transitions

Week 3- Time for Change

Page 32: A Core Course on Modeling

32

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

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)

Page 33: A Core Course on Modeling

33

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Equal intervals

a mass-spring system.

Page 34: A Core Course on Modeling

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Equal intervals

a mass-spring system.

K = ma K = C(urest-u)

a = v’

v = u’

t = i

34

Page 35: A Core Course on Modeling

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Equal intervals

a mass-spring system.K = ma K(t) Ki

K = C(urest-u) a(t) (v(t+)-v(t))/ = (vi+1 - vi) /

a = v’ v(t) (u(t+ )-u(t))/ = (ui+1 - ui) /

v = u’

t = i

35

Page 36: A Core Course on Modeling

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Equal intervals

a mass-spring system.K = ma K(t) Ki

K = C(urest-u) a(t) (v(t+)-v(t))/ = (vi+1 - vi) / a = v’ v(t) (u(t+ )-u(t))/ = (ui+1 - ui) / v = u’ ui+1 = ui + vi

t = i vi+1 = vi + ai

= vi + K/m

= vi + C(urest-ui) /m

36

Page 37: A Core Course on Modeling

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Equal intervals

a mass-spring system.K = ma K(t) Ki

K = C(urest-u) a(t) (v(t+)-v(t))/ = (vi+1 - vi) / a = v’ v(t) (u(t+ )-u(t))/ = (ui+1 - ui) / v = u’ ui+1 = ui + vi

t = i 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

37

Page 38: A Core Course on Modeling

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

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(t) (u(t+ )-u(t))/ = (ui+1 - ui) / v = u’ ui+1 = ui + vi

t = i 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 v0

38

Page 39: A Core Course on Modeling

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Equal intervals

a mass-spring system with damping.

39

39

Page 40: A Core Course on Modeling

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

Infinitesimal intervalsa mass-spring system with damping.

40

Page 41: A Core Course on Modeling

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

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

Page 42: A Core Course on Modeling

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

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 et

C(urest-u) - u’ = mu’’ and use u’ = Aet; u’’ = A2et.

C(urest-urest-Aet) - Aet = mA2et . Must hold for any t, so

C + + m2 = 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

Page 43: A Core Course on Modeling

43

A Core Course on Modeling

Summary

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

Week 3- Time for Change

Page 44: A Core Course on Modeling

44

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

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)

Page 45: A Core Course on Modeling

45

A Core Course on Modeling

Time and State Transitions

Week 3- Time for Change

samples taken every 1/44100 sec

original sound

the reconstructed signal

Equal intervals

Playing a CD: a series of 44100 samples/sec.

Page 46: A Core Course on Modeling

46

A Core Course on Modeling

Summary

• 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);

• equal, small intervals: approximation, sampling error (examples: moving point mass, … );

• infinitesimal intervals: continuous time, differential equations (examples: mass-spring system);

Week 3- Time for Change