salvo.jesus.graph.algorithm
Class TopologicalSorting

java.lang.Object
  extended by salvo.jesus.graph.algorithm.GraphTraversal
      extended by salvo.jesus.graph.algorithm.TopologicalSorting
All Implemented Interfaces:
java.io.Serializable

public class TopologicalSorting
extends GraphTraversal

A concrete subclass of GraphTraversal that performs a topological sort against a directed acyclic graph.

Author:
Jesus M. Salvo Jr.
See Also:
Serialized Form

Field Summary
(package private)  DirectedAcyclicGraph dag
           
 
Fields inherited from class salvo.jesus.graph.algorithm.GraphTraversal
graph, OK, TERMINATEDBYVISITOR
 
Constructor Summary
TopologicalSorting(DirectedAcyclicGraph dag)
          Creates an instance of TopologicalSorting that will perform a topological sort against a directed acyclic graph.
 
Method Summary
 java.util.Vector reverseTraverse()
          Perform a reverse topological sort of the entire directed acyclic graph.
 java.util.Vector reverseTraverse(Vertex startat)
          Perform a reverse topological sort of the connected set of a directed acyclic graph to which Vertex startat belongs, starting at Vertex startat.
 java.util.Vector traverse()
          Perform a topological sort of the entire directed acyclic graph.
 java.util.Vector traverse(Vertex startat)
          Perform a topological sort of the connected set of a directed acyclic graph to which Vertex startat belongs, starting at Vertex startat.
 int traverse(Vertex startat, java.util.Vector visited, Visitor visitor)
          Perform a topological sort of the connected set of a directed acyclic graph to which Vertex startat belongs, starting at Vertex startat.
 java.util.Vector traverse(Vertex startat, Visitor visitor)
          Perform a topological sort of the connected set of a directed acyclic graph to which Vertex startat belongs, starting at Vertex startat.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dag

DirectedAcyclicGraph dag
Constructor Detail

TopologicalSorting

public TopologicalSorting(DirectedAcyclicGraph dag)
Creates an instance of TopologicalSorting that will perform a topological sort against a directed acyclic graph.

Parameters:
dag - The DirectedAcyclicGraph on which topological sorting will be performed.
Method Detail

traverse

public int traverse(Vertex startat,
                    java.util.Vector visited,
                    Visitor visitor)
Perform a topological sort of the connected set of a directed acyclic graph to which Vertex startat belongs, starting at Vertex startat.

Specified by:
traverse in class GraphTraversal
Parameters:
startat - The Vertex to which you want to start the traversal.
visited - Vector of vertices that has been visited, in the sequence they were visited.
visitor - Visitor object to visit each vertex as they are visited. Return value of the visitor is ignored.

traverse

public java.util.Vector traverse(Vertex startat,
                                 Visitor visitor)
Perform a topological sort of the connected set of a directed acyclic graph to which Vertex startat belongs, starting at Vertex startat.

Specified by:
traverse in class GraphTraversal
Parameters:
startat - The Vertex to which you want to start the traversal.
visitor - Visitor object to visit each vertex as they are visited. Return value of the visitor is ignored.
Returns:
A Vector of vertices in the order that they were visited.

traverse

public java.util.Vector traverse(Vertex startat)
Perform a topological sort of the connected set of a directed acyclic graph to which Vertex startat belongs, starting at Vertex startat.

Specified by:
traverse in class GraphTraversal
Parameters:
startat - The Vertex to which you want to start the traversal.
Returns:
A Vector of vertices in the order that they were visited.

reverseTraverse

public java.util.Vector reverseTraverse(Vertex startat)
Perform a reverse topological sort of the connected set of a directed acyclic graph to which Vertex startat belongs, starting at Vertex startat. This method is not part of the GraphTraversal abstract class, but is added here for convenience.

Parameters:
startat - The Vertex to which you want to start the traversal.
Returns:
A Vector of vertices in the order that they were visited.

traverse

public java.util.Vector traverse()
Perform a topological sort of the entire directed acyclic graph. Note that the sequence of vertices in the return Vector will not distinguish between connected components of the graph. This method is not part of the GraphTraversal abstract class, but is added here for convenience.

Returns:
Vector containing the sequence of the vertices visited in the entire directed acyclic graph, regardless of the connected components of the graph.

reverseTraverse

public java.util.Vector reverseTraverse()
Perform a reverse topological sort of the entire directed acyclic graph. Note that the sequence of vertices in the return Vector will not distinguish between connected components of the graph. This method is not part of the GraphTraversal abstract class, but is added here for convenience.

Returns:
Vector containing the sequence of the vertices visited in the entire directed acyclic graph, regardless of the connected components of the graph.