State Transition Diagram - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

State Transition Diagram

Description:

Alt. switch. light [st=on] [st=off] TurnOff ( ) TurnOn ( ) From. State ... The history of preset. state is 'remembered' if. the radio is turned. on after it is ... – PowerPoint PPT presentation

Number of Views:2649
Avg rating:3.0/5.0
Slides: 16
Provided by: Frank47
Category:

less

Transcript and Presenter's Notes

Title: State Transition Diagram


1
State Transition Diagram
  • A state transition diagram is a technique to
    depict
  • The states of an entity
  • The transitions of states of the entity
  • The trigger or the event that caused the
    transition of state of the entity
  • The entity may be a physical device such as a
    light switch or a vending machine it may be a
    software system or component such as a word
    processor or an operating system it may be a
    biological system such as a cell or a human or
    - - - -

This modeling technique came from a more formal
area called automata theory. State transition
diagram depicted a Finite State Machine.
2
Software Program View
  • The end product of a software is a program which
    executes. In depicting the program (or an object)
    we can consider
  • Variables which take on different values
  • Control structure and assignment statements in
    the program change the values of the variables

1. Combination of values of the variables at any
point of the program represent the program
state at that point. 2. The change made to the
values of the variables through assignment
statements represent a transition of state
3
A very simple example light switch (page 368 of
your text)
From State (light)
to State (light)
Alt
Event (switch)
switch
light
on turnOff off
ston
TurnOff ( )
off turnOn on
stoff
TurnOn ( )
State transition table for light with switch
events
Sequence diagram (alternative fragment) for
switch and light interaction
turnOff
on
off
turnOn
State transition diagram for light with switch
events
4
A little more on the light switch
turnOff
turnOff
turnOff
off
on
off
on
turnOn
turnOn
turnOn
What happens if we turn on a light that is
already on?
state can transition to its current state
5
Using State Transition Diagram
  • Model the entity at the level where the number of
    states is manageable.
  • Design (list) the number of of states (should
    not be big)
  • List the number of events that will trigger the
    state transition (should not be big)
  • There must be an starting state
  • There must be a terminating state or states
  • Design the transition rules (where the bulk of
    your design work is)

1.The above is not necessarily performed in
sequence iterate through these. 2. Even with a
modest number of states and events, the state
transition diagram, which really depicts the
transition rules, can be enormous.
6
Designing the Voice Recorder(similar to example
on page 397 of text)
  • For the entity, voice recorder, design the states
    of this entity
  • How many states does ( somewhat based on
    requirement ) a voice recorder have?
  • Set of recorder states off, on, play, record,
    erase, stop, error-msg
  • What are the initial and terminating states?
  • Initial state off
  • Terminating state off
  • List the events that will change the state of the
    entity
  • What are the events that will change the
    recorders states?
  • Input signals 1, 2, 3, 4, 5, 6 which
    corresponds to
  • off, on, play, record, erase,
    stop

Note no rewind state
7
Designing the Voice Recorder(example form page
397 of text) cont.
  • Design the transition rules for the voice recorder

from state
to state
events
off 2
on
off 1
off
on 1
off
More transition rules 1. Any state transition
not described here will transition to error-msg
state 2. once in error-msg state, the
system displays a message and automatically
transitions to stop state.
on 3
play
on 4
record
on 5
erase
play 6
stop
record 6
stop
erase 6
stop
stop 3
play
stop 4
record
stop 5
erase
stop 1
off
1off, 2on, 3play, 4record, 5erase, 6stop
8
State Transition Diagram ofVoice Recorder
1off, 2on, 3play, 4record, 5erase, 6stop
1
1
stop
On
always true
Off
2
1
3
Error-msg
4
3
5
5
4
6
play
6
6
erase
record
Couple things to note 1. All non-specified
events for all the states go to Error-msg state
- - - is that o.k? 2. What happens when a signal
of 6 comes in when in state ON - - - error
message? 3. How do you specify display error
message in Error-msg state ? 4. How do you
specify Starting and Terminating state ?
9
Finite State Machine (more original usage)
Pseudo code for the design of M1 Read input
string If input string includes non - 0s or
1s, error msg break if input string length is
odd number, error msg break Set state
s1 While (the string is non-empty) ele
first element from the string delete
the first element from the string if
(state s1 ele 0) then state s2
if (state s1 ele 1) then state s4
if (state s2 ele 0) then state s1
if (state s2 ele 1) then state s3
if (state s3 ele 0) then state s4
if (state s3 ele 1) then state
s2 if (state s4 ele 0) then
state s3 if (state s4 ele 1)
then state s1 if (state s1) accept
string else error msg end
0
S1
S2
0
1
1
1
1
0
S3
S4
0
M1 A, S, T, I, term where A 0, 1 S
s1, s2, s3, s4 T (s1,0)-gt s2 (s1,1) -gt
s4 ----- I s1 term s1
M1 is a string checker that accepts all strings
that contain even number of 0s and 1s
10
UMLs improvements on State Transition Diagrams
  • Event may be expressed with a string
  • event-signature guard /
    action-expression
  • State symbol may contain several compartments
  • Name
  • Processing activities in the form of
  • Action-label / Action-expressions
  • Action-labels
  • Entry specifies activities upon state entry
  • Exit specifies activities upon state exit
  • Do specifies activities to be performed after
    entry but before exit
  • Include names another state diagram to be used
    for nested state transition diagram for further
    refinement
  • Action-expression specifies the activities to be
    performed.
  • Instead of include, there may be a stubbed
    state which can be expanded later.
  • The state diagram may contain another state
    diagram (nested diagram) in its compartment

11
UML State Transition Composite Diagram
Example(cruise control system - similar to page
401 of text)
off
onBtnclick
offBtnclick
On
Note 1. the start and terminating states 2.
When entering a composite diagram, the start
state must be clearly defined. 3. How we exit
this composite diagram from the freeSpeed state
and actually enter off state
pedalSpeed
entry / spLock undefined
engage
pressBreak
setSpeed
freeSpeed
entry/ spLock current speed do /
lockState on
entry / spLock undefined do
/ lockState off exit / set offBtnclick

12
Some Deeper (Advance) UML State Diagrams
  • Concurrent Composite State Diagram contains two
    or more composite state diagrams that may be
    executed in parallel state diagram is divided up
    into compartments by parallel doted lines.

Concurrent Composite State
StateW
Event-K
StateZ
Note 1. Transition to a concurrent composite
state boundary will enter initial states of all
the concurrent state diagrams 2. Or one can
specify the sub states which will be entered,
along with the one specified start state 3.
similarly exits can be specified
Event-A
13
More Advanced UML State Transition Diagramwith
Synchronization Mechanism
EW east-west NSnorth-south
SignalOperationState
after 40 sec
after 5 sec
EW Green
EW Red
EW Yellow
after 35 sec
after 45 sec
NS Red
after 30 sec
NS Yellow
NS Green
after 5 sec
Synch signal used to help regulate transition
SynchronizedSignalOperation
after 35 sec
EW Red
Synch signal used to help regulate transition
after 40 sec
after 5 sec
EW Green
EW Yellow
1
1
after 45 sec
NS Red
after 5 sec
after 30 sec
NS Yellow
NS Green
14
Advanced Mechanism to set History
RadioOn
The history of preset state is remembered
if the radio is turned on after it is turned
off History state, H, says re-enter the state
that was last active
Preset FM
setFM
setAM
Preset AM
Preset Clock
setClock
off
turnOn
H
turnoff
15
Read at least one example from the text on your
own.(Especially the Dialog Map and UI diagram)
Write a Comment
User Comments (0)
About PowerShow.com