File indexing completed on 2025-01-18 09:37:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_GRAPH_MST_PRIM_HPP
0011 #define BOOST_GRAPH_MST_PRIM_HPP
0012
0013 #include <functional>
0014 #include <boost/graph/graph_traits.hpp>
0015 #include <boost/graph/dijkstra_shortest_paths.hpp>
0016
0017 namespace boost
0018 {
0019
0020 namespace detail
0021 {
0022
0023 template < class U, class V > struct _project2nd
0024 {
0025 V operator()(U, V v) const { return v; }
0026 };
0027 }
0028
0029 namespace detail
0030 {
0031
0032
0033
0034
0035 template < class Graph, class P, class T, class R, class Weight >
0036 inline void prim_mst_impl(const Graph& G,
0037 typename graph_traits< Graph >::vertex_descriptor s,
0038 const bgl_named_params< P, T, R >& params, Weight)
0039 {
0040 typedef typename property_traits< Weight >::value_type W;
0041 std::less< W > compare;
0042 detail::_project2nd< W, W > combine;
0043 dijkstra_shortest_paths(
0044 G, s, params.distance_compare(compare).distance_combine(combine));
0045 }
0046 }
0047
0048 template < class VertexListGraph, class DijkstraVisitor, class PredecessorMap,
0049 class DistanceMap, class WeightMap, class IndexMap >
0050 inline void prim_minimum_spanning_tree(const VertexListGraph& g,
0051 typename graph_traits< VertexListGraph >::vertex_descriptor s,
0052 PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
0053 IndexMap index_map, DijkstraVisitor vis)
0054 {
0055 typedef typename property_traits< WeightMap >::value_type W;
0056 std::less< W > compare;
0057 detail::_project2nd< W, W > combine;
0058 dijkstra_shortest_paths(g, s, predecessor, distance, weight, index_map,
0059 compare, combine, (std::numeric_limits< W >::max)(), 0, vis);
0060 }
0061
0062 template < class VertexListGraph, class PredecessorMap, class P, class T,
0063 class R >
0064 inline void prim_minimum_spanning_tree(const VertexListGraph& g,
0065 PredecessorMap p_map, const bgl_named_params< P, T, R >& params)
0066 {
0067 detail::prim_mst_impl(g,
0068 choose_param(get_param(params, root_vertex_t()), *vertices(g).first),
0069 params.predecessor_map(p_map),
0070 choose_const_pmap(get_param(params, edge_weight), g, edge_weight));
0071 }
0072
0073 template < class VertexListGraph, class PredecessorMap >
0074 inline void prim_minimum_spanning_tree(
0075 const VertexListGraph& g, PredecessorMap p_map)
0076 {
0077 detail::prim_mst_impl(g, *vertices(g).first,
0078 predecessor_map(p_map).weight_map(get(edge_weight, g)),
0079 get(edge_weight, g));
0080 }
0081
0082 }
0083
0084 #endif