GraphLab Project

graphlab.library.algorithms.spanningtree
Class Prim<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>

java.lang.Object
  extended by graphlab.library.algorithms.Algorithm
      extended by graphlab.library.algorithms.spanningtree.Prim<VertexType,EdgeType>
All Implemented Interfaces:
AlgorithmInterface, AutomatedAlgorithm
Direct Known Subclasses:
PrimAnim

public class Prim<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
extends Algorithm
implements AutomatedAlgorithm

Implementation of Prim algorithm to find minimum spanning tree. The output of this method is a new independent graph representing the spanning tree.

Author:
Omid Aladini

Nested Class Summary
 class Prim.DefaultEdgeComparator
          Compares two edges of type EdgeType.
 
Constructor Summary
Prim(BaseGraph<VertexType,EdgeType> graph, EdgeVertexCopier<VertexType,EdgeType> gc)
          Constructor of the Prim algorithm.
 
Method Summary
 void doAlgorithm()
           
 Pair<java.util.Vector<VertexType>,java.util.Vector<EdgeType>> findMinimumSpanningTree(VertexType v)
          Finds minimum spanning tree starting at vertex v.
 Pair<java.util.Vector<VertexType>,java.util.Vector<EdgeType>> findMinimumSpanningTree(VertexType v, java.util.Comparator<EdgeType> comparator)
          Finds minimum spanning tree starting at vertex v.
 
Methods inherited from class graphlab.library.algorithms.Algorithm
acceptEventDispatcher, dispatchEvent, getDispatcher
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface graphlab.library.algorithms.AlgorithmInterface
acceptEventDispatcher
 

Constructor Detail

Prim

public Prim(BaseGraph<VertexType,EdgeType> graph,
            EdgeVertexCopier<VertexType,EdgeType> gc)
Constructor of the Prim algorithm.

Parameters:
graph - Graph the algorithm is going to find it's minimum spanning tree.
gc - Reference to a GraphConverter object which is responsible for duplication of the graph elements, because graph edges and vertices are going to be copied to the newly created spanning tree.
Method Detail

findMinimumSpanningTree

public Pair<java.util.Vector<VertexType>,java.util.Vector<EdgeType>> findMinimumSpanningTree(VertexType v,
                                                                                             java.util.Comparator<EdgeType> comparator)
                                                                                                                                      throws InvalidGraphException,
                                                                                                                                             InvalidVertexException
Finds minimum spanning tree starting at vertex v. Note that if your graph is not connected, the algorithm falls in an infinite loop it's the caller's task to check connectivity.

Parameters:
v - Start vertex of Prim algorithm.
Returns:
The spanning tree graph.
Throws:
InvalidGraphException - if the supplied vertex is invalid.
InvalidVertexException

findMinimumSpanningTree

public Pair<java.util.Vector<VertexType>,java.util.Vector<EdgeType>> findMinimumSpanningTree(VertexType v)
                                                                                                                                      throws InvalidGraphException,
                                                                                                                                             InvalidVertexException
Finds minimum spanning tree starting at vertex v. Note that if your graph is not connected, the algorithm falls in an infinite loop it's the caller's task to check connectivity. Default comparator which compares weight parameter of the graph is used.

Parameters:
v - Start vertex of Prim algorithm.
Returns:
The spanning tree graph.
Throws:
InvalidGraphException - if the supplied vertex is invalid.
InvalidVertexException

doAlgorithm

public void doAlgorithm()
Specified by:
doAlgorithm in interface AutomatedAlgorithm

GraphLab Project