Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
State diagram
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== State diagrams versus flowcharts == Newcomers to the state machine formalism often confuse '''[[UML state machine#Basic UML state diagrams|state diagrams]]''' with '''[[flowchart]]s'''. The figure below shows a comparison of a [[UML state machine#Basic UML state diagrams|state diagram]] with a flowchart. A state machine (panel (a)) performs actions in response to explicit events. In contrast, the flowchart (panel (b)) automatically transitions from node to node upon completion of activities.<ref name="Practical UML Statecharts in C/C++, Second Edition: Event-Driven Programming for Embedded Systems">{{cite book | last = Samek | first = Miro | title = Practical UML Statecharts in C/C++, Second Edition: Event-Driven Programming for Embedded Systems | publisher = Newnes | year = 2008 | isbn = 978-0-7506-8706-5 | page = 728}}</ref> :[[Image:statechart vs flowchart.png|State diagram (a) and flowchart (b)]] Nodes of flowcharts are edges in the induced graph of states. The reason is that each node in a flowchart represents a program command. A program command is an action to be executed. A command is not a state, but when applied to the program's state, causes a transition to another state. In more detail, the source code listing represents a program graph. Executing the program graph (parsing and interpreting) results in a state graph. So each program graph induces a state graph. Conversion of the program graph to its associated state graph is called "unfolding" of the program graph. The program graph is a sequence of commands. If no variables exist, then the state consists only of the program counter, which keeps track of program location during execution (what is the next command to be applied). Before executing a command, the program counter is at some position (state before the command is executed). Executing the command moves the program counter to the next command. Since the program counter is the whole state, executing the command changed the state. Thus, the command itself corresponds to a transition between the two states. Now consider the full case, when variables exist and are affected by the program commands being executed. Not only does the program counter change between different program counter locations, but variables might also change values due to the commands executed. Consequently, even if we revisit some program command (e.g. in a loop), this does not imply the program is in the same state. In the previous case, the program would be in the same state because the whole state is just the program counter. Thus, if the program counterpoints to the same position (next command) it suffices to specify that we are in the same state. However, if the state includes variables that change value, we can be at the same program location with different variable values, meaning in a different state in the program's state space. The term "unfolding" originates from this multiplication of locations when producing the state graph from the program graph. A self transition is a transition where the initial and the final state are the same. A representative example is a do loop incrementing some counter until it overflows and becomes 0 again. Although the do loop executes the same increment command iteratively, its state space is not a cycle but a line. This results from the state being the program location (here cycling) combined with the counter value, which is strictly increasing (until the overflow). Thus, different states are visited in sequence until the overflow occurs. After the overflow the counter becomes 0 again, so the initial state is revisited in the state space, closing a cycle in the state space (assuming the counter was initialized to 0). The figure above attempts to show that reversal of roles by aligning the arcs of the state diagrams with the processing stages of the flowchart. One can compare a flowchart to an assembly line in manufacturing because the flowchart describes the progression of some task from beginning to end (e.g., transforming source code input into object code output by a compiler). A state machine generally has no notion of such a progression. The door state machine example shown above is not in a more advanced stage in the "closed" state than in the "opened" state. Rather, it simply reacts differently to the open/close events. A state in a state machine is an efficient way of specifying a behavior, rather than a stage of processing.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)