alma::acs::algorithms::TopologicalSort Class Reference

Collaboration diagram for alma::acs::algorithms::TopologicalSort:
Collaboration graph
[legend]

List of all members.

Public Member Functions

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

Private Member Functions

void dfsVisit (Vertex vertex)

Private Attributes

Collection< Vertexm_vertices
LinkedList< Vertexm_sortedVertices
Map< Vertex, List< Vertex > > m_cyclicVertices

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  )  [inline]

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

Parameters:
vertices 

References m_sortedVertices, and m_vertices.


Member Function Documentation

void alma::acs::algorithms::TopologicalSort::dfsVisit ( Vertex  vertex  )  [inline, private]
Map alma::acs::algorithms::TopologicalSort::getCyclicVertices (  )  [inline]

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]

References m_cyclicVertices.

Referenced by alma::acs::algorithms::TopologicalSortTest::testFailOnCyclicGraph().

boolean alma::acs::algorithms::TopologicalSort::hasCycles (  )  [inline]

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

References m_cyclicVertices.

Referenced by alma::acs::algorithms::TopologicalSortTest::testFailOnCyclicGraph(), and alma::acs::algorithms::TopologicalSortTest::testSortDirectedAcyclicGraph().

List alma::acs::algorithms::TopologicalSort::sort (  )  [inline]

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 dfsVisit(), alma::acs::algorithms::Vertex::getColor(), m_sortedVertices, and m_vertices.

Referenced by alma::acs::algorithms::TopologicalSortTest::testFailOnCyclicGraph(), and alma::acs::algorithms::TopologicalSortTest::testSortDirectedAcyclicGraph().


Member Data Documentation

Referenced by dfsVisit(), sort(), and TopologicalSort().

Referenced by sort(), and TopologicalSort().


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2