Questions tagged [fsm]

Acronym for Finite State Machine.

Finite state machine, finite state automata, or state machine, is used in computer science or logic theory to represent a finite number of states and the transitions between states.

Finite state machines are commonly used in parsing and matching strings, so it accepts certain types of strings (such as those representing an integer), and a language (set of strings) is regular if and only if it can be represented as a finite state machine.

An example of a finite state machine implementation in pseudocode, accepting all decimal integers:

state = 0;
digits = "152341264"; // Some sequence of decimal digits
for (k = 0; k < len(digits); k++) {
    switch (state) {
    case 0: // Initial state
        if (digits[k] is a decimal digit)
            state = 1;
        else
            state = 2;
        break;
    case 1: // Digit found, also an accepting state
        if (digits[k] is a decimal digit)
            state = 1;
        else
            state = 2;
        break;
    case 2: // Dead state
        break;
    }
}
FSM accepts the string digits if it finishes at state 1.

Finite state machines represent all the regular languages, or Type 3 languages, which are the lowest in the Chomsky hierarchy, below the context-free (Type 2) languages, which is below the context-sensitive (Type 1) languages, which is below the recursively enumerable (Type 0) languages.

Wikipedia page

The tag is also known like on stackoverflow.

533 questions
3
votes
2 answers

Compile Finite State Machine to UML(-like) Diagram

Every Python developer knows tools like Sphinx. You write some text in a markup language, write make in the shell and let some compilers do their job. In the end you get beautiful HTML or PDF. I am looking for something like that, just for Finite…
erikbstack
  • 12,878
  • 21
  • 81
  • 115
3
votes
3 answers

Unity Performance - Coroutines vs FSM on update

I just started studying Unity scripting and I'm having a hard time to understand why some people prefer coroutines over state machines. I do understand that the code might be more readable for some programmers, but I can't understand why some…
Hodor
  • 166
  • 1
  • 8
3
votes
2 answers

What are Erlang Alternatives?

What are the closest framework to Erlang for other programming languages like Java, C++ especially for Embedded linux application The framework support a close flavor of the FSM model of Erlang in addition to other main features of Erlang so for…
iCode
  • 4,308
  • 10
  • 44
  • 77
3
votes
2 answers

Switching between various screens of the same state type?

I've been having an issue with the basic structure of a program that I'm working on. I'm a very inexperienced programmer trying to teach myself the basics of programs that use multiple states. Right now, I have a very simple game-ish program with a…
MrKatSwordfish
  • 1,504
  • 5
  • 18
  • 30
3
votes
0 answers

Is an FSM the right solution for my asynchronous, Akka Actor based calculation engine

I am writing a calculation engine (implemented as an Akka Actors) that will use a few asynchronous and concurrent actors to perform some data retrieval as well as some parts of the calculation. When the main actor receives a message to start the…
garyKeorkunian
  • 421
  • 4
  • 7
3
votes
2 answers

Verilog, FPGA, use of an unitialized register

I have a question about what seems to me odd behavior of an AGC/SPI controller I'm working on. It's done in Verilog, targeting a Xilinx Spartan 3e FPGA. The controller is a FSM that relies on external inputs to start. The state of the FSM is…
Frank Dejay
  • 689
  • 5
  • 13
  • 17
2
votes
2 answers

Is the dk.brics.automaton package thread safe?

Apache Lucene uses a modified form of the Brics automaton package. But is Brics thread safe? More specifically, can it safely handle multiple, concurrent automaton instances from different threads - without blocking?
Ashwin Jayaprakash
  • 2,168
  • 24
  • 29
2
votes
3 answers

Parsing file using finite state machine

I am implementing my own fsm to parse a file. I am new to fsm pattern so trying to learn about it. My fsm class takes a stream of the file that is being parsed along with the current state and a collection of all accepting states. Now I am…
Obaid
  • 4,328
  • 9
  • 42
  • 42
2
votes
1 answer

Terminate gen_fsm if no event come

I want my FSM to terminate any time event doesn't come after specified amout of time in every state. I can achieve such a scenario only in case there is no event after FSM creation by specifing timeout value in init callback, but I would like to…
mkorszun
  • 4,461
  • 6
  • 28
  • 43
2
votes
1 answer

Clean Architecture For Creating Different Finite State Machines Within Single Application

Looking for a way to avoid duplication when creating different, flexible FSMs within single application. I have a concept below, under the heading 0: BEFORE Requirements Change. This concept shows how FSMs of different products can be created, and…
2
votes
1 answer

from HFSM with parallel states to Camunda?

I was tasked with implementing an HFSM with parallel states and the ability to transition to multiple parallel states in Python. Unfortunately, I could not find a library that supported this. I was told to look into Camunda. I am having trouble…
2
votes
1 answer

How to pass parameters to on_enter callbacks in `transitions` library?

I want to use transitions, and need a rather trivial feature I could not find in the docs, and was wondering if it was implemented: I want to define a on_enter callback on some state, but pass a parameter to that callback. At least to know from…
Gulzar
  • 23,452
  • 27
  • 113
  • 201
2
votes
1 answer

Divide Binary Numbers FSM

Note: this question can be solved by math experts too. Today I learnt about FSM, My lecturer said for example if we are given a number in binary (being inserted from its MSB to LSB) we can decide if it's divisible by 7 using 7 states where each…
user14686745
2
votes
1 answer

Hierarchical State Machine (HSM) Current State

I am researching HSM and I have a question about. In HSM (for all system), is there only one current state? For example; In my project, there is two user type : normal user and technician user. There is no identicality between them. Normal user can…
kaernk
  • 63
  • 6
2
votes
2 answers

State Machine using immutable Records in F#

I have the following definiition for a State Machine in F#: type MyEvent = Event1 | Event2 | Event3 type MachineState<'event when 'event:comparison> = { Transitions: Map<'event, MachineState<'event>> Data: int //...other State…
fnzr
  • 171
  • 9