Download presentation
Presentation is loading. Please wait.
Published byFelicity Wilcox Modified over 9 years ago
1
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
2
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
3
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, 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 … Week 3- Time for Change
4
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 What is the ink level in this pen ( in percentile, so: level=0 means: ink between 0.00 and 0.01 of maximum )? Is my 4CP ready for writing ? Is this pen in or out? Week 3- Time for Change
5
5 A Core Course on Modeling Describe processes: statecharts intuition: describe a process by relating states (=‘freezes’ or ‘snapshots’) of the system 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
6
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
7
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 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; red 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
8
8 A Core Course on Modeling Examples from real life: parking garage: xxxx states yyyy zzzz Introduction to Processes Week 3- Time for Change 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
9
9 A Core Course on Modeling Introduction to Processes Week 3- Time for Change 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 m i values, nr states = i=1 … n m i Number of behaviors with p steps = j=1 … p i=1 … n m i State and process explosion
10
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 … Is this really necessary ?? red.levelgreen.levelblue.levelblack.levelred.inOutgreen.inOutblue.inOutred.inOut
11
11 A Core Course on Modeling Let us look at individual properties: use is relevant level is not relevant (not visible) inOut is relevant … depends on purpose Let us look at individual properties: use is relevant level is not relevant (not visible) inOut is relevant … depends on purpose Introduction to Processes Week 3- Time for Change
12
12 A Core Course on Modeling 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 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 Introduction to Processes Week 3- Time for Change
13
13 A Core Course on Modeling 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 Introduction to Processes Week 3- Time for Change
14
14 A Core Course on Modeling 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 Introduction to Processes Week 3- Time for Change
15
15 A Core Course on Modeling Example: 4-color pen The simplest process description contains merely two states, only involving the most crucial exposed quantity: ‘use’: myPen.use=TRUEmyPen.use=FALSE writing Introduction to Processes Assume that initially there is one pen out Week 3- Time for Change
16
16 A Core Course on Modeling 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 Introduction to Processes Week 3- Time for Change
17
17 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 state: all pens are in (say nothing about ink levels) clicking red pen, level>0, in and out clicking red pen, with no ink, in and out red pen, running out of ink: only possible when out Introduction to Processes state: red pen is out; no ink left in red pen Week 3- Time for Change state: red pen is out; level>0 in red pen
18
18 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 Using projection, we reduced multiple states with irrelevant differences to only one state This model behaves like a true 4- color ballpoint: shows how eventually, every pen.level will become 0 shows how in the use=FALSE state, we can only click empty pens in and out never more than 1 pen is out. of the 16000000 states, we projected out only 9 relevant ones Introduction to Processes Week 3- Time for Change
19
19 A Core Course on Modeling Projection: one conceptual model different statecharts, depending on the choice for exposed quantities Purpose: just clicking behavior is interesting Only exposed quantities are the ‘inOut’ properties red.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
20
20 A Core Course on Modeling Projection: one conceptual model different statecharts, depending on the choice for exposed quantities None of the simplified statecharts shows relations between ‘level’ and ‘inOut’ Carefully select exposed quantities. Balance simplicity expressive power (given the purpose) Advanced: hierarchical states, conditional transitions, orthogonal regions (see lecture series ‘process 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 Purpose: warn user when pen runs out Only exposed quantities are the level properties
21
21 A Core Course on Modeling 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 proporties 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) Introduction to Processes Week 3- Time for Change
22
22 A Core Course on Modeling Flavours of time Transitions happen instantaneous (take no time) States may last States and Transitions alternate Time and State Transitions Week 3- Time for Change States and transitions alternate like sandwiches and toppings
23
23 A Core Course on Modeling Flavours of time partial order for zero or more pairs of transitions T 1, T 2, you can specify or verify earlier(T 1,T 2 ) or later(T 1,T 2 ) application: specification or verification – e.g., manufacturing, control, parallel calculations, … total order for all pairs of transitions T 1, T 2, you can determine earlier (T 1,T 2 ) or later(T 1,T 2 ) application: prediction or documentation (logging) – e.g., physics, material engineering, … Time and State Transitions Week 3- Time for Change
24
24 A Core Course on Modeling 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) ? Time and State Transitions Week 3- Time for Change these transitions are not ordered no total order
25
25 A Core Course on Modeling 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!) Time and State Transitions Week 3- Time for Change
26
26 A Core Course on Modeling Causality forbids that something depends on its future. Any quantity’s value in the current state can only depend on the previous state(s): Q curr =F(Q prev,P prev ) Since dependency works from ‘previous’ to ‘current’, Q prev and P prev have no dependence on Q curr. So we won’t have Q curr =F(Q curr,…) 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. Time and State Transitions Week 3- Time for Change Various forms of perpetuum mobiles assume some circular causality.
27
27 A Core Course on Modeling Causality forbids that something depends on its future. Any quantity’s value in the current state can only depend on the previous state(s): Q curr =F(Q prev,P prev ) Since dependency works from ‘previous’ to ‘current’, Q prev and P prev have no dependence on Q curr. So we won’t have Q curr =F(Q curr,…) F is called a recursive function: it calculates Q taking an earlier value of Q as argument. HELP!!! I don’t see an ‘F’ … so let’s look at some examples Time and State Transitions Week 3- Time for Change Various forms of perpetuum mobiles assume some circular causality.
28
28 A Core Course on Modeling 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, …), {E i } question: at which posts should you pick banana(s) (each containing B kCal)? Time and State Transitions Week 3- Time for Change
29
29 A Core Course on Modeling Arbitrary intervals: consider a leisure sports event: Q i =amount of kCal in stomach at post i, i > 0 Q 0 =amount of kCal in stomach at start Q i+1 =Q i -E i if you don’t eat Q i+1 =Q i -E i +nB if you eat n bananas at post i What is n? Answer: n should be such that Q i+1 >0, and as small as possible (weight!) Q i+1 =Q i -E i +nB; Q i -E i +nB>0, so nB>E i -Q i ; n=max(0, (E i -Q i )/B ), so Q i+i =Q i -E i +B*max(0, (E i -Q i )/B ) or: Q i+1 =F(Q i,P i ) Time and State Transitions Week 3- Time for Change max(0,…): you can’t eat a negative amount of bananas … : rounding up: you don’t want to eat a fraction of a banana
30
30 A Core Course on Modeling Equal intervals: playing a CD. Sound on a CD is represented as a series of 44100 samples/sec of the amplitude. Playing the sound: take a sample P i Do a calculation to process the sound (e.g., Q i+1 = Q i +(1- )P i ) Next, output Q i+1 to the speaker. So again Q i+1 =F(Q i,P i ) Time and State Transitions Week 3- Time for Change If is (close to) 0, we get the original samples; if is closer to 1, Q i+1 is more similar to Q i, so no fast changes in Q: higher frequencies are reduced: low-pass filtering
31
31 A Core Course on Modeling The reconstructed sound will contain a pitch that was not present initially!! (sampling aliasing) Time and State Transitions Week 3- Time for Change Equal intervals: playing a CD. Sound on a CD is represented as a series of 44100 samples/sec of the amplitude. Playing the sound: take a sample P i Do a calculation to process the sound (e.g., Q i+1 = Q i +(1- )P i ) Next, output Q i+1 to the speaker. So again Q i+1 =F(Q i,P i ) samples taken every 1/44100 sec original sound the reconstructed signal A remedy to aliasing, is to apply a low-pass filter on the input signal. This is also a dynamic system of the form Q curr =F(Q prev,P prev ) (details fall beyond the scope of this lecture)
32
32 A Core Course on Modeling t i K(t) K i u(t) u i u’(t) (u(t+ )-u(t))/ = (u i+1 -u i )/ v’(t) (v(t+ )-v(t))/ = (v i+1 -v i )/ So u i+1 = u i + v i v i+1 = v i + a i = = v i + K i /m = = v i + C(u rest -u i ) /m So again Q curr =F(Q prev,P prev ): u curr =F 1 (u prev,v prev )=u prev + v prev v curr =F 2 (v prev,u prev )= =v prev + C(u rest -u prev ) /m, with suitable u 0 and v 0 Equal intervals: a mass-spring system. From physics, we know K=ma where K=C(u rest -u) and a=u’’. Write v=u’, then a=v’. Here, K=K(t), u=u(t). Let us approximate by sampling. For 0: -v-v ( - v i ) ( - v prev ) u(t+ )= =u(i + ) =u((i+1) ) =u i+1, and similar for v Remember: order of evaluation F 1, F 2 is irrelevant Time and State Transitions Week 3- Time for Change …and now with damping:
33
33 A Core Course on Modeling t i K(t) K i u(t) u i u’(t) (u(t+ )-u(t))/ = (u i+1 -u i )/ v’(t) (v(t+ )-v(t))/ = (v i+1 -v i )/ So u i+1 = u i + v i v i+1 = v i + a i = = v i + F i /m = = v i + C(u rest -u i ) /m So again Q curr =F(Q prev,P prev ): u curr =F 1 (u prev,v prev )=u prev + v prev v curr =F 2 (v prev,u prev )= =v prev + C(u rest -u prev ) /m, with suitable u 0 and v 0. Equal intervals: a mass-spring system. From physics, we know K=ma where K=C(u rest -u) and a=u’’. Write v=u’, then a=v’. Here, K=K(t), u=u(t). Let us approximate by sampling. For 0: -v-v ( - v i ) ( - v prev ) WARNING: 0 is not the same as =small. The substitutions for u’(t) and v’(t) are approximations only. As we saw in the previous sampling example, aliasing errors are worse when the sampled signal changes rapidly, compared to the sampling rate. Concrete: unless is much smaller than the period of the oscillation (= m/C), the approximations are bad – with the risk of instability. Time and State Transitions Week 3- Time for Change
34
34 A Core Course on Modeling Infinitesimal intervals: the mass- spring system revisited. From physics, we know K=ma where K=C(u rest -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. Time and State Transitions Week 3- Time for Change
35
35 A Core Course on Modeling With damping: try u=u rest +Ae t, then C+ +m 2 =0, or 1,2 =(- ( 2 -4mC))/2m Let 0 = (4mC). For = 0 critical damping; for < 0 oscillations; T=T 0 (1- 0 2 ) for > 0 super critical damping (further details: lectures ‘dynamical systems’) Infinitesimal intervals: the mass- spring system revisited. From physics, we know K=ma where K=C(u rest -u) and a=u’’. Here, K=K(t), u=u(t). Let us try a solution of the form u=u rest +A sin(t/T) u’’= -AT -2 sin(t/T) Substitute back: -mAT -2 sin(t/T)=C(u rest -u rest -Asin(t/T), mT -2 =C, or T= m/C ( =:T 0 ) By substituting u = Ae t into C(u rest -u)- u’=mu’’ and using u’=A e t ; u’’=A 2 e t. C(u rest -u rest -Ae t )- A e t =mA 2 e t Must hold for any t, so indeed C + + m 2 =0 Time and State Transitions Week 3- Time for Change
36
36 A Core Course on Modeling Summary 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 Q curr =F(Q prev,P prev ) interested in outcomes? use simplest possible numerical techniques, be aware for accuracy (perhaps decrease performance !!) interested in insight? try symbolic methods Week 3- Time for Change
37
37 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 Q i+1 = F(Q i, Q i-1, Q i-2, …., P i, P i-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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.