Questions tagged [state-machine]

A State Machine is a computation model used to design both computer programs and sequential logic circuits. It determines that an entity in a program can be in one of a finite number of states. The state it is in at any given time is called the current state. It can change from one state to another when initiated by a triggering event or condition; this is called a transition.

A state machine is an abstract machine, which possesses

  • State a condition that when tested will be either true or false
  • Transitions the result of true/false decision to another State
  • Entry actions (what happens when a state is entered)
  • Exit actions (analogous to entry actions)

As a result, a system can dynamically change its behavior based upon what it is currently doing and what input it receives - this allows state machines to model many types of systems. (An familiar example is Regex - Perl, Python, Tcl, .NET, and most other implementations use a state machine internally).

For example, consider a printer, which can be either waiting for a job, or printing it (states), and can start printing when a job is received and start waiting when it is done with the current job (transitions). Send notification is an exit action for the "Printing" state, to notify the print queue that it is done.

SDL description of a printer

(The above diagram is in the SDL format - UML is also popular for representing state diagrams).

#Related tags - The Coyote open source asynchronous programming framework

1708 questions
309
votes
23 answers

Simple state machine example in C#?

Update: Again thanks for the examples, they have been very helpful and with the following, I don't mean to take anything away from them. Aren't the currently given examples, as far as I understand them & state-machines, only half of what we usually…
Jennifer Owens
  • 4,044
  • 5
  • 19
  • 22
203
votes
26 answers

C state-machine design

I am crafting a small project in mixed C and C++. I am building one small-ish state-machine at the heart of one of my worker thread. I was wondering if you gurus on SO would share your state-machine design techniques. NOTE: I am primarily after…
jldupont
  • 93,734
  • 56
  • 203
  • 318
183
votes
3 answers

What is an actual difference between redux and a state machine (e.g. xstate)?

I am working on investigation of one front-end application of medium complexity. At this moment it is written in pure javascript, it has a lot of different event-based messages connecting few main parts of this application. We decided that we need…
Artem Arkhipov
  • 7,025
  • 5
  • 30
  • 52
156
votes
5 answers

Boost Statechart vs. Meta State Machine

Apparently boost contains two separate libraries for state machines: Statechart and Meta State Machine (MSM). The taglines give very similar descriptions: Boost.Statechart - Arbitrarily complex finite state machines can be implemented in easily…
FireAphis
  • 6,650
  • 8
  • 42
  • 63
100
votes
8 answers

Use cases of the Workflow Engine

I'd like to know about specific problems you - the SO reader - have solved using Workflow Engines and what libraries/frameworks you used if you didn't roll your own. I'd also like to know when a Workflow Engine wasn't the best choice and if/how you…
96
votes
6 answers

Is a Markov chain the same as a finite state machine?

Is a finite state machine just an implementation of a Markov chain? What are the differences between the two?
Carson
  • 17,073
  • 19
  • 66
  • 87
81
votes
8 answers

state machines tutorials

I am just wondering if anyone know of some good tutorials on the Internet for developing state machines. Or ebooks? I am starting working on state machines and just need something general to get me started.
ant2009
  • 27,094
  • 154
  • 411
  • 609
68
votes
18 answers

uses for state machines

In what areas of programming would I use state machines ? Why ? How could I implement one ? EDIT: please provide a practical example , if it's not too much to ask .
Geo
  • 93,257
  • 117
  • 344
  • 520
66
votes
11 answers

How useful is Turing completeness? are neural nets turing complete?

While reading some papers about the Turing completeness of recurrent neural nets (for example: Turing computability with neural nets, Hava T. Siegelmann and Eduardo D. Sontag, 1991), I got the feeling that the proof which was given there was not…
Albert
  • 65,406
  • 61
  • 242
  • 386
64
votes
1 answer

Akka finite state machine instances

I am trying to leverage Akka's finite state machine framework for my use case. I am working on a system that processes a request that goes through various states. The request here is the application name that needs to be deployed along with the…
user_mda
  • 18,148
  • 27
  • 82
  • 145
64
votes
8 answers

How to implement a FSM - Finite State Machine in Java

I have something to do for work and I need your help. We want to implement a FSM - Finite State Machine, to identify char sequence(like: A, B, C, A, C), and tell if it accepted. We think to implement three classes: State, Event and Machine. The…
Ofir A.
  • 3,112
  • 11
  • 57
  • 83
51
votes
3 answers

get list of state_machine states

We are using state_machine ( https://github.com/pluginaweek/state_machine ) in a project and would like to offer a form with a select that lets us choose a state. (this is for searching, not for setting). I can't seem to find a way to list out all…
phil
  • 4,668
  • 4
  • 33
  • 51
51
votes
3 answers

Why does this take so long to match? Is it a bug?

I need to match certain URLs in web application, i.e. /123,456,789, and wrote this regex to match the pattern: r'(\d+(,)?)+/$' I noticed that it does not seem to evaluate, even after several minutes when testing the…
abhillman
  • 3,942
  • 1
  • 20
  • 21
50
votes
12 answers

Python state-machine design

Related to this Stack Overflow question (C state-machine design), could you Stack Overflow folks share your Python state-machine design techniques with me (and the community)? At the moment, I am going for an engine based on the following: class…
jldupont
  • 93,734
  • 56
  • 203
  • 318
49
votes
7 answers

What is the difference between a state machine and the implementation of the state pattern?

I wonder if a state machine is just the state pattern at work or if there is actually a difference between those two? I found this article with the bold title "the state design pattern vs state machine" but at the end of the day he only says that…
Christoph
  • 26,519
  • 28
  • 95
  • 133
1
2 3
99 100