Advanced State Modeling: Or: "Derek Zoolander Strikes Back"

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Advanced State Modeling


Or: Derek Zoolander Strikes Back
Jonathan Sprinkle1
University of Arizona
Department of Electrical and Computer Engineering
PO Box 210104, Tucson, AZ 85721, USA

Jonathan Sprinkle

Advanced State Modeling

Reminders from State Modeling

Advanced State Modeling Concepts

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

Advanced State Modeling

Reminders from State Modeling

Advanced State Modeling Concepts

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

Advanced State Modeling

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Outline

Reminders from State Modeling


Definitions
Sending Signals

Advanced State Modeling Concepts


Nested State Diagrams
Concurrency and States
Concurrency within an Object
Synchronization of Concurrent Activities

In-Class Exercises

Jonathan Sprinkle

Advanced State Modeling

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Definitions

Transitions happen.

State1
entry/action
do/activity
exit/action
event/action(arguments)

Jonathan Sprinkle

event[guard]

Advanced State Modeling

State2
entry/action
do/activity
exit/action

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Definitions

Activities happen.

State1
entry/action
do/activity
exit/action
event/action(arguments)

Jonathan Sprinkle

event[guard]/action

Advanced State Modeling

State2
entry/action
do/activity
exit/action

Reminders from State Modeling

Advanced State Modeling Concepts

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

However, it may be possible get a state stuck if guard conditions


prevent taking the transition, and no more completion transitions
fire. Completion transitions should be used with careor not
at all!! You will be heavily penalized on exams and homework
assignments for state models with ambiguous completion
transitions.
Jonathan Sprinkle

Advanced State Modeling

Reminders from State Modeling

Advanced State Modeling Concepts

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

Advanced State Modeling

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Outline

Reminders from State Modeling


Definitions
Sending Signals

Advanced State Modeling Concepts


Nested State Diagrams
Concurrency and States
Concurrency within an Object
Synchronization of Concurrent Activities

In-Class Exercises

Jonathan Sprinkle

Advanced State Modeling

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Advanced State Modeling


Previously discussed concepts for state modeling are sufficient for
toy examples, but systems which are deployed frequently require
more advanced concepts. This information is from Chapter 6 of
the text.

Jonathan Sprinkle

Advanced State Modeling

10

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Nested State Diagrams

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

Advanced State Modeling

11

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Nested State Diagrams

Example (From Figures 6.2, 6.3 in Chapter 6)


Consider a vending machine, with more that one selectable item.
Vending Machine
start
cons in(amount) / set balance

Collecting money
coins in(amount) / add to balance

Idle
cancel / refund coins

[item empty]

select(item)
[change < 0]

do / test item and compute change


[change = 0]

dispense : DispenseItem

[change > 0]

do / make change

Figure: The Vending Machine state diagram


Jonathan Sprinkle

Advanced State Modeling

12

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Nested State Diagrams

A submachine: DispenseItem
Example (The DispenseItem submachine)
DispenseItem

start

do / move arm( item.getRow( ) )

end

pushed

arm ready

do / move arm( item.getCol( ) )

do / push item off shelf

arm ready

Figure: The DispenseItem subdiagram

Jonathan Sprinkle

Advanced State Modeling

13

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Concurrency and States

Aggregation Concurrency

State models by their appearance and definition support


concurrency well; however, it is entirely possible that certain
objects may require interdependence at certain points in their life.
The aggregate state refers to the combined state of all state
diagrams in a collection.

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

Advanced State Modeling

14

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Concurrency and States

When employing Aggregation Concurrency, it is most interesting


for contained states to interact (e.g., transitions for one object may
depend on the state of another object).

Example (Car example.)


Car

Transmission

Jonathan Sprinkle

Accelerator

Advanced State Modeling

Brake

15

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Concurrency and States

Aggregations Concurrent State Diagram


start

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

Advanced State Modeling

16

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Concurrency within an Object

When modeling an object which may have a concurrent set of


states, it is possible to partition the state with a dotted line, to
show that the state of the object is a tuple of single states from
each concurrent region.
State
State1

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

Advanced State Modeling

17

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Concurrency within an Object

Example (Tennis Game)

Jonathan Sprinkle

Advanced State Modeling

18

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Synchronization of Concurrent Activities

For atomic synchronization, it is possible to use splitting and


merging.

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

Advanced State Modeling

19

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Synchronization of Concurrent Activities

A few notes...

Merge and split are themselves transitions, and fire based on


events, guards, and can produce actions.
It is not necessary for concurrent states (after splitting
control) to occur simultaneously.
Implicit merges and simple splitting can cause headaches if
states (and substates) do not contain default states. You
should specify a default state for all concurrent substates to
avoid confusion.

Jonathan Sprinkle

Advanced State Modeling

20

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Outline

Reminders from State Modeling


Definitions
Sending Signals

Advanced State Modeling Concepts


Nested State Diagrams
Concurrency and States
Concurrency within an Object
Synchronization of Concurrent Activities

In-Class Exercises

Jonathan Sprinkle

Advanced State Modeling

21

Reminders from State Modeling

Advanced State Modeling Concepts

In-Class Exercises

Example (Completion Confusion)


Create 2-3 example state models where completion transitions are used to
describe a specific design of your choosing. Have some be clear, and others be
unclear. Create sequence diagrams for unclear state models.

Example (Current Concurrent)


Create a state model using concurrent substates, to describe how capacitors in
an example circuit are charging. Make sure to show the example circuit, but no
specific equations need be given.

Example (Substate Mate)


Create a state model with explicit substates, that describe a chess game, and
various strategies that either player will use as parts of each substate. Be
general in your algorithms, not specific.

Jonathan Sprinkle

Advanced State Modeling

22

You might also like