|
Search this API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objecty.algo.Dfs
public class Dfs
Framework class for implementing depth first search (DFS) based algorithms.
A depth first search starts from a specified node and traverses the neighbors within a branch as deeply as possible (i.e., without visiting any vertex twice) before backtracking.
A depth first search traversal induces a DFS forest that may consist of more than one DFS tree. Based on these trees, the edges are divided into four categories (see example):
During a DFS run each node of the graph can be in one of the following states:
Graph algorithms, which are based on a depth first search, can extend this class and override appropriate callback methods provided by this class.


| Field Summary | |
|---|---|
protected static java.lang.Object |
BLACK
A constant indicating a node has been completed. |
protected static java.lang.Object |
GRAY
A constant indicating a node has already been visited, but has not been completed yet. |
protected NodeMap |
stateMap
A NodeMap that holds for each Node an Object indicating the current state of the given
node as it is visited by this algorithm. |
protected static java.lang.Object |
WHITE
A constant indicating a node has not been visited yet. |
| Constructor Summary | |
|---|---|
Dfs()
Creates a new Dfs instance with default settings. |
|
| Method Summary | |
|---|---|
protected void |
cancel()
Cancels the depth first search. |
protected void |
lookFurther(Node v)
Callback method that will be invoked whenever DFS continues its search at a new root node. |
protected void |
postTraverse(Edge edge,
Node node)
Callback method that will be invoked after the DFS has returned from the given node. |
protected void |
postVisit(Node node,
int dfsNumber,
int compNumber)
Callback method that will be invoked whenever a node visit has been completed. |
protected void |
preTraverse(Edge edge,
Node node,
boolean treeEdge)
Callback method that will be invoked if the given edge will be considered the first (and only) time during the DFS. |
protected void |
preVisit(Node node,
int dfsNumber)
Callback method that will be invoked whenever a formerly unvisited node gets visited for the first time. |
void |
setDirectedMode(boolean directed)
Specifies whether or not to interpret the edges of the graph as directed. |
void |
setLookFurtherMode(boolean lookFurther)
Specifies whether or not to continue the depth first search after all nodes reachable from the first node have been visited. |
void |
start(Graph graph)
Starts a depth first search on the given graph. |
void |
start(Graph graph,
Node start)
Starts a depth first search from a given Node of the input graph. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected NodeMap stateMap
NodeMap that holds for each Node an Object indicating the current state of the given
node as it is visited by this algorithm. Each node will be assigned one of the WHITE,
GRAY or BLACK objects that describe the state of the nodes.
protected static final java.lang.Object WHITE
protected static final java.lang.Object GRAY
protected static final java.lang.Object BLACK
| Constructor Detail |
|---|
public Dfs()
Dfs instance with default settings.
| Method Detail |
|---|
public void setDirectedMode(boolean directed)
directed - true if the edges are considered as directed, false otherwisepublic void setLookFurtherMode(boolean lookFurther)
lookFurther - true if the depth first search should continue, false otherwisepublic void start(Graph graph)
The first node of the graph will be visited first.
graph - the input graph
public void start(Graph graph,
Node start)
Node of the input graph.
start node is null, this method returns silently.graph - the input graphstart - the given start node
protected void preVisit(Node node,
int dfsNumber)
By default, this method does nothing. It may be overridden to support custom implementations.
node - the given nodedfsNumber - the DFS number of the given node
protected void postVisit(Node node,
int dfsNumber,
int compNumber)
By default, this method does nothing. It may be overridden to support custom implementations.
node - the given nodedfsNumber - the DFS number of the given nodecompNumber - the completion number of the given node
protected void preTraverse(Edge edge,
Node node,
boolean treeEdge)
By default, this method does nothing. It may be overridden to support custom implementations.
edge - the given edgenode - the node to be visited next only if treeEdge == truetreeEdge - true if the node will be visited, false otherwise
protected void postTraverse(Edge edge,
Node node)
By default, this method does nothing. It may be overridden to support custom implementations.
edge - the given edgenode - the node that has been reached via the given edgeprotected void lookFurther(Node v)
By default, this method does nothing. It may be overridden to support custom implementations.
v - the new root nodeprotected void cancel()
It may be overridden to support custom implementations.
|
© Copyright 2000-2025, yWorks GmbH. All rights reserved. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||