Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

state machines and multiple states

Using the traditional definition of state machines, can state machine records be in multiple states at the same time? For example, if I have a User model, can users be in both a subscriber and in a promotional_period state at the same time?

Note, I am not asking if it makes sense to do this, my question is - is it possible with state machines.

like image 717
Dty Avatar asked Feb 10 '13 01:02

Dty


People also ask

Can a state machine be in multiple states?

No. State machines have one state at a time. A combination state could be done with another state, like subscriber_and_promotional_period .

How many states are in a state machine?

It consists of two states, Off and On. On is the initial state here; it is activated when the state machine is executed. The arrows between the states denote the possible state transitions. They define for which input a state change occurs.

Can a state machine have only one state?

A state machine is a mathematical model of computation. It's an abstract concept whereby the machine can have different states, but at a given time fulfills only one of them. There are different types of state machines.

What is the difference between state and state machine?

A state is a description of the status of a system that is waiting to execute a transition. A state machine is also a visual depiction of such an abstract machine.


2 Answers

All the answers saying "no" are only correct if you are assuming the "typical" type of finite state machines (FSMs) known as deterministic finite automata (DFAs), which can only have a single active state at any given time.

However, this is not the only type of FSMs, and there is no good reason to restrict yourself to this type of mechanism in all cases. There are also nondeterministic finite automata (NFAs), which can be in any number of states simultaneously.

This isn't just academic, or even really about parsing (as the wikipedia links might imply): NFAs are actually quite simple and incredibly useful and are used in practice all over the place in both hardware and software implementations.

Basically, to design an NFA, you do it just like a DFA, but instead of having a "current state" and using the inputs to compute a "next state", you have a "current state set" and use the inputs to compute a "next state set". In hardware (e.g. FPGAs implemented in VHDL) this can be done literally simultaneously. In (single-threaded) software, this is typically done by just iterating through the current states in each "step" of the machine.

like image 56
wjl Avatar answered Sep 20 '22 15:09

wjl


No. State machines have one state at a time.

A combination state could be done with another state, like subscriber_and_promotional_period. This is the usual way to do it.

like image 33
ameed Avatar answered Sep 21 '22 15:09

ameed