Public Member Functions

alma.acs.algorithms.TopologicalSort Class Reference

List of all members.

Public Member Functions

 TopologicalSort (Collection< Vertex > vertices)
List sort ()
boolean hasCycles ()
Map getCyclicVertices ()

Detailed Description

Topological sort algorithm, following Cormen et al, "Introduction to Algorithms".

To be used to sort a list of interdependent nodes, or to find out that this is impossible because the dependencies are cyclic. Applications need to wrap each of their nodes with a Vertex object, set up the directed dependencies between any two such vertex objects (see addAdjacentVertex), run the sort algorithm, and then extract the original nodes from the sorted vertices.

Expected use is to detangle component dependencies etc.


Constructor & Destructor Documentation

alma.acs.algorithms.TopologicalSort.TopologicalSort ( Collection< Vertex vertices  ) 

Constructor that takes the nodes, which we hope form a directed acyclic graph

Parameters:
vertices 

Member Function Documentation

Map alma.acs.algorithms.TopologicalSort.getCyclicVertices (  ) 

Returns the vertices (graph nodes) that form a back edge in the graph.

Returns:
Map [key = Vertex, Value = List of adjacent Vertex objects that form the cycle]
boolean alma.acs.algorithms.TopologicalSort.hasCycles (  ) 

States whether the graph contains cyclic dependencies, which implies that it could not be sorted. To be called after sort() was called.

Returns:
true if cycles were found
List alma.acs.algorithms.TopologicalSort.sort (  ) 

Tries to sort the vertices and to return them in a list. The list will be incomplete if the graph could not be sorted, see hasCycles().

References alma.acs.algorithms.Vertex.getColor().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties