Deterministic Finite State Machines
A Deterministic Finite State Machine (DFSM) [1] is a model of states, events, and transitions between states based on the current state and a given event. Starting from an initial state, a DFSM accepts a sequence of events (also called word) if the state reached when processing all events is a final state.
Type Definition
States and events are represented as either symbols or first-order logic atoms.
For convenience, we define a shortcut to sets of states and events.
A transition maps a tuple of a state and event to a state.
A set of transitions is constrained to contain at most one successor to any state-event combination.
Finally, we define a Deterministic Finite State Machine (DFSM) as a tuple containing a set of states, a set of events, a set of transitions, and initial state, and a set of final states. The constraint asserts that all events and states are part of their respective sets.
The full AIDDL type definition can be found here.
Example Input
The following entry contains an instance of a DFSM with two states s1 and s2, two events a and b, three transitions, initial state s1 and a single final state s2.
The aiddl file containing this example can be found here.
Implementation Overview
The Scala implementation of a DFSM can be found here.
It loads a DFSM via the initializable trait. Afterwards, the apply method allows to traverse the state space by sending single events or sequences of events, checking the current state and wether it is a final state, and resetting the machine.
Try It Yourself
First, we create a container, parse the test file and load the entry.
Next, we create an instance of our DFSM implementation and initialize it with the entry shown above.
Now we can step with single events.
We can use multi-step to move through a sequence of events.
Finally, we perform another step that moves to s2, check again on the current state and confirm that this is the final state.
The test case containing this code can be found here.
References
[1] Sipser, Michael (2013). "Introduction to the Theory of Computation". Cengage Learning.