28 #ifndef INCLUDE_SPANNINGTREE_PGR_PRIM_HPP_
29 #define INCLUDE_SPANNINGTREE_PGR_PRIM_HPP_
33 #include <boost/graph/prim_minimum_spanning_tree.hpp>
50 typedef typename G::B_G
B_G;
53 std::vector<pgr_mst_rt>
prim(
G &graph);
55 std::vector<pgr_mst_rt>
primBFS(
57 std::vector<int64_t> roots,
60 std::vector<pgr_mst_rt>
primDFS(
62 std::vector<int64_t> roots,
65 std::vector<pgr_mst_rt>
primDD(
67 std::vector<int64_t> roots,
98 int64_t root_vertex) {
101 predecessors.resize(graph.num_vertices());
102 distances.resize(graph.num_vertices());
104 auto v_root(graph.get_V(root_vertex));
109 CHECK_FOR_INTERRUPTS();
111 boost::prim_minimum_spanning_tree(
114 boost::distance_map(&distances[0]).
115 weight_map(get(&G::G_T_E::cost, graph.graph))
117 .visitor(prim_visitor(data)));
119 for (
const auto v : data) {
124 if (std::isinf(distances[v]))
continue;
125 m_unassigned.erase(v);
128 auto u = predecessors[v];
133 if (u == v)
continue;
135 auto cost = distances[u] - distances[v];
136 auto edge = graph.get_edge(u, v, cost);
137 this->m_spanning_tree.edges.insert(
edge);
147 size_t totalNodes = num_vertices(graph.graph);
149 m_unassigned.clear();
150 for (
V v = 0; v < totalNodes; ++v) {
151 m_unassigned.insert(m_unassigned.end(), v);
154 while (!m_unassigned.empty()) {
155 auto root = *m_unassigned.begin();
156 m_unassigned.erase(m_unassigned.begin());
159 graph.graph[root].id);
164 std::vector<pgr_mst_rt>
167 return this->mst(graph);
171 std::vector<pgr_mst_rt>
174 std::vector<int64_t> roots,
176 return this->mstBFS(graph, roots, max_depth);
180 std::vector<pgr_mst_rt>
183 std::vector<int64_t> roots,
185 return this->mstDFS(graph, roots, max_depth);
189 std::vector<pgr_mst_rt>
192 std::vector<int64_t> roots,
194 return this->mstDD(graph, roots, distance);
202 #endif // INCLUDE_SPANNINGTREE_PGR_PRIM_HPP_