|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnz.ac.waikato.jdsl.graph.algo.DFS
public class DFS
algorithmic template may be extended to solve a variety of problems on either directed or undirected graphs.
This algorithm runs in O(V+E) time where V is the number of
vertices in the graph, and E is the number of edges. It also uses
O(V+E) additional space to store data about the vertices and edges
during the computation. To this end, it is expected that the
Edges
and Vertices
implement the
Decorable
interface.
This DFS also conforms to the CLR version in that it maintains "parent references" to the previous Vertex in a DFS path as well as "start-" and "finish times".
Field Summary | |
---|---|
static java.lang.Object |
BACK_EDGE
Constant signifying that a marked edge is a back edge. |
static java.lang.Object |
CROSS_EDGE
Constant signifying that a marked edge is a cross edge. |
static java.lang.Object |
EDGE_TYPE
Constant used as key to look up an edge's type. |
static java.lang.Object |
FINISH_TIME
Constant used as key to look up the finish time of a vertex. |
static java.lang.Object |
FORWARD_EDGE
Constant signifying that a marked edge is a forward edge. |
protected InspectableGraph |
graph_
The graph being traversed. |
static java.lang.Object |
PARENT
Constant used as key to look up the parent of a vertex. |
static java.lang.Object |
START_TIME
Constant used as key to look up the start time of a vertex. |
static java.lang.Object |
TREE_EDGE
Constant signifying that a marked edge is a tree edge. |
static java.lang.Object |
TREE_NUMBER
Constant used as key to look up the tree to which a Vertex belongs. |
protected int |
treeNum_
The number of the DFS tree being traversed. |
static java.lang.Object |
UNSEEN
Constant signifying that an edge has not yet been seen. |
static java.lang.Object |
UNVISITED
Constant signifying that an vertex has not been visited |
static java.lang.Object |
VERTEX_STATUS
Constant used as key to look up an vertex's status. |
static java.lang.Object |
VISITED
Constant signifying that an vertex has been visited |
static java.lang.Object |
VISITING
Constant signifying that an vertex is being visited |
protected java.lang.Object |
visitResult_
The result of the traversal. |
Constructor Summary | |
---|---|
DFS()
|
Method Summary | |
---|---|
void |
cleanup()
Cleans up all decorations stored in the provided graph. |
protected void |
dfsVisit(Vertex v)
Performs a recursive depth-first search starting at v |
void |
execute(InspectableGraph g)
Execute a DFS without specifying an initial source vertex. |
void |
execute(InspectableGraph g,
Vertex start)
Runs the depth first search algorithm on a graph. |
java.lang.Integer |
finishTime(Vertex v)
Returns the "Finish time" of a Vertex. |
protected void |
finishVisit(Vertex v)
Called when the search has finished with the vertex. |
protected EdgeIterator |
interestingIncidentEdges(Vertex v)
A method that returns an iterator over those edges incident to the parameter vertex in the graph which should be considered for exploration. |
boolean |
isBackEdge(Edge e)
Tests if an edge is a back edge. |
boolean |
isCrossEdge(Edge e)
Tests if an edge is a cross edge. |
protected boolean |
isDone()
Tests if the depth first search is done. |
boolean |
isForwardEdge(Edge e)
Tests if an edge is a forward edge. |
boolean |
isTreeEdge(Edge e)
Tests if an edge is a tree edge. |
boolean |
isUnseen(Edge e)
Tests if an edge has been seen yet. |
boolean |
isUnvisited(Vertex v)
Tests if a vertex has not been visited. |
boolean |
isVisited(Vertex v)
Tests if a vertex has been visited. |
boolean |
isVisiting(Vertex v)
Tests if a vertex is being visited. |
Vertex |
parent(Vertex v)
Retrieves the parent Vertex of a Vertex |
java.lang.Integer |
startTime(Vertex v)
Returns the "Start time" of a Vertex. |
protected void |
startVisit(Vertex v)
Called when a vertex is visited. |
java.lang.Object |
status(Vertex v)
Accesses the current status of the given Vertex. |
protected void |
traverseBackEdge(Edge e,
Vertex from)
Called when a back edge is traversed. |
protected void |
traverseCrossEdge(Edge e,
Vertex from)
Called when a cross edge is traversed. |
protected void |
traverseForwardEdge(Edge e,
Vertex from)
Called when a forward edge is traversed. |
protected void |
traverseTreeEdge(Edge e,
Vertex from)
Called when a discovery edge is traversed. |
java.lang.Integer |
treeNumber(Vertex v)
Retrieves an index representing a connected DFS component. |
java.lang.Object |
type(Edge e)
Accesses the current type of the given Edge. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.Object EDGE_TYPE
public static final java.lang.Object UNSEEN
public static final java.lang.Object TREE_EDGE
public static final java.lang.Object BACK_EDGE
public static final java.lang.Object FORWARD_EDGE
public static final java.lang.Object CROSS_EDGE
public static final java.lang.Object VERTEX_STATUS
public static final java.lang.Object UNVISITED
public static final java.lang.Object VISITING
public static final java.lang.Object VISITED
public static final java.lang.Object PARENT
public static final java.lang.Object TREE_NUMBER
public static final java.lang.Object START_TIME
public static final java.lang.Object FINISH_TIME
protected InspectableGraph graph_
protected java.lang.Object visitResult_
protected int treeNum_
Constructor Detail |
---|
public DFS()
Method Detail |
---|
public void execute(InspectableGraph g, Vertex start)
g
- An InspectableGraph
on which to run a depth first
search.start
- The Vertex
at which to start the depth first
search.public void execute(InspectableGraph g)
protected void dfsVisit(Vertex v)
v
v
- - the vertex at which to start a DFS.public java.lang.Integer startTime(Vertex v)
v
- - the Vertex to check.public java.lang.Integer finishTime(Vertex v)
v
- - the Vertex to check.public Vertex parent(Vertex v)
v
- - the Vertex whose parent to find.public java.lang.Integer treeNumber(Vertex v)
v
- - the Vertex to check.public java.lang.Object status(Vertex v)
null
is returned.
v
- - the Vertex to check.public boolean isUnvisited(Vertex v)
v
- - the Vertex to check.public boolean isVisiting(Vertex v)
v
- - the Vertex to check.public boolean isVisited(Vertex v)
v
- - the Vertex to check.public java.lang.Object type(Edge e)
null
is returned.
e
- - the Edge to check.public boolean isUnseen(Edge e)
e
- - the Edge to check.public boolean isTreeEdge(Edge e)
e
- - the Edge to check.public boolean isBackEdge(Edge e)
e
- - the Edge to check.public boolean isForwardEdge(Edge e)
e
- - the Edge to check.public boolean isCrossEdge(Edge e)
e
- - the Edge to check.public void cleanup()
protected void startVisit(Vertex v)
protected void traverseTreeEdge(Edge e, Vertex from)
protected void traverseBackEdge(Edge e, Vertex from)
protected void traverseForwardEdge(Edge e, Vertex from)
protected void traverseCrossEdge(Edge e, Vertex from)
protected boolean isDone()
protected void finishVisit(Vertex v)
protected EdgeIterator interestingIncidentEdges(Vertex v)
v
- The vertex for which interesting incident edges shouldbe
returned
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |