Class TopologicalSortAlgo

java.lang.Object
org.jhotdraw8.graph.algo.TopologicalSortAlgo

public class TopologicalSortAlgo extends Object
Provides topological sort algorithms for directed graphs.
Author:
Werner Randelshofer
  • Constructor Details

    • TopologicalSortAlgo

      public TopologicalSortAlgo()
  • Method Details

    • sortTopologically

      public <V, A> @NonNull List<V> sortTopologically(DirectedGraph<V,A> m)
      Sorts the specified directed graph topologically.
      Type Parameters:
      V - the vertex data type
      A - the arrow data type
      Parameters:
      m - the graph
      Returns:
      the sorted list of vertices
    • sortTopologicallyInt

      public int @NonNull [] sortTopologicallyInt(@NonNull IndexedDirectedGraph model)
      Sorts the specified directed graph topologically.
      Parameters:
      model - the graph
      Returns:
      the sorted list of vertices
    • sortTopologicallyIntBatches

      public @NonNull SimpleOrderedPair<int[],IntArrayList> sortTopologicallyIntBatches(@NonNull IndexedDirectedGraph model)
      Sorts the specified directed graph topologically. Returns a list of batches that do not depend topologically on each other.
      Parameters:
      model - the graph
      Returns:
      the sorted list of vertices and the list of batches, batches will be empty if the graph has cycles
    • sortTopologicallyObject

      public <V, A> @NonNull List<V> sortTopologicallyObject(@NonNull DirectedGraph<V,A> model)
      Sorts the specified directed graph topologically.
      Type Parameters:
      V - the vertex data type
      A - the arrow data type
      Parameters:
      model - the graph
      Returns:
      the sorted list of vertices
    • sortTopologically

      public <V> @NonNull List<V> sortTopologically(@NonNull Collection<V> vertices, @NonNull Function<V,Iterable<? extends V>> nextVertices)
      Sorts the specified directed graph topologically.

      If the graph contains cycles, then this method splits the graph inside a cycle.

      Type Parameters:
      V - the vertex data type
      Parameters:
      vertices - the vertices of the graph
      nextVertices - a function that delivers the next vertices for a given vertex
      Returns:
      the sorted list of vertices