1 / 46

A Core Course on Modeling

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

abedi
Télécharger la présentation

A Core Course on Modeling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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)

  2. A Core Course on Modeling Week 3- Time for Change    Contents     2 Question: • how to model systems … • … that vary over time … • … such that their behavior • can be predicted, • can be specified, • can be verified, • can be … ?

  3. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     3 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

  4. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     4 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

  5. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     5 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 write with red pen red pen goes out

  6. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     6 • 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

  7. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     7 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 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 Red pen is out; other three pens are in; red pen contains less ink All four pens are in and contain 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

  8. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     8 A real-life example: controlling a parking garage

  9. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     9 • 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

  10. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     10 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!)

  11. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     11 Idea: hiding and exposing quantities or values

  12. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     12 Individualproperties: use is visible level is notvisible inOut … dependsonpurpose make use an exposed quantity make level a hidden quantity make inOutexposed if color of a pen matters; otherwise hidden

  13. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     13 • Decrease amount of states: • distinguish exposed and hidden quantities or values • focus on the exposed ones

  14. writing A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     14 Example: 4-color pen Simples process description: just two states myPen.use=TRUE myPen.use=FALSE

  15. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     15 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

  16. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     16 Denote state and state transitions: statechart red.inOut=out red.level>0 red.inOut=out red.level=0 black.inOut=out black.level=0 green.inOut=out green.level>0 red.inOut=in green.inOut=in blue.inOut=in black.inOut=in green.inOut=out green.level=0 black.inOut=out black.level>0 blue.inOut=out blue.level>0 blue.inOut=out blue.level=0

  17. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     17 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

  18. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     18 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

  19. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     19 Now we have a state chart model. So what? garage model was reduced to 3.3 x 106states … and couldbeanalysedby computer

  20. A Core Course on Modeling Week 3- Time for Change    Introduction to Processes     20 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?

  21. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    21 Let’s start talking about time.

  22. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    22 state S0 transition T1 state S1 transition T2 state S2 transition T3 state S3

  23. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    23 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)

  24. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    24 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) ?

  25. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    25 Flavours of time (applications) partial order

  26. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    26 Flavours of time (applications) total order for all pairs of T1, T2, earlier (T1,T2) or later(T1,T2)

  27. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    27 Flavours of time (applications) total order + equal intervals

  28. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    28 Flavours of time (applications) total order + infinitesimal intervals

  29. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    29 Causality: Qcurr=F(Qprev,Pprev) Forbidden: Qcurr=F(Qcurr,…)

  30. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    30 Causality: Qcurr=F(Qprev,Pprev) Forbidden: Qcurr=F(Qcurr,…) F is a recursive function

  31. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    31 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)?

  32. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    32 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)

  33. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    33 Equal intervals a mass-spring system.

  34. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    34 Equal intervals a mass-spring system. K = ma K = C(urest-u) a = v’ v = u’ t = i

  35. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    35 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

  36. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    36 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

  37. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    37 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

  38. 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(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

  39. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    39 Equal intervals a mass-spring system with damping. 39

  40. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    40 Infinitesimal intervals a mass-spring system with damping.

  41. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    41 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)

  42. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    42 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

  43. 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

  44. A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    44 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)

  45. the reconstructed signal samples taken every 1/44100 sec original sound A Core Course on Modeling Week 3- Time for Change    Time and State Transitions    45 Equal intervals Playing a CD: a series of 44100 samples/sec.

  46. 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 = transitionsbetween 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 exposedand hiddenproperties 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 recursivefunction Qi+1 = F(Qi , Qi-1 , Qi-2, …. , Pi , Pi-1 , Pi-2 , …) to evaluate or unrolla behavior; • equal intervals: closed form evaluation (e.g.,: periodic financial transactions; sampling); • equal, small intervals: approximation, sampling error (examples: moving point mass, … ); • infinitesimal intervals: continuoustime, differential equations (examples: mass-spring system);

More Related