- Forward


State Models
with UML


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

System State
Back SMYC Forward
  • Recall:
    • A system is a set of entities, their attributes, and the relationships between them
    • Attributes are the external manifestations of the way the objects are known or observed
  • System State:
    • The values of the attributes at a particular point (e.g., in time and/or space)
System State (cont.)
Back SMYC Forward
  • A Simple System:
    • A light
  • The Attributes:
    • A boolean named power
  • The Possible States:
    • T (i.e., On)
    • F (i.e., Off)
System State (cont.)
Back SMYC Forward
  • Abstraction Revisited:
    • Recall that abstraction is the process of considering what is important and ignoring what isn’t
  • Unimportant Attributes in this Example:
    • Wattage
    • Voltage
    • Physical Dimensions
  • Why Might Attributes be Unimportant?
    • They don’t change
    • They aren't relevant to the problem at hand
The State Space
Back SMYC Forward
  • Defined:
    • The set of all possible states of a system
  • Kinds of State Spaces:
    • Discrete – each attribute is integer-valued
    • Continuous – each attribute is real-valued
    • Mixed/Hybrid – some attributes are integer-valued and some are real-valued
The State Space (cont.)
Back SMYC Forward
  • The Computer Science Perspective:
    • We are (mostly) interested in digital computers in which everything is discrete
  • The Implication:
    • We (almost) always work with discrete state spaces
System State (cont.)
Back SMYC Forward
  • A Slightly More Complicated Example:
    • A light with one integer attribute, color, and one boolean attribute, power
  • An Individual State:
    • Can be denoted by the ordered pair (power, color) where power can take on the values T and F, and color can take on the values R, G, and B
  • The State Space:
    • {(T, R), (T, G), (T, B), (F, R), (F, G), (F, B)}
The Size of the State Space
Back SMYC Forward
  • An Observation:
    • Even discrete state spaces can be very large (sometimes called state space explosion)
  • Some Discrete Math:
    • Letting \(x_i\) denote the number of values for attribute \(i\) and \(N\) denote the number of attributes, the (maximum) size of the state space, \(S\), is given by
    • \(S = \prod_{i=1}^{N} x_i\)
The Size of the State Space (cont.)
Back SMYC Forward
  • An Example:
    • An HVAC system with two modes (heating and cooling), three levels (low, medium and high), and two zones (upstairs and downstairs) has a size of \(S = 2 \cdot 3 \cdot 2 = 12\)
  • A More Realistic Example:
    • An HVAC system with two modes (heating and cooling), 70 levels (temperatures between 31 and 100), and two zones (upstairs and downstairs) has a size of \(S = 2 \cdot 70 \cdot 2 = 280\)
State Space: An Example
Back SMYC Forward

Use Case Descriptions

OpeningSource_UseCaseDescriptions
State Space: An Example (cont.)
Back SMYC Forward
  • Attributes of Interest:
    • Whether the door is opened or closed
    • Whether the overhead light is off, dim, or bright
  • The State Space:
    • \(\{CLOSED, OPENED\} \times \{OFF, DIM, BRIGHT\}\)
System Dynamics
Back SMYC Forward
  • Recall:
    • A dynamic model describes how a system changes over time (which may be discrete or continuous)
  • Time-Based Models:
    • Describe the system at every point in time regardless of whether the state of the system changes
  • Event-Based Models:
    • Describe the system only at times when specific events (which cause a transition between states) occur
Components of UML Statemachine Diagrams
Back SMYC Forward
  • States:
    • statechart_umlstates
    • In general, the names of states should be adjectives
  • Transitions:
    • statechart_umltransitions
    • In general, the names of transitions should be nouns or verbs
Example UML Statemachine Diagrams (cont.)
Back SMYC Forward
  • The Simple Light Example:
    • statechart_light
  • A Printer:
    • statechart_printer
Pseudo States
Back SMYC Forward
  • Common Pseudo States:
    • Initial State statechart_initial-state
    • Final State statechart_final-state
  • An Example Revisited:
    • statechart_light2
Activities and Effects
Back SMYC Forward
  • Activities in States:
    • statechart_umlactions2
  • Effects of Transitions:
    • statechart_umlactions1
    • The constraint in square brackets is called a guard
Activities and Effects (cont.)
Back SMYC Forward
OpeningSource_ActivitiesOrEffects

In general, one should use an entry action when the behavior should be executed regardless of how the state is entered. On the other hand, one should use an effect when the behavior is specific to the transition.

Activities and Effects (cont.)
Back SMYC Forward
OpeningSource_FourStateModel
A "Real World" Example
Back SMYC Forward

The Transmission Control Protocol (TCP)

statechart_tcp
Timed Transitions
Back SMYC Forward
  • An Observation:
    • Some states are realized for a predetermined amount of time
  • An Example:
    • A Pre-Timed Traffic Light
    • statechart_trafficlight
State Generalization/Specialization
Back SMYC Forward
  • Specialization:
    • A specialization of a set (e.g., an extension of a class) is a subset in which each element has additional attributes in common (i.e., the specialization is less abstract)
  • Generalization:
    • When one generalizes one ignores some attributes (i.e., the generalization is more abstract)
XOR-Composition
Back SMYC Forward
  • The Process:
    • Create a disjunctive superstate from multiple substates
  • Interpretation:
    • A system that is in a superstate is in exactly one of the substates that it can be decomposed into
  • The Rationale:
    • Simplicity
    • Reduction of the state space
XOR-Composition (cont.)
Back SMYC Forward

An Example

statechart_button

In the abstract model, this system has two states, Disabled and Enabled, and transitions between the two as a result of two events, Enable and Disable.

AND-Composition
Back SMYC Forward
  • The Process:
    • Create a conjunctive superstate from multiple substates
  • Interpretation:
    • A system that is in a superstate must be in all of the states that it can be disaggregated into
  • The Rationale:
    • Simplicity
  • Example:
    • A GPS navigation system that, when in the Tracking state, is in both the Navigating state and the Recording state
Orthogonal Regions
Back SMYC Forward
  • The Process:
    • Create an AND-composition in which the substates are independent
  • Rationale:
    • Results in an additive increase in the size of the state space rather than a multiplicative increase
  • Example:
    • A keyboard with a main keypad (that has a normal state and a caps lock state) and a numeric keypad (that has a normal state and a num lock state)
Orthogonal Regions (cont.)
Back SMYC Forward

Example

statechart_keyboard

Note that, because of the orthogonal regions, we do not have to define the states UnlockedPositioning, LockedPositioning, UnlockedNumeric, and UnlockedArrows.

Orthogonal Regions (cont.)
Back SMYC Forward
  • Transitions into Orthogonal States:
    • Fork vertices can be used to split an incoming transition
    • statechart_fork
  • Transitions out of Orthogonal States:
    • Join vertices can be used to merge transitions coming from orthogonal states
    • statechart_join
Submachines
Back SMYC Forward
  • Rationale:
    • A state can sometimes be viewed subsystem (i.e., has sufficient richness of relationships)
  • UML Notation:
    • statechart_submachine
The Art of State Modeling
Back SMYC Forward
  • The System:
    • A light with one integer attribute, color,and one boolean attribute, power
  • The Obvious Model:
    • statechart_colorlight1
The Art of State Modeling (cont.)
Back SMYC Forward

Using AND-Composition for this System

statechart_colorlight2
The Art of State Modeling (cont.)
Back SMYC Forward

Using XOR-Composition for this System

statechart_colorlight3
A Comparison of Different UML Diagrams
Back SMYC Forward
  • State Diagrams:
    • Event-based
  • Activity Diagrams:
    • Timing is incorporated using tokens
  • Sequence Diagrams:
    • Time is incorporated using the vertical dimension
  • Communication Diagrams:
    • Ordering over time is incorporated using sequence numbers
There's Always More to Learn
Back -