Class FiniteStateMachine<S,I>

java.lang.Object
org.episteme.natural.computing.ai.automata.FiniteStateMachine<S,I>

public class FiniteStateMachine<S,I> extends Object
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)
  • Constructor Details

    • FiniteStateMachine

      public FiniteStateMachine(S initialState)
      Creates a new FSM with the given initial state.
      Parameters:
      initialState - the starting state
  • Method Details

    • addState

      public FiniteStateMachine<S,I> addState(S state, boolean accepting)
      Adds a state to the FSM.
      Parameters:
      state - the state to add
      accepting - whether this is an accepting/final state
      Returns:
      this FSM for chaining
    • addTransition

      public FiniteStateMachine<S,I> addTransition(S from, I input, S to)
      Adds a transition from one state to another on a given input.
      Parameters:
      from - source state
      input - input symbol
      to - destination state
      Returns:
      this FSM for chaining
    • process

      public boolean process(I input)
      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

      public boolean processAll(Iterable<I> inputs)
      Processes a sequence of inputs.
      Parameters:
      inputs - the input sequence
      Returns:
      true if all inputs were processed successfully
    • getCurrentState

      public S getCurrentState()
      Returns the current state.
      Returns:
      current state
    • 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

      public Set<S> getStates()
      Returns all states.
      Returns:
      unmodifiable set of states
    • addStateChangeListener

      public void addStateChangeListener(FiniteStateMachine.StateChangeListener<S,I> listener)
      Adds a state change listener.
      Parameters:
      listener - the listener