public class GeneralDeterministicFiniteAutomaton extends java.lang.Object implements DeterministicFiniteAutomaton
Modifier and Type | Field and Description |
---|---|
protected int |
alphabetSize |
protected short |
initialState |
protected java.lang.String |
label |
protected short[][] |
matrix
Stores the representation of this automaton.
|
Constructor and Description |
---|
GeneralDeterministicFiniteAutomaton(java.lang.String label,
int alphabetSize)
Constructs a DFA over a given alphabet from [0..alphabetSize) (exclusive)
without states.
|
GeneralDeterministicFiniteAutomaton(java.lang.String label,
int alphabetSize,
int matrixSize)
Constructs a DFA over a given alphabet from [0..alphabetSize) (exclusive)
without states.
|
Modifier and Type | Method and Description |
---|---|
short |
addState(boolean isInitial,
byte type,
boolean addSelfLoops)
Adds a new state to the matrix
|
void |
addTransition(short fromS,
short toS,
short label)
Add a transition from state fromS to state toS labeled with label
|
void |
complete()
Adds a single PV type state to which all other states can transition
using any label not currently in the DFA.
|
boolean |
equals(java.lang.Object o) |
short |
getInitialState()
Returns the initial state
|
java.lang.String |
getLabel() |
short |
getNextState(short currentState,
int label)
returns the new state after executing a transition with the given label
in currentState, or NOSTATE is no such new state exists.
|
byte |
getStateType(short state)
Returns the type of the state (PV, TV, PS, or TS)
|
int |
hashCode() |
boolean |
isAcceptingState(short state)
Returns true if the given state is an accepting state
|
boolean |
isAllowed(short currentState,
int label)
Checks if the transition with the given label is possible in the given
state
|
boolean |
isComplete()
Check if the automaton is complete, i.e.
|
void |
reduce()
Reduces the DFA to remove all permanently violated states by simply
removing all transitions into these states and then removing unreachable
states.
|
void |
removeTransition(short fromS,
short label)
Remove transition labeled with label from state fromS
|
void |
setInitialState(short state)
Sets the initial state
|
void |
setStateType(short state,
byte type) |
java.lang.String |
toString() |
protected final int alphabetSize
protected short[][] matrix
protected short initialState
protected final java.lang.String label
public GeneralDeterministicFiniteAutomaton(java.lang.String label, int alphabetSize)
alphabetSize
- public GeneralDeterministicFiniteAutomaton(java.lang.String label, int alphabetSize, int matrixSize)
alphabetSize
- public short addState(boolean isInitial, byte type, boolean addSelfLoops)
DeterministicFiniteAutomaton
addState
in interface DeterministicFiniteAutomaton
public void addTransition(short fromS, short toS, short label)
DeterministicFiniteAutomaton
addTransition
in interface DeterministicFiniteAutomaton
public void removeTransition(short fromS, short label)
DeterministicFiniteAutomaton
removeTransition
in interface DeterministicFiniteAutomaton
public short getNextState(short currentState, int label)
DeterministicFiniteAutomaton
getNextState
in interface DeterministicFiniteAutomaton
public boolean isAllowed(short currentState, int label)
DeterministicFiniteAutomaton
isAllowed
in interface DeterministicFiniteAutomaton
public short getInitialState()
DeterministicFiniteAutomaton
getInitialState
in interface DeterministicFiniteAutomaton
public void setInitialState(short state)
DeterministicFiniteAutomaton
setInitialState
in interface DeterministicFiniteAutomaton
public boolean isAcceptingState(short state)
DeterministicFiniteAutomaton
isAcceptingState
in interface DeterministicFiniteAutomaton
public void setStateType(short state, byte type)
setStateType
in interface DeterministicFiniteAutomaton
public void reduce()
DeterministicFiniteAutomaton
reduce
in interface DeterministicFiniteAutomaton
public void complete()
DeterministicFiniteAutomaton
complete
in interface DeterministicFiniteAutomaton
public boolean isComplete()
DeterministicFiniteAutomaton
isComplete
in interface DeterministicFiniteAutomaton
public byte getStateType(short state)
DeterministicFiniteAutomaton
getStateType
in interface DeterministicFiniteAutomaton
public boolean equals(java.lang.Object o)
equals
in interface DeterministicFiniteAutomaton
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface DeterministicFiniteAutomaton
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in interface DeterministicFiniteAutomaton
toString
in class java.lang.Object
public java.lang.String getLabel()
getLabel
in interface DeterministicFiniteAutomaton