Class PrimMinimumSpanningTree<V,​E>

  • Type Parameters:
    V - the vertex type
    E - the edge type
    All Implemented Interfaces:
    com.google.common.base.Function<Graph<V,​E>,​Graph<V,​E>>, java.util.function.Function<Graph<V,​E>,​Graph<V,​E>>

    public class PrimMinimumSpanningTree<V,​E>
    extends java.lang.Object
    implements com.google.common.base.Function<Graph<V,​E>,​Graph<V,​E>>
    For the input Graph, creates a MinimumSpanningTree using a variation of Prim's algorithm.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected com.google.common.base.Supplier<? extends Graph<V,​E>> treeFactory  
      protected com.google.common.base.Function<? super E,​java.lang.Double> weights  
    • Constructor Summary

      Constructors 
      Constructor Description
      PrimMinimumSpanningTree​(com.google.common.base.Supplier<? extends Graph<V,​E>> supplier)
      Creates an instance which generates a minimum spanning tree assuming constant edge weights.
      PrimMinimumSpanningTree​(com.google.common.base.Supplier<? extends Graph<V,​E>> supplier, com.google.common.base.Function<? super E,​java.lang.Double> weights)
      Creates an instance which generates a minimum spanning tree using the input edge weights.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Graph<V,​E> apply​(Graph<V,​E> graph)  
      protected V findRoot​(Graph<V,​E> graph)  
      protected void updateTree​(Graph<V,​E> tree, Graph<V,​E> graph, java.util.Collection<E> unfinishedEdges)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface com.google.common.base.Function

        equals
      • Methods inherited from interface java.util.function.Function

        andThen, compose
    • Field Detail

      • treeFactory

        protected com.google.common.base.Supplier<? extends Graph<V,​E>> treeFactory
      • weights

        protected com.google.common.base.Function<? super E,​java.lang.Double> weights
    • Constructor Detail

      • PrimMinimumSpanningTree

        public PrimMinimumSpanningTree​(com.google.common.base.Supplier<? extends Graph<V,​E>> supplier)
        Creates an instance which generates a minimum spanning tree assuming constant edge weights.
        Parameters:
        supplier - used to create the tree instances
      • PrimMinimumSpanningTree

        public PrimMinimumSpanningTree​(com.google.common.base.Supplier<? extends Graph<V,​E>> supplier,
                                       com.google.common.base.Function<? super E,​java.lang.Double> weights)
        Creates an instance which generates a minimum spanning tree using the input edge weights.
        Parameters:
        supplier - used to create the tree instances
        weights - the edge weights to use for defining the MST
    • Method Detail

      • apply

        public Graph<V,​E> apply​(Graph<V,​E> graph)
        Specified by:
        apply in interface com.google.common.base.Function<V,​E>
        Specified by:
        apply in interface java.util.function.Function<V,​E>
        Parameters:
        graph - the Graph to find MST in
      • findRoot

        protected V findRoot​(Graph<V,​E> graph)
      • updateTree

        protected void updateTree​(Graph<V,​E> tree,
                                  Graph<V,​E> graph,
                                  java.util.Collection<E> unfinishedEdges)