1 cs/cpe 426 senior projects chapter 21: state machines chapter 22:advanced state machines [arlow...
Post on 21-Dec-2015
218 views
TRANSCRIPT
![Page 1: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/1.jpg)
11
CS/CPE 426Senior Projects
Chapter 21: State MachinesChapter 22:Advanced State Machines
[Arlow and Neustadt 2005]
March 24, 2009
![Page 2: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/2.jpg)
22
Outline State machines:
IntroductionState machine diagramsStatesTransitionsEvents
Advanced state machines:Composite states
SimpleOrthogonal
Submachine statesSubmachine communicationHistory
![Page 3: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/3.jpg)
33
Introduction
Both activity diagrams and state machine diagrams model system behavior
However, they have different semantics:Activity diagrams are based on Petri Nets and
usually model processes when several objects participate
State machine are based on Harel’s statecharts and typically used to model single reactive objects
![Page 4: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/4.jpg)
44
Introduction
Reactive objects:Respond to external eventsMay generate and respond to internal
eventsHave a lifecycle modeled as a progression
of states, transitions and eventsMay have current behavior that depends
on past behavior State machines are used to model
behavior of classifiers such as classes, use cases, subsystems, systems
![Page 5: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/5.jpg)
55
Introduction
There are two types of state machines: Behavioral state machines Protocol state machines
State machines are most commonly used to model dynamic behavior of classes
In UP, state machines can be used in: requirements, analysis, design
A significant challenge is testing state machines: manual walkthrough, simulation, code generation + test harnesses for state machines
![Page 6: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/6.jpg)
66
State machine diagrams There are three main modeling elements in state
diagrams: states transitions, and events. Example of a simple state machine, Fig. 21.2 [Arlow &
Neustadt]
![Page 7: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/7.jpg)
77
States
Summary of UML state syntax, Fig.21.4 [Arlow & Neustadt 2005]
![Page 8: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/8.jpg)
88
TransitionsSummary of UML syntax for transitions in behavioral state diagrams, Fig.21.5 [Arlow & Neustadt 2005]
Where: event(s)= internal or external occurrence(s) that trigger the transition guardCondition = boolean expression, when true the transition is
allowed anAction = some operation that takes place when the transition fires
![Page 9: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/9.jpg)
99
Transitions
Summary of UML syntax for transitions in protocol state
diagrams, Fig.21.6 [Arlow & Neustadt 2005]
Note that there is no action and guard conditions are replaced by preconditions and postconditions.
![Page 10: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/10.jpg)
1010
TransitionsA junction pseudo-state represents a point where transitions
merge or branch, e.g. Fig.21.7 [Arlow & Neustadt 2005]
![Page 11: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/11.jpg)
1111
TransitionsA junction pseudo-state may have more than one output
transition(protected by mutually exclusive guard conditions) e.g.
Fig.21.8[Arlow & Neustadt 2005]
![Page 12: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/12.jpg)
1212
TransitionsChoice pseudo-state can also be used, e.g. Fig. 21.9 [Arlow &
Neustadt2005]
![Page 13: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/13.jpg)
1313
Events
Events can be of four types:Call eventSignal eventChange eventTime event
![Page 14: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/14.jpg)
1414
Events
Example of a call event, Fig.21.11 [Arlow & Neustadt 2005]
![Page 15: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/15.jpg)
1515
Events
A signal is a package of information sent asynchronously between objects. Example of signal event Fig. 21.12 [Arlow & Neustadt 2005]
Example of sending a Signal Fig. 21.13 [Arlow & Neustadt 2005]
![Page 16: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/16.jpg)
1616
EventsChange events are positive edge triggered.Example of a change event, Fig. 21.15 [Arlow & Neustadt
2005]
![Page 17: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/17.jpg)
1717
Events
Time events are indicated by the keywords when and after. Example of a time event, Fig. 21.16 [Arlow & Neustadt,
2002]
![Page 18: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/18.jpg)
1818
Example of astate machine[Dascalu 2001]
Stopped MoveWithSpeedOne
MoveWithSpeedTwo
Blocked
go1_command /speedOne()
target_reached /stop()
go2_command /speedTwo()
go2_command /speedOne()
limit_reached or otheremergency condition /
stop ()
permission_to_restart /reset ()
limit_reached or otheremergency condition /
stop ()
stateinitial state
transition
event action
change_direction_command /reverseDirection()
final state
off
off
From the stopped state, the 2-speed motor brings the probe in atarget position by "accelerating" with speed 1, "crusing" with speed2, "deccelerating" with speed 1, and then stopping. If out of limitsor in case of another emergency, the motor stops immediately andrequires the operator's permission to restart working.
![Page 19: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/19.jpg)
1919
Composite states
A composite state contains one or more nested state machines (submachines), each existing in its own region, Fig 22.2 [Arlow & Neustadt 2005].
The composition icon is shown in Fig. 22.4
![Page 20: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/20.jpg)
2020
Simple composite states A superstate that contains a single region is called a
simple composite state, e.g. Fig 22.5 [Arlow & Neustadt 2005]
![Page 21: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/21.jpg)
2121
Orthogonal composite states Orthogonal composite states consist of two or more sub-
machines that execute in parallel. In Fig 22.6 [Arlow & Neustadt 2005] there are two such composite states, Initializing and Monitoring
![Page 22: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/22.jpg)
2222
Orthogonal composite states
The composite state Initializing, Fig 22.7 [Arlow & Neustadt 2005]
![Page 23: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/23.jpg)
2323
Orthogonal composite statesThe composite state Monitoring, Fig 22.8 [Arlow & Neustadt 2008]
![Page 24: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/24.jpg)
2424
Submachine states
A submachine state is a special state that references a state machine recorded in a separate diagram, e.g. Fig. 22. 9 [Arlow and Neustadt 2005]
![Page 25: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/25.jpg)
2525
Submachine states Fig. 22. 10 [Arlow & Neustadt 2005]. The notation
for a submachine state is
<state name : name of referenced state machine diagram>
![Page 26: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/26.jpg)
2626
Submachine communication
Asynchronous submachine communication can be achieved via attributes:
The modeled reactive object has a set of attributes that can be used by submachines
The communication mechanism: one machine sets attributes and the other uses the attribute values in guard conditions of their transitions
![Page 27: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/27.jpg)
2727
Submachine communication Example of communication via attributes, Fig. 22.11
[A&N 2005]
![Page 28: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/28.jpg)
2828
HistoryExample of using the shallow history indicator, Fig 22.12 [Arlow &
Neustadt 2005]
![Page 29: 1 CS/CPE 426 Senior Projects Chapter 21: State Machines Chapter 22:Advanced State Machines [Arlow and Neustadt 2005] March 24, 2009](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d5f5503460f94a4034d/html5/thumbnails/29.jpg)
2929
History
Example of using the deep history indicatorFig 22.13 [Arlow & Neustadt 2005]