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
17
votes
5 answers

java generics design problem (state machine)

i made a state machine and would like it to take advantage of generics in java. currently i dont see the way i can make this work and get pretty looking code. im sure this design problem has been approached many times before, and im looking for…
aepurniet
  • 1,719
  • 16
  • 24
16
votes
3 answers

Explicitly defining flag combinations in an enum

I was thinking of implementing an enum that defines the state of a game object, and I wanted to know if I could directly use flags within the enum's definition, instead of defining the object's state as a collection of flags with no easy,…
J Mor
  • 181
  • 9
16
votes
5 answers

How to persist objects which implement the State pattern?

I am new to the State design pattern and I can't find a proper example of saving different states of an object to the database (SQL Server in my case). The scenario is quite similar [almost identical] to the example described in the following…
MHOOS
  • 5,146
  • 11
  • 39
  • 74
15
votes
2 answers

How to create a simple state machine in java

I am currently learning java and would like to know how to control state in a OO way. I implemented a Pong app. If I wanted multiple states like gameplay and menu, and each one of these states had to execute start, stop and run how would I achieve…
Sam Becker
  • 19,231
  • 14
  • 60
  • 80
14
votes
1 answer

Finite State Transducers in Haskell?

I've been wondering if there is a way to define and work with finite state transducers in Haskell in an idiomatic way. You can approach FSTs as generators (it generates an output of type {x1,x2}), or as recognizers (given an input of type {x1,x2} it…
gonzaw
  • 771
  • 4
  • 17
14
votes
6 answers

Finite State Machine and inter-FSM signaling

Recommendations for languages with native (so no FSM generation tools) support for state machine development and execution and passing of messages/signals. This is for telecoms, e.g implementation of FSMs of this level of complexity. I have…
user172783
13
votes
4 answers

Hidden Markov Models

I want to get started on HMM's, but don't know how to go about it. Can people here, give me some basic pointers, where to look? More than just the theory, I like to do a lot of hands-on. So, would prefer resources, where I can write small code…
13
votes
2 answers

how to access error information in Step Function from previous Function in Catch state

I am wondering how to access the cause of my custom exception raised inside my lambda function. I need to access it at the end of my Step Functions workflow, as shown below. The diagram below is an example of a failed execution. The error…
13
votes
3 answers

What's the difference of Petri Nets and Finite State Machines?

Both of them represent the different states a system can take. So what is the difference of Petri Nets and Finite State Machines? When do I use Petri Nets, and when do I use Finite State Machines?
LJag
  • 321
  • 2
  • 13
13
votes
3 answers

Rails 4 with Pundit & Statesman gem - policy when an object is in a state

I am trying to make an app in Rails 4. I am trying to use statesman gem for states and then pundit for policies. My gemfile has: gem 'statesman', '~> 1.3', '>= 1.3.1' gem 'pundit' I have an article model and an article transitions model and an…
Mel
  • 2,481
  • 26
  • 113
  • 273
13
votes
3 answers

State pattern and guard

Update: State pattern might a wrong way to solve this. Hence, any other pattern is welcome. Basically I'm looking for a way to have guard conditions for each state yet having a clean and maintainable code. How would front-end side routing systems…
Sam R.
  • 16,027
  • 12
  • 69
  • 122
13
votes
1 answer

Stateless state machine library - appropriate way to structure?

How do people structure their code when using the c# stateless library? https://github.com/nblumhardt/stateless I'm particularly interested in how this ties in with injected dependencies, and a correct approach of responsibilities and layering…
dandcg
  • 442
  • 4
  • 16
13
votes
5 answers

How to get this Qt state machine to work?

I have two widgets that can be checked, and a numeric entry field that should contain a value greater than zero. Whenever both widgets have been checked, and the numeric entry field contains a value greater than zero, a button should be enabled. I…
Ton van den Heuvel
  • 10,157
  • 6
  • 43
  • 82
13
votes
4 answers

Can a DFA have epsilon/lambda transitions?

Can´t find anything affirmative about it. And a NFA with any epsilon transition is a epsilon-NFA ? Thanks.
liwing
  • 211
  • 2
  • 3
  • 8
13
votes
2 answers

How to get current state from bbv.Common.StateMachine (now Appccelerate.StateMachine) class?

bbv.Common.StateMachine class is the best state machine code I have ever seen. But it lacks just one thing: getting current state. This is an order tracking system: fsm = new ActiveStateMachine(); …
ramazan polat
  • 7,111
  • 1
  • 48
  • 76