Class FiniteStateMachine<S,I>
java.lang.Object
org.episteme.natural.computing.ai.automata.FiniteStateMachine<S,I>
Finite State Machine (FSM) implementation.
A finite state machine is a mathematical model of computation. It consists of a finite number of states, transitions between states triggered by input symbols, and optionally produces output.
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceListener interface for state changes. -
Constructor Summary
ConstructorsConstructorDescriptionFiniteStateMachine(S initialState) Creates a new FSM with the given initial state. -
Method Summary
Modifier and TypeMethodDescriptionAdds a state to the FSM.voidAdds a state change listener.addTransition(S from, I input, S to) Adds a transition from one state to another on a given input.Returns the current state.Returns all states.booleanChecks if the FSM is in an accepting state.booleanProcesses an input symbol, transitioning to the next state.booleanprocessAll(Iterable<I> inputs) Processes a sequence of inputs.voidreset()Resets the FSM to its initial state.
-
Constructor Details
-
FiniteStateMachine
Creates a new FSM with the given initial state.- Parameters:
initialState- the starting state
-
-
Method Details
-
addState
Adds a state to the FSM.- Parameters:
state- the state to addaccepting- whether this is an accepting/final state- Returns:
- this FSM for chaining
-
addTransition
-
process
Processes an input symbol, transitioning to the next state.- Parameters:
input- the input symbol- Returns:
- true if a transition was made
- Throws:
IllegalStateException- if no transition exists for the input
-
processAll
-
getCurrentState
-
isAccepting
public boolean isAccepting()Checks if the FSM is in an accepting state.- Returns:
- true if current state is accepting
-
reset
public void reset()Resets the FSM to its initial state. -
getStates
-
addStateChangeListener
Adds a state change listener.- Parameters:
listener- the listener
-