24 #ifndef INCLUDE_TRAVERSAL_PGR_DEPTHFIRSTSEARCH_HPP_
25 #define INCLUDE_TRAVERSAL_PGR_DEPTHFIRSTSEARCH_HPP_
30 #include <boost/graph/depth_first_search.hpp>
31 #include <boost/graph/undirected_dfs.hpp>
82 std::vector < int64_t > roots,
85 std::vector < pgr_mst_rt > results;
87 for (
auto root : roots) {
88 std::vector < E > visited_order;
89 results.push_back({root, 0, root, -1, 0.0, 0.0});
91 if (graph.has_vertex(root)) {
92 auto v_root(graph.get_V(root));
96 auto result =
get_results(visited_order, root, max_depth, graph);
97 results.insert(results.end(), result.begin(), result.end());
125 std::vector < E > &visited_order,
131 std::vector < boost::default_color_type > colors(boost::num_vertices(graph.graph));
132 std::map < E, boost::default_color_type > edge_color;
134 auto i_map = boost::get(boost::vertex_index, graph.graph);
137 auto vertex_color_map = boost::make_iterator_property_map(colors.begin(), i_map);
138 auto edge_color_map = boost::make_assoc_property_map(edge_color);
140 auto vis = dfs_visitor(root, visited_order, max_depth, colors, graph);
143 CHECK_FOR_INTERRUPTS();
147 boost::depth_first_search(graph.graph, vis, vertex_color_map, root);
149 boost::undirected_dfs(graph.graph, vis, vertex_color_map, edge_color_map, root);
153 }
catch (boost::exception
const& ex) {
156 }
catch (std::exception &e) {
178 template <
typename T >
184 std::vector < pgr_mst_rt > results;
186 std::vector < double > agg_cost(graph.num_vertices(), 0);
187 std::vector < int64_t > depth(graph.num_vertices(), 0);
189 for (
const auto edge : visited_order) {
190 auto u = graph.source(
edge);
191 auto v = graph.target(
edge);
193 agg_cost[v] = agg_cost[u] + graph[
edge].cost;
194 depth[v] = depth[u] + 1;
196 if (max_depth >= depth[v]) {
213 #endif // INCLUDE_TRAVERSAL_PGR_DEPTHFIRSTSEARCH_HPP_