Professional Documents
Culture Documents
Advanced State Modeling: Or: "Derek Zoolander Strikes Back"
Advanced State Modeling: Or: "Derek Zoolander Strikes Back"
Advanced State Modeling: Or: "Derek Zoolander Strikes Back"
In-Class Exercises
Jonathan Sprinkle
In-Class Exercises
Abstract
Abstract
This lecture continues discussion of state modeling and state
diagrams. Specific details to be discussed include concurrent
models, and various instance models of states.
Jonathan Sprinkle
In-Class Exercises
Previously, on ECE373. . .
State models give the behavior of a particular class.
States are an abstraction of the current value(s) of an object
and its links
Events are instantaneous (when they happen), and unique.
Kinds of events can be classified
Transitions can fire when an event occurs, and guard
conditions are satisfied (recall event[guard]).
Jonathan Sprinkle
In-Class Exercises
Outline
In-Class Exercises
Jonathan Sprinkle
In-Class Exercises
Definitions
Transitions happen.
State1
entry/action
do/activity
exit/action
event/action(arguments)
Jonathan Sprinkle
event[guard]
State2
entry/action
do/activity
exit/action
In-Class Exercises
Definitions
Activities happen.
State1
entry/action
do/activity
exit/action
event/action(arguments)
Jonathan Sprinkle
event[guard]/action
State2
entry/action
do/activity
exit/action
In-Class Exercises
Definitions
Completion transitions
When an activity is complete, or no activity exists, an unlabeled
transition called the completion transition can be taken when
activity is done. This is in response to the completion event, which
fires only once.
State1
State2
entry/action
do/activity
exit/action
In-Class Exercises
Sending Signals
Race conditions
An object can send a signal to another object, or objects.
Generally, if a signal is directed at a group of objects, then each
object received a unique signal, and they are processed
concurrently. If an object can receive signals from more than one
object, then it may be possible for the order of receipt to affect the
final state of the object. This effect is called a race condition.
Definition
A race condition is a design consequence, wherein a particular
objects final state is nondeterministic when considering the order
of receipt of messages from more than one source.
It is interesting to note that race conditions are not necessarily
design flaws, but that many real-time of concurrent systems prefer
that race conditions do not exist.
Jonathan Sprinkle
In-Class Exercises
Outline
In-Class Exercises
Jonathan Sprinkle
In-Class Exercises
Jonathan Sprinkle
10
In-Class Exercises
Flat state diagrams can become unwieldy, and are often so large
that they cannot be readily understood as a documentation tool.
Furthermore, it may be the case that the complexity of a flattened
state diagram may hide design flaws in the same way that the
complexity of textual code, for a sufficiently large example.
Enter, then, nested state diagrams, which allow subdiagrams to
hide complexity, or refactor tasks. Consider a vending machine,
with 10 different selections. The act of dispensing an item can be
refactored as a single state, even though it may require several
sub-states to complete its task.
Jonathan Sprinkle
11
In-Class Exercises
Collecting money
coins in(amount) / add to balance
Idle
cancel / refund coins
[item empty]
select(item)
[change < 0]
dispense : DispenseItem
[change > 0]
do / make change
12
In-Class Exercises
A submachine: DispenseItem
Example (The DispenseItem submachine)
DispenseItem
start
end
pushed
arm ready
arm ready
Jonathan Sprinkle
13
In-Class Exercises
Aggregation Concurrency
Definition
Aggregation Concurrency is an and relationship between
concurrent states. Two state which employ aggregation
concurrency are both active at the same time.
Jonathan Sprinkle
14
In-Class Exercises
Transmission
Jonathan Sprinkle
Accelerator
Brake
15
In-Class Exercises
Transmission
Park
select(reverse)
select(park)[v=0]
Reverse
select(park)[v=0]
select(drive)
Drive
when( v > v_max )
First
when( v < v_min )
Accelerator
Idle
do / decrease v
Second
push down
Depressed
do / increase v
release
Brake
Idle
push down
Depressed
do / decrease v
release
Jonathan Sprinkle
16
In-Class Exercises
State2
StateA
StateB
The state can be State1 and StateB, for example, but not
StateA and StateB since exactly one state from each partition
must be active.
Jonathan Sprinkle
17
In-Class Exercises
Jonathan Sprinkle
18
In-Class Exercises
Definition
Splitting control requires that all following activities occur
concurrently. A splitting fork (heavy bar with one input and 2..*
outputs) denotes splitting of control.
Definition
Merging control is the collection of completion of all incoming
activities before continuing. A merging (or joining) fork (heavy bar
with 2..* inputs and one output) denotes merging of control.
Jonathan Sprinkle
19
In-Class Exercises
A few notes...
Jonathan Sprinkle
20
In-Class Exercises
Outline
In-Class Exercises
Jonathan Sprinkle
21
In-Class Exercises
Jonathan Sprinkle
22