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
12
votes
1 answer

State machines and UI: Rendering based on 'node-level' states instead of 'leaf' states

Before proceeding, I'd like to point out that the title of this question was rather difficult to phrase. If a more suitable title should be used, please let me know so that I may change it and make this question more useful to others. OK, on to the…
sookie
  • 2,437
  • 3
  • 29
  • 48
12
votes
2 answers

QT : Using State Machine for UI interactions?

Greetings, We are developing a scientific QT Application which detect the border of a cell.Please refer to following prototype snapshots. Now ,we are going to develop this as a opensource product with a good design and architecture.We reconed that…
Ashika Umanga Umagiliya
  • 8,988
  • 28
  • 102
  • 185
12
votes
10 answers

How would you code a washing machine?

Imagine I have a class that represents a simple washing machine. It can perform following operations in the following order: turn on -> wash -> centrifuge -> turn off. I see two basic alternatives: I can have a class WashingMachine with methods…
Dan
  • 11,077
  • 20
  • 84
  • 119
11
votes
2 answers

Is there any alternative to Apache Commons SCXML?

I'm looking for a good and universal state machine and so far I've found SCXML. It's really simple to use (I mean the configuration) but the source code is archaic - there is no type safety and all collections are raw types. I don't have to say how…
user219882
  • 15,274
  • 23
  • 93
  • 138
11
votes
4 answers

Named scopes for states in state_machine

I use state_machine with ActiveRecord on one of my Rails 3.1 application. I found the syntax to access records with different states to be cumbersome. Is it possible to define each state to be the scope at the same time without writing scope…
Andrew
  • 8,330
  • 11
  • 45
  • 78
11
votes
3 answers

Does statemachine and statechart mean the same?

I have heard people using these terms. I wonder if they refer to the same thing or is there a difference between these two?
ajsie
  • 77,632
  • 106
  • 276
  • 381
11
votes
6 answers

State machine transitions at specific times

Simplified example: I have a to-do. It can be future, current, or late based on what time it is. Time State 8:00 am Future 9:00 am Current 10:00 am Late So, in this example, the to-do is "current" from 9 am to 10…
wesgarrison
  • 6,975
  • 5
  • 30
  • 39
11
votes
7 answers

Truth tables in code? How to structure state machine?

I have a (somewhat) large truth table / state machine that I need to implement in my code (embedded C). I anticipate the behavior specification of this state machine to change in the future, and so I'd like to keep this easily modifiable in the…
HanClinto
  • 9,423
  • 3
  • 30
  • 31
11
votes
1 answer

Request for a simple example for GKStateMachine?

I've been researching Apple's state machine for Swift and found several examples, but none of them really dead simple. Could someone whip up a super simple GKStateMachine, perhaps with two states, in Swift, preferably all in one Swift file? Thanks!
Chris Tucker
  • 133
  • 1
  • 6
11
votes
1 answer

State machines for Entities in DDD and Dependency Injection context?

I've been studying Spring State Machine and State design pattern since I have to develop a microservice with Spring Boot and persisted objects with a lot of confused states that need to be cleared up, and I am looking for a clean design solution out…
11
votes
1 answer

General Finite State Machine (Transducer) in Scala

What is the general way to implement a finite state machine (or finite state transducer) in Scala? I often find myself in need for state machine implementation. My typical implementation looks like object TypicalFSM { // actually — finite state…
Arseniy Zhizhelev
  • 2,381
  • 17
  • 21
10
votes
1 answer

How to access state during transitions in Akka FSM

I am using Akka FSM for handling state in my Actor. I want some actions to be performed every time a transition to a certain state occurs, no matter which state the transition was made from. After reading the docs, I felt certain that this could be…
eirirlar
  • 814
  • 6
  • 24
10
votes
4 answers

Finite State Machine with Guards in PHP?

Does anybody know a finite state machine that has guard feature in PHP ?
Bamdad Dashtban
  • 354
  • 3
  • 17
10
votes
5 answers

Best way to implement a large state machine?

Basically I have a state machine that controls a game character's attacks, with timings based on the animation length. So for example: I start at the default state, and if the player hits an attack button it starts an attack, switching the state and…
deek0146
  • 962
  • 6
  • 20
10
votes
3 answers

How to perform FST (Finite State Transducer) composition

Consider the following FSTs : T1 0 1 a : b 0 2 b : b 2 3 b : b 0 0 a : a 1 3 b : a T2 0 1 b : a 1 2 b : a 1 1 a : d 1 2 a : c How do I perform the composition operation on these two FSTs (i.e. T1 o T2) I saw some algorithms but couldn't…
Tasbeer
  • 408
  • 10
  • 17