ProtocolLearner
Class FSAutomaton

java.lang.Object
  extended by ProtocolLearner.FSAutomaton

public class FSAutomaton
extends java.lang.Object

Abstract Finite State Automaton class. It provides basic operations to populate and manipulate finite state automaton. This is an extended version of the FSA since it allows sequences of output messages to be associated with the input sequences.

Author:
Serge Gorbunov

Constructor Summary
FSAutomaton()
          Constructor.
 
Method Summary
 boolean addOuputSymbol(int srcState, int dstState, java.lang.String inSymbol, java.util.ArrayList<java.lang.String> outSymbols)
          Add an output message to an array of output message sequences for the particular input on a given state
 int addState()
          Adds a new state to the set of states
 int addTransition(int srcState, FSATransition transition)
          Add a transition object to the automaton
 int addTransition(int srcState, java.lang.String intputSymbol, int dstState)
          Adds a next transition function to the automaton
 int addTransition(int srcState, java.lang.String inputSymbol, int dstState, java.util.ArrayList<java.lang.String> outputSymbols)
          Adds a next transition function to the automaton
 boolean checkIfStatesAreIdentical(int stateID1, int stateID2)
          Function compares two states based on their transitions and colors of their children.
 boolean checkOutputMsg(int srcState, java.lang.String input, java.util.ArrayList<java.lang.String> output)
          Check if the output strings of the given input symbol in the automaton math to the output symbols of the given input
 int checkTransition(int srcState, java.lang.String input)
          Checks if a transition exists from a states based on the certain input
 int getInitStateIndex()
          Returns the index of the initial state
 java.awt.Color getStateColor(int stateID)
          Returns the color of the state
 int getStateHeight(int stateID)
          Returns the height of the state
 java.util.HashMap<java.lang.Integer,java.awt.Color> getStates()
          Returns all states in the automaton
 java.util.ArrayList<java.lang.Integer> getStatesWithSpecHeight(int height)
          Returns the array list of states with a particular height
 java.util.Set<java.lang.Integer> getStatesWithTrans()
          Returns the list of states that have transitions
 java.util.ArrayList<FSATransition> getStateTransition(int stateID)
          Returns the set of transition functions for a state.
 boolean removeSubtree(int subtreeStateID)
          A recursive function to remove a subtree from a FSA
 boolean removeTransitionFromState(int stateID, int dstStateID)
          A function that remove a specific transition for some input from a state
 boolean setStateColor(int stateID, java.awt.Color c)
          Modifies the color of a particular state
 boolean setStateHeight(int stateID, int height)
          Sets the height of the state to a specific value
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FSAutomaton

public FSAutomaton()
Constructor. Sets the initial state in the automaton is 0, index of the next states to be added is 1

Method Detail

getInitStateIndex

public int getInitStateIndex()
Returns the index of the initial state

Returns:
Index of the root state

addState

public int addState()
Adds a new state to the set of states

Returns:
The index of the added state

addTransition

public int addTransition(int srcState,
                         java.lang.String intputSymbol,
                         int dstState)
Adds a next transition function to the automaton

Parameters:
srcState - Source state
inputSymbol - Input symbol
dstState - Destination state
Returns:
0 if successfully added the transition, -1 if no source state exists, -2 if no destination state exists

addTransition

public int addTransition(int srcState,
                         java.lang.String inputSymbol,
                         int dstState,
                         java.util.ArrayList<java.lang.String> outputSymbols)
Adds a next transition function to the automaton

Parameters:
srcState - source state ID
inputSymbol - input symbol
dstState - destination state
outputSymbols - A list of output symbols associated with the input
Returns:
0 if successfully added the transition, -1 if no source state exists, -2 if no destination state exists

checkTransition

public int checkTransition(int srcState,
                           java.lang.String input)
Checks if a transition exists from a states based on the certain input

Parameters:
srcState - Source state ID
input - Input string to be searched for in the set of transitions of the state
Returns:
Index to the destination transition where transition leads to, or -1 if no such exists

checkOutputMsg

public boolean checkOutputMsg(int srcState,
                              java.lang.String input,
                              java.util.ArrayList<java.lang.String> output)
Check if the output strings of the given input symbol in the automaton math to the output symbols of the given input

Parameters:
src - State Source state ID
input - Input symbol
output - Output message sequence
Returns:
true - if the output message sequence matches to the output message sequence of the transition. False - otherwise

addOuputSymbol

public boolean addOuputSymbol(int srcState,
                              int dstState,
                              java.lang.String inSymbol,
                              java.util.ArrayList<java.lang.String> outSymbols)
Add an output message to an array of output message sequences for the particular input on a given state

Parameters:
srcState - Source state ID
dstState - Destination state ID
inSymbol - Input symbol
outSymbols - Output message sequence
Returns:
True: if output sequence was added successfully, false otherwise

getStates

public java.util.HashMap<java.lang.Integer,java.awt.Color> getStates()
Returns all states in the automaton

Returns:
A map of States, and their associated colors

setStateColor

public boolean setStateColor(int stateID,
                             java.awt.Color c)
Modifies the color of a particular state

Parameters:
State - ID
Returns:
True if the color was successfully changed, false if no such states exists

getStatesWithTrans

public java.util.Set<java.lang.Integer> getStatesWithTrans()
Returns the list of states that have transitions

Returns:
A set of states from the transition hash map

getStateTransition

public java.util.ArrayList<FSATransition> getStateTransition(int stateID)
Returns the set of transition functions for a state.

This method returns null if no state ID is present in the automaton.

Parameters:
stateID - Unique state identifier
Returns:
An array list of transitions or null if no transitions found/no state found.
See Also:
FSAutomaton

getStateColor

public java.awt.Color getStateColor(int stateID)
Returns the color of the state

Parameters:
statID - Unique state ID
Returns:
State color or null if no such state exists

setStateHeight

public boolean setStateHeight(int stateID,
                              int height)
Sets the height of the state to a specific value

Parameters:
stateID - Unique state ID
height - New state height
Returns:
True is the state height was successfully set. False if no stateID was found in the list.

getStateHeight

public int getStateHeight(int stateID)
Returns the height of the state

Parameters:
stateID - Unique state ID
Returns:
The height of the state, or -1 if the state is not found

getStatesWithSpecHeight

public java.util.ArrayList<java.lang.Integer> getStatesWithSpecHeight(int height)
Returns the array list of states with a particular height

Parameters:
height - Height to be searched for among all states
Returns:
An array list of state IDs with the specified height

checkIfStatesAreIdentical

public boolean checkIfStatesAreIdentical(int stateID1,
                                         int stateID2)
Function compares two states based on their transitions and colors of their children. States are considered identical if they have the same input/output transition functions and their children have the same color.

Parameters:
stateID1 - The first unique state ID
stateID2 - The second unique state ID
Returns:
True if the states are identical, false otherwise

removeSubtree

public boolean removeSubtree(int subtreeStateID)
A recursive function to remove a subtree from a FSA

Parameters:
substreeStateID - Unique state ID of the subtree
Returns:
True if the state was successfully removed, False otherwise or if state ID is not found

removeTransitionFromState

public boolean removeTransitionFromState(int stateID,
                                         int dstStateID)
A function that remove a specific transition for some input from a state

Parameters:
stateID - Unique state ID for the state of which transition should be removed
dstStateID - Unique state ID of the destination state of the transition
Returns:
True if the transition was successfully removed, False if state(s) was not found.

addTransition

public int addTransition(int srcState,
                         FSATransition transition)
Add a transition object to the automaton

Parameters:
transition - A new transition object
Returns:
-1 if no source state id exists 0 if everything went fine