Class Dfs


  • public class Dfs
    extends java.lang.Object
    Framework 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.Object BLACK
      Node state specifier.
      protected static java.lang.Object GRAY
      Node state specifier.
      protected java.util.Map<java.lang.Object,​java.lang.Object> stateMap
      NodeMap that indicates the state of the nodes as they are visited by this algorithm.
      protected static java.lang.Object WHITE
      Node 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 boolean doTraverse​(java.lang.Object e)
      Do traverse boolean.
      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.
      protected void postVisit​(java.lang.Object node, int dfsNumber, int compNumber)
      Callback method that will be invoked whenever a node visit has been completed.
      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.
      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.
      void setDirectedMode​(boolean directed)
      Whether or not to interpret the edges of the graph as directed.
      void start​(Network network, java.lang.Object start)
      Starts a depth first search on the given graph.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • stateMap

        protected java.util.Map<java.lang.Object,​java.lang.Object> stateMap
        NodeMap that indicates the state of the nodes as they are visited by this algorithm. Possible states of a node are WHITE, GRAY and BLACK.
      • 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.
    • Constructor Detail

      • Dfs

        public Dfs()
        Instantiates a new Dfs object.
    • 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. If start is null, this method returns silently.
        Parameters:
        network - the network
        start - 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 node
        dfsNumber - 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 node
        dfsNumber - the dfs number
        compNumber - 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 iff treeEdge == true. By default this method does nothing
        Parameters:
        edge - the edge
        node - the node
        treeEdge - 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 edge
        node - the node
      • doTraverse

        protected boolean doTraverse​(java.lang.Object e)
        Do traverse boolean.
        Parameters:
        e - the e
        Returns:
        the boolean