Public Member Functions | |
TopologicalSort (Collection< Vertex > vertices) | |
List | sort () |
boolean | hasCycles () |
Map | getCyclicVertices () |
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.
alma.acs.algorithms.TopologicalSort.TopologicalSort | ( | Collection< Vertex > | vertices | ) |
Constructor that takes the nodes, which we hope form a directed acyclic graph
vertices |
Map alma.acs.algorithms.TopologicalSort.getCyclicVertices | ( | ) |
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.
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().