State machine diagrams are a familiar technique to describe the behavior of a System. Various forms of State diagrams haue been around since the 1960s and the earliest object-oriented techniques adopted them to show behavior. In object-oriented approaches, you draw a State machine diagram for a single dass to show the lifetime behavior of a single object.
Whenever people write about State machines, the examples are inevitably cruise controls or vending machines . As I’m a little bored wich them, 1 decided to use a controller for a secret panel in a Gothic castle . In this castle, 1 wanz to keep my valuables in a safe that’s hard to find . So to reveal the lock to the safe, 1 haue to remove a strategic candle from its holder, but this will reveal the lock only while the door is closed . Once 1 can See the lock, I can insert my key to open the safe . For extra safety, 1 make sure that 1 can open the safe only if 1 replaces the candle first . If a thief neglects this precaution, I’ll unleash a nasty monster to devour him.
A state diagram is a type of diagram used in computer science and related fields to describe the behavior of systems. State diagrams require that the system described is composed of a finite number of states; sometimes, this is indeed the case, while at other times this is a reasonable abstraction. Many forms of state diagrams exist, which differ slightly and have different semantics.
Overview
State diagrams are used to give an abstract description of the behavior of a system. This behavior is analyzed and represented by a series of events that can occur in one or more possible states. Hereby “each diagram usually represents objects of a single class and track the different states of its objects through the system”.
State diagrams can be used to graphically represent finite-state machines (also called finite automata). This was introduced by Claude Shannon and Warren Weaver in their 1949 book The Mathematical Theory of Communication. Another source is Taylor Booth in his 1967 book Sequential Machines and Automata Theory. Another possible representation is the state-transition table.
Directed graph
A classic form of state diagram for a finite automaton (FA) is a directed graph with the following elements (Q, Σ, Z, δ, q0, F):[2][3]
- Vertices Q: a finite set of states, normally represented by circles and labeled with unique designator symbols or words written inside them
- Input symbols Σ: a finite collection of input symbols or designators
- Output symbols Z: a finite collection of output symbols or designators
The output function ω represents the mapping of ordered pairs of input symbols and states onto output symbols, denoted mathematically as ω : Σ × Q→ Z.
- Edges δ: represent transitions from one state to another as caused by the input (identified by their symbols drawn on the edges). An edge is usually drawn as an arrow directed from the present state to the next state. This mapping describes the state transition that is to occur on input of a particular symbol. This is written mathematically as δ : Q × Σ → Q, so δ (the transition function) in the definition of the FA is given by both the pair of vertices connected by an edge and the symbol on an edge in a diagram representing this FA. Item δ(q, a) = p in the definition of the FA means that from the state named q under input symbol a, the transition to the state p occurs in this machine. In the diagram representing this FA, this is represented by an edge labeled by a pointing from the vertex labeled by q to the vertex labeled by p.
- Start state q0: (not shown in the examples below). The start state q0 ∈ Q is usually represented by an arrow with no origin pointing to the state. In older texts,[2][4] the start state is not shown and must be inferred from the text.
- Accepting state(s) F: If used, for example for accepting automata, F ∈ Q is the accepting state. It is usually drawn as a double circle. Sometimes the accept state(s) function as “Final” (halt, trapped) states.
For a deterministic finite automaton (DFA), nondeterministic finite automaton (NFA), generalized nondeterministic finite automaton (GNFA), or Moore machine, the input is denoted on each edge. For a Mealy machine, input and output are signified on each edge, separated with a slash “/”: “1/0” denotes the state change upon encountering the symbol “1” causing the symbol “0” to be output. For a Moore machine the state’s output is usually written inside the state’s circle, also separated from the state’s designator with a slash “/”. There are also variants that combine these two notations.
For example, if a state has a number of outputs (e.g. “a= motor counter-clockwise=1, b= caution light inactive=0”) the diagram should reflect this : e.g. “q5/1,0” designates state q5 with outputs a=1, b=0. This designator will be written inside the state’s circle.