Class MinimumSpanningTreeAlgo

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

public class MinimumSpanningTreeAlgo extends Object
  • Constructor Details

    • MinimumSpanningTreeAlgo

      public MinimumSpanningTreeAlgo()
  • Method Details

    • createForest

      public static <VV> @NonNull Map<VV,List<VV>> createForest(@NonNull Collection<VV> vertices)
    • union

      public static <VV> void union(@NonNull List<VV> uset, @NonNull List<VV> vset, @NonNull Map<VV,List<VV>> forest)
    • findMinimumSpanningTree

      public <V, A, C extends Number & Comparable<C>, P extends OrderedPair<V, V>> @NonNull List<P> findMinimumSpanningTree(@NonNull Collection<V> vertices, @NonNull List<P> orderedEdges, @Nullable List<P> rejectedEdges)
      Given a set of vertices and a list of arrows ordered by cost, returns the minimum spanning tree.

      Uses Kruskal's algorithm.

      Type Parameters:
      P - the pair data type
      Parameters:
      vertices - a directed graph
      orderedEdges - list of edges sorted by cost in ascending order (lowest cost first, highest cost last).
      rejectedEdges - optional, all excluded edges are added to this list, if it is provided.
      Returns:
      the arrows that are part of the minimum spanning tree.
    • findMinimumSpanningTreeGraph

      public <V, A, C extends Number & Comparable<C>> @NonNull SimpleMutableDirectedGraph<V,A> findMinimumSpanningTreeGraph(@NonNull DirectedGraph<V,A> graph, @NonNull Function<A,C> costf)
      Given an undirected graph and a cost function, returns a builder with the minimum spanning tree.

      Parameters:
      graph - the graph. This must be an undirected graph represented as a directed graph with two identical arrows for each edge.
      costf - the cost function
      Returns:
      the graph builder
    • findMinimumSpanningTreeGraph

      public <V, A, C extends Number & Comparable<C>> @NonNull SimpleMutableDirectedGraph<V,A> findMinimumSpanningTreeGraph(@NonNull DirectedGraph<V,A> graph, @NonNull Function3<V,V,A,C> costf)
      Given an undirected graph and a cost function, returns a builder with the minimum spanning tree.

      Parameters:
      graph - the graph. This must be an undirected graph represented as a directed graph with two identical arrows for each edge.
      costf - the cost function
      Returns:
      the graph builder
    • findMinimumSpanningTreeGraph

      public <V, A, C extends Number & Comparable<C>, P extends OrderedPair<V, V>> @NonNull SimpleMutableDirectedGraph<V,P> findMinimumSpanningTreeGraph(@NonNull Collection<V> vertices, @NonNull List<P> orderedArrows, @Nullable List<P> includedArrows, List<P> rejectedArrows)
      Given a set of vertices and a list of arrows ordered by cost, returns a builder with the minimum spanning tree. This is an undirected graph with an arrow in each direction.

      Type Parameters:
      P - the pair data type
      Parameters:
      vertices - the list of vertices
      orderedArrows - list of arrows sorted by cost in ascending order (lowest cost first, highest cost last)
      includedArrows - optional, all included arrows are added to this list, if it is provided.
      rejectedArrows - optional, all excluded arrows are added to this list, if it is provided.
      Returns:
      the graph builder