Package common

Class FSM

java.lang.Object
common.FSM
All Implemented Interfaces:
Configuration

public class FSM extends Object implements Configuration
Deterministic Finite State Automaton (DFSA)
The FSM class defines a DFSA in terms of a 5-tuple, (Q, Σ, δ, q0, F)
  • a finite set of states Q
  • finite set of input symbols called the alphabet Σ
  • transition function δ : Q × Σ → Q
  • one initial or start state q0 ∈ Q
  • a set of accept states F ⊆ Q
The set of states, the set of actions, and the two-dimensional transition table defines the FSM. The initial state is defined by invoking setInitialState(State), and the set of final states with invocations to setFinalStates(State...)
Author:
Krish Pillai
  • Constructor Details

    • FSM

      public FSM(event.State[] states, String[] actions, event.State[][] transitions)

      The FSM class defines a DFSA in terms of a 5-tuple, (Q, Σ, δ, q0, F). For each state q in Q and each input symbol a in Σ, let δ(q, a) = p. Then the transition diagram has an arc from node q to node p, labeled a.

      Reference: Introduction to Automata Theory, Language, and Computation- Hopcroft, Motwane, and Ullman
      Invoke start() only after setting initial and final states. Initial state has to be defined. Final states are not required.

      Parameters:
      states - Represents Q. For each state in Q, there is a node
      actions - Set of input symbols
      transitions - The transition table containing δ(q, a)
      See Also:
  • Method Details

    • inFinalState

      public boolean inFinalState()
      Returns true if the state is designated a final state. There can be multiple final states
      Returns:
      true or false
    • inInitialState

      public boolean inInitialState()
      Returns true if the state is designated a final state. There can be only one initial state for a given FSM.
      Returns:
      true or false
    • getCurrentState

      public event.State getCurrentState()
      Gives the current state of the FSM.
      Returns:
      the current state
      See Also:
      • State
    • getInitial

      public event.State getInitial()
      Returns:
      the initial
    • getAccepting

      public event.State[] getAccepting()
      Returns:
      the accepting
    • transition

      public void transition(String action)
      Computes the next state for the specified action based on the transition table. This method then invokes the overridden State.manage() method.
      Parameters:
      action - String defining the action
    • addStateChangeListener

      public void addStateChangeListener(event.StateChangeListener listener)
      Defines a listener for this FSM. If listener is not null, it will be notified of a state change whenever the State.manage() invocation completes.
      Parameters:
      listener - the listener
      See Also:
      • State
      • StateChangeListener
      • State.manage()
    • setInitialState

      public void setInitialState(event.State state)
      Defines the initial state of this FSM
      Parameters:
      state - the initial state
    • setFinalStates

      public void setFinalStates(event.State... states)
      Defines the final state of this FSM. There can be multiple final states. The final states can be supplied either as an array or a comma separated list. An FSM with no final state will run forever.
      Parameters:
      states - the comma separated list of final states
    • start

      public void start()
      Puts this FSM into run state and invokes the manage() method on the initial state. The initial state should be defined. A severe error is reported and an abend occurs if initial state is undefined.
    • pause

      public void pause()
      Suspends the FSM.
    • resume

      public void resume()
      Puts this FSM into run state
    • toString

      public String toString()
      Overrides:
      toString in class Object