Package org.svvrl.goal.core.aut
Class DFS
java.lang.Object
org.svvrl.goal.core.aut.DFS
- Direct Known Subclasses:
DoubleDFS
,MSCCFinder.Finder
public class DFS
extends java.lang.Object
This class provides depth-first searches (DFS) in an automaton. The
depth-first search is implemented by a stack. This class is not thread-safe.
Do not invoke more than one DFS concurrently in the same
DFS
object.
Note that if the automaton has disconnected states, those states may not be
visited.- Author:
- Ming-Hsien Tsai
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
dfs()
Performs a DFS in the input automaton from the initial states.void
dfs(java.util.Set<State> states)
Performs a DFS in the input automaton from a specified set of states.void
dfs(State s)
Performs a DFS in the input automaton from a specified state.Automaton
getAutomaton()
Returns the automaton where this DFS is performed.int
getDFSNumber(State s)
Returns the DFS number of a state (starting from 0).StateSet
getUnvisitedStates()
Returns the unvisited states.StateSet
getVisitedStates()
Returns the visited states.boolean
isVisitable(State s)
Returnstrue
if a specified state can be visited.boolean
isVisited(State s)
Returnstrue
if a specified state was visited during some previous DFS.protected void
onAllSuccessorsReturned(StateList prefix, State curr)
Invoked after the depth-first search of all successors of a state returns.protected void
onSuccessorReturned(StateList prefix, State curr, State succ)
Invoked when returning from the depth-first search of a successor.protected void
onVisitedStateFound(StateList prefix, State curr, State visited)
Invoked when a visited state is encountered.protected void
onVisitState(StateList prefix, State curr)
Invoked when a state is visited at the first time.State
proposeNextUnvisitedState()
Proposes the next unvisited state for the start of a DFS.void
reset()
Resets this DFS.void
setVisitable(StateSet states)
Makes this DFS visit only a specified set of states.
-
Constructor Details
-
DFS
Constructs this DFS to search in an automaton.- Parameters:
automaton
- an automaton
-
-
Method Details
-
getAutomaton
Returns the automaton where this DFS is performed.- Returns:
- the automaton where this DFS is performed
-
setVisitable
Makes this DFS visit only a specified set of states.- Parameters:
states
- a set of states that can be visited
-
isVisitable
Returnstrue
if a specified state can be visited.- Parameters:
s
- a state- Returns:
true
if the state can be visited
-
reset
public void reset()Resets this DFS. -
isVisited
Returnstrue
if a specified state was visited during some previous DFS.- Parameters:
s
- a state- Returns:
true
if the state was visited during some previous DFS
-
getDFSNumber
Returns the DFS number of a state (starting from 0).- Parameters:
s
- a state- Returns:
- the DFS number of a state, or -1 if the state was not visited in any performed DFS
-
getVisitedStates
Returns the visited states.- Returns:
- a set of visited states
-
getUnvisitedStates
Returns the unvisited states. Note that states that cannot be visited will not be returned.- Returns:
- a set of unvisited states
- See Also:
setVisitable(StateSet)
-
onVisitState
Invoked when a state is visited at the first time.- Parameters:
prefix
- a path from the root to the current statecurr
curr
- the current state to be visited- Throws:
FinishedException
- if the depth-first search should stop here
-
onSuccessorReturned
protected void onSuccessorReturned(StateList prefix, State curr, State succ) throws FinishedExceptionInvoked when returning from the depth-first search of a successor.- Parameters:
prefix
- the path from the root to the current statecurr
curr
- the current statesucc
- the successor ofcurr
- Throws:
FinishedException
- if the depth-first search should stop here
-
onAllSuccessorsReturned
Invoked after the depth-first search of all successors of a state returns.- Parameters:
prefix
- the path from the root to the current statecurr
curr
- the current state- Throws:
FinishedException
- if the depth-first search should stop here
-
onVisitedStateFound
protected void onVisitedStateFound(StateList prefix, State curr, State visited) throws FinishedExceptionInvoked when a visited state is encountered.- Parameters:
prefix
- a path from the root to the current statecurr
curr
- the current state which is the last state inprefix
visited
- the state that has been visited. It must be a successor ofcurr
.- Throws:
FinishedException
- if the depth-first search should stop here
-
proposeNextUnvisitedState
Proposes the next unvisited state for the start of a DFS. Below is the priority of the proposed states.- Initial state.
- State that has no predecessor or have itself as the only predecessor.
- Other state
- Returns:
- an unvisited state, or
null
if all states were visited
-
dfs
public void dfs()Performs a DFS in the input automaton from the initial states. -
dfs
Performs a DFS in the input automaton from a specified state.- Parameters:
s
- the start of the DFS
-
dfs
Performs a DFS in the input automaton from a specified set of states.- Parameters:
states
- the starts of the DFS
-