Method: RGL::PrimAlgorithm#minimum_spanning_tree

Defined in:
lib/rgl/prim.rb

#minimum_spanning_tree(start_vertex = nil) ⇒ Object

Returns minimum spanning tree for the graph. If the graph is disconnected, Prim’s algorithm will find the minimum spanning tree only for one of the connectivity components. If start_vertex is given, Dijkstra’s search will be started in this vertex and the algorithm will return the minimum spanning tree for the component it belongs to.



30
31
32
33
# File 'lib/rgl/prim.rb', line 30

def minimum_spanning_tree(start_vertex = nil)
  @dijkstra.find_shortest_paths(start_vertex || @graph.vertices.first)
  AdjacencyGraph[*@visitor.parents_map.to_a.flatten]
end