Sttechrts y Kenr ooper ontents Introuction Stte igrms epth (hierrchy) Orthogonlity (concurrency) rocst ommuniction Exmple Prolems Introuction Sttechrts were introuce y vi Hrel in 1987. Hrel, Sttechrts: visul formlism for complex systems, Science of omputer Progrmming 8, 1987, pp. 231-274. Sttechrts re useful for escriing lrge, complex, rective systems rective system is one which must continuously rect to externl n internl stimuli They re grphic nottion ( visul ) Sttechrt = stte-igrms + epth (lso known s strction) + orthogonlity (lso known s concurrency) + rocst communiction The Sttechrt nottion is kin of extene FSM with strction, concurrency, n communiction Stte igrms ompose of sttes, trnsitions trnsitions from one stte to nother hppen when the event tht is lele on the rc (if ny) occurs n the conition (if ny) is true n output cn e ssocite with the trnsition o In the igrm elow, the stte chnges from to when event occurs n the conition P is true; the output is c o c is glol (cn e seen everywhere in the Sttechrt moel) c cn e use s n input on trnsition
this supports communiction in the moel (P)/c epth (hierrchy) sttechrts exten this with: o refinement, clustering o N, OR ecomposition of sttes (ctully XOR, not OR) Exmple (clustering, ottom up pproch) e(p) n e clustere like this: e(p) is clle superstte. The semntics (k mening) of superstte is: o xor The rc lele is common property to the superstte
Exmple (refinement, top-own pproch) in this exmple, we strt with sttes n Stte is refine to inclue sttes n The events, re unerspecifie (which one goes where?) - nees to e fixe The trnsition from to lso nees to e specifie for the exmple e(p)
efult stte If we hve susttes,, n n we wnt to enter stte y efult, we specify this using smll rrow: or History Stte n use history entrnce (H). The stte entere is the lst stte the level ws in when it existe. The H entrnce overries efult stte The scope of the H entrnce is the current level of the igrm The scope of the H* entrnce is to the lowest level of the igrm. H Exmple: timer tht continues to count own s the stte is entere n exite (the timer oes not get reset when the stte is entere)
Orthogonlity (concurrency) N Exmple Y is the orthogonl prouct of n Y E u g G F From the efult sttes: If event occurs, then the igrm moves from sttes,f into stte,g t the sme time ( is synchronize with ) If event u occurs, then only is ffecte n the igrm moves from,f into stte, E ( is inepenent from ) igrms cn e much smller, simpler thn those rwn in equivlent form using XORs Smller n simpler men the igrm is esier to write, review, correct, n mintin. rocst ommuniction n event is seen everywhere in the igrm t the sme time. Exmple Specify the ehvior of n lrm clock using sttechrts. ssumptions: The lrm clock hs 2 uttons. We cn strt with setting the current time. Nee to set hours, minutes, secons Nee to ecie which uttons (one, oth together) o wht
Set urrent Time &2 link Hours utton 2 utton 2 &2 link Minutes utton 2 utton 2 &2 link Secons utton 2 Hours Minutes Secons urrenttime Set
Now, consier setting the lrm time. Set lrm Time &2 link Hours utton 2 utton 2 &2 link Minutes utton 2 utton 2 &2 link Secons utton 2 Hours Minutes Secons lrm Time Set Now, consier how these supersttes relte to one nother? xor lock isply Time isply lrm Time utton 2 Set urrent Time Set lrm Time Now, exten the sttechrt to escrie the lrm going off.
lock isply Time lrm Time lrm On utton 2 Set urrent Time Set lrm Now, vlite the ehvior of the sttechrt (i.e., oes the sttechrt specify the system the wy we wnt it to work) Question: Wht hppens if the lrm goes off for 5 minutes? isply vs. Mintin the time? Mintining the time nees to occur concurrently with: the lrm going off setting the lrm time Question: Is it possile to isply n mintin the current time concurrently? Next step is to fix the sttechrt. fter it is fixe, nee to re-vlite the sttechrt. Other things to consier: Is there rio? Is there snooze utton? Is there ttery ckup?. HW Exercise: complete the sttechrt.
Prolems 1. Wht is sttechrt? 2. escrie 3 types of systems tht woul e suitle for escriing in sttechrts. 3. In softwre engineering, we use the principle of strction. How oes sttechrts support this principle? 4. rw sttechrt tht specifies the functionlity of igitl wtch tht hs n lrm feture (i.e., you cn set the time for eeping lrm to go off). 2. rw sttechrt tht specifies the functionlity of four function clcultor. 3. rw Sttechrt tht represents the ining Philosophers Prolem. The ining Philosophers Prolem Five philosophers sit t roun tle. t ny given time, philosopher my either et or meitte. When they et, they nee to pick up two chopsticks (one on their left n one on their right). When they meitte, they o not nee ny chopsticks. There re totl of five chopsticks ville.