Method: RGL::Graph#prim_minimum_spanning_tree
- Defined in:
- lib/rgl/prim.rb
#prim_minimum_spanning_tree(edge_weights_map, start_vertex = nil, visitor = DijkstraVisitor.new(self)) ⇒ Object
Finds the minimum spanning tree of the graph.
Returns an AdjacencyGraph that represents the minimum spanning tree of the graph’s connectivity component that contains the starting vertex. The algorithm starts from an arbitrary vertex if the start_vertex is not given. Since the implementation relies on the Dijkstra’s algorithm, Prim’s algorithm uses the same visitor class and emits the same events.
Raises ArgumentError if edge weight is undefined.
49 50 51 |
# File 'lib/rgl/prim.rb', line 49 def prim_minimum_spanning_tree(edge_weights_map, start_vertex = nil, visitor = DijkstraVisitor.new(self)) PrimAlgorithm.new(self, edge_weights_map, visitor).minimum_spanning_tree(start_vertex) end |