Package com.yworks.yshrink.core
Class Dfs
- java.lang.Object
-
- com.yworks.yshrink.core.Dfs
-
public class Dfs extends java.lang.ObjectFramework class for depth first search (DFS) based algorithms. To write graph algorithms that are based on a depth first search one can extend this class and overwrite appropriate callback methods provided by this class.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.ObjectBLACKNode state specifier.protected static java.lang.ObjectGRAYNode state specifier.protected java.util.Map<java.lang.Object,java.lang.Object>stateMapNodeMap that indicates the state of the nodes as they are visited by this algorithm.protected static java.lang.ObjectWHITENode state specifier.
-
Constructor Summary
Constructors Constructor Description Dfs()Instantiates a new Dfs object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleandoTraverse(java.lang.Object e)Do traverse boolean.protected voidpostTraverse(java.lang.Object edge, java.lang.Object node)Callback method that will be invoked after the search returns from the given node.protected voidpostVisit(java.lang.Object node, int dfsNumber, int compNumber)Callback method that will be invoked whenever a node visit has been completed.protected booleanpreTraverse(java.lang.Object edge, java.lang.Object node, boolean treeEdge)Callback method that will be invoked if the given edge will be looked at in the search the first (and only) time.protected voidpreVisit(java.lang.Object node, int dfsNumber)Callback method that will be invoked whenever a formerly unvisited node gets visited the first time.voidsetDirectedMode(boolean directed)Whether or not to interpret the edges of the graph as directed.voidstart(Network network, java.lang.Object start)Starts a depth first search on the given graph.
-
-
-
Field Detail
-
stateMap
protected java.util.Map<java.lang.Object,java.lang.Object> stateMap
-
WHITE
protected static java.lang.Object WHITE
Node state specifier. Indicates that a node was not yet visited.
-
GRAY
protected static java.lang.Object GRAY
Node state specifier. Indicates that a node was already visited but has not been completed yet, i.e. it is still part of an active path of the dfs tree.
-
BLACK
protected static java.lang.Object BLACK
Node state specifier. Indicates that the node has been completed, i.e. it has been visited before and is not part of an active path in the dfs tree anymore.
-
-
Method Detail
-
setDirectedMode
public void setDirectedMode(boolean directed)
Whether or not to interpret the edges of the graph as directed. By default directed mode is disabled.- Parameters:
directed- the directed
-
start
public void start(Network network, java.lang.Object start)
Starts a depth first search on the given graph. The given node will be visited first. Ifstartis null, this method returns silently.- Parameters:
network- the networkstart- the start
-
preVisit
protected void preVisit(java.lang.Object node, int dfsNumber)Callback method that will be invoked whenever a formerly unvisited node gets visited the first time. The given int is the dfsnumber of that node. By default this method does nothing- Parameters:
node- the nodedfsNumber- the dfs number
-
postVisit
protected void postVisit(java.lang.Object node, int dfsNumber, int compNumber)Callback method that will be invoked whenever a node visit has been completed. The dfs number and the completion number of the given node will be passed in. By default this method does nothing- Parameters:
node- the nodedfsNumber- the dfs numbercompNumber- the comp number
-
preTraverse
protected boolean preTraverse(java.lang.Object edge, java.lang.Object node, boolean treeEdge)Callback method that will be invoked if the given edge will be looked at in the search the first (and only) time. The given node is the node that will be visited next ifftreeEdge == true. By default this method does nothing- Parameters:
edge- the edgenode- the nodetreeEdge- the tree edge- Returns:
- the boolean
-
postTraverse
protected void postTraverse(java.lang.Object edge, java.lang.Object node)Callback method that will be invoked after the search returns from the given node. The node has been reached via the given edge. By default this method does nothing.- Parameters:
edge- the edgenode- the node
-
doTraverse
protected boolean doTraverse(java.lang.Object e)
Do traverse boolean.- Parameters:
e- the e- Returns:
- the boolean
-
-