PGROUTING  3.2
pgrouting::functions::Pgr_depthFirstSearch< G > Class Template Reference

#include "pgr_depthFirstSearch.hpp"

Public Types

typedef G::E E
 
typedef G::V V
 

DepthFirstSearch

std::vector< pgr_mst_rtdepthFirstSearch (G &graph, std::vector< int64_t > roots, bool directed, int64_t max_depth)
 depthFirstSearch function More...
 
bool depthFirstSearch_single_vertex (G &graph, V root, std::vector< E > &visited_order, bool directed, int64_t max_depth)
 Calls the Boost function. More...
 
template<typename T >
std::vector< pgr_mst_rtget_results (T visited_order, int64_t root, int64_t max_depth, const G &graph)
 to get the results More...
 

Detailed Description

template<class G>
class pgrouting::functions::Pgr_depthFirstSearch< G >

Definition at line 54 of file pgr_depthFirstSearch.hpp.

Member Typedef Documentation

◆ E

template<class G >
typedef G::E pgrouting::functions::Pgr_depthFirstSearch< G >::E

Definition at line 57 of file pgr_depthFirstSearch.hpp.

◆ V

template<class G >
typedef G::V pgrouting::functions::Pgr_depthFirstSearch< G >::V

Definition at line 56 of file pgr_depthFirstSearch.hpp.

Member Function Documentation

◆ depthFirstSearch()

template<class G >
std::vector< pgr_mst_rt > pgrouting::functions::Pgr_depthFirstSearch< G >::depthFirstSearch ( G &  graph,
std::vector< int64_t >  roots,
bool  directed,
int64_t  max_depth 
)
inline

depthFirstSearch function

It does all the processing and returns the results.

Parameters
graphthe graph containing the edges
rootsthe root vertices
max_depththe maximum depth of traversal
directedwhether the graph is directed or undirected
Returns
results, when results are found
See also
boost::depth_first_search
boost::undirected_dfs

Definition at line 80 of file pgr_depthFirstSearch.hpp.

84  {
85  std::vector < pgr_mst_rt > results;
86 
87  for (auto root : roots) {
88  std::vector < E > visited_order;
89  results.push_back({root, 0, root, -1, 0.0, 0.0});
90 
91  if (graph.has_vertex(root)) {
92  auto v_root(graph.get_V(root));
93 
94  depthFirstSearch_single_vertex(graph, v_root, visited_order, directed, max_depth);
95 
96  auto result = get_results(visited_order, root, max_depth, graph);
97  results.insert(results.end(), result.begin(), result.end());
98  }
99  }
100 
101  return results;
102  }

References pgrouting::functions::Pgr_depthFirstSearch< G >::depthFirstSearch_single_vertex(), and pgrouting::functions::Pgr_depthFirstSearch< G >::get_results().

Referenced by pgr_depthFirstSearch().

◆ depthFirstSearch_single_vertex()

template<class G >
bool pgrouting::functions::Pgr_depthFirstSearch< G >::depthFirstSearch_single_vertex ( G &  graph,
V  root,
std::vector< E > &  visited_order,
bool  directed,
int64_t  max_depth 
)
inlineprivate

Calls the Boost function.

Calls boost::depth_first_search and boost::undirected_dfs for directed graphs and undirected graphs, respectively.

Parameters
graphthe graph containing the edges
rootthe root vertex
visited_ordervector which will contain the edges of the resulting traversal
directedwhether the graph is directed or undirected
Returns
bool true, when results are found

Definition at line 122 of file pgr_depthFirstSearch.hpp.

127  {
128  using dfs_visitor = visitors::Dfs_visitor < V, E, G >;
129 
130  // Exterior property storage containers
131  std::vector < boost::default_color_type > colors(boost::num_vertices(graph.graph));
132  std::map < E, boost::default_color_type > edge_color;
133 
134  auto i_map = boost::get(boost::vertex_index, graph.graph);
135 
136  // Iterator property maps which record the color of each vertex and edge, respectively
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);
139 
140  auto vis = dfs_visitor(root, visited_order, max_depth, colors, graph);
141 
142  /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
143  CHECK_FOR_INTERRUPTS();
144 
145  try {
146  if (directed) {
147  boost::depth_first_search(graph.graph, vis, vertex_color_map, root);
148  } else {
149  boost::undirected_dfs(graph.graph, vis, vertex_color_map, edge_color_map, root);
150  }
151  } catch(found_goals &) {
152  {}
153  } catch (boost::exception const& ex) {
154  (void)ex;
155  throw;
156  } catch (std::exception &e) {
157  (void)e;
158  throw;
159  } catch (...) {
160  throw;
161  }
162  return true;
163  }

Referenced by pgrouting::functions::Pgr_depthFirstSearch< G >::depthFirstSearch().

◆ get_results()

template<class G >
template<typename T >
std::vector< pgr_mst_rt > pgrouting::functions::Pgr_depthFirstSearch< G >::get_results ( visited_order,
int64_t  root,
int64_t  max_depth,
const G &  graph 
)
inlineprivate

to get the results

Uses the visited_order of vertices to get the results. Selects only those nodes in the final result whose depth is less than the max_depth.

Parameters
visited_ordervector which contains the edges of the resulting traversal
rootthe root vertex
max_depththe maximum depth of traversal
graphthe graph containing the edges
Returns
results vector

Definition at line 179 of file pgr_depthFirstSearch.hpp.

183  {
184  std::vector < pgr_mst_rt > results;
185 
186  std::vector < double > agg_cost(graph.num_vertices(), 0);
187  std::vector < int64_t > depth(graph.num_vertices(), 0);
188 
189  for (const auto edge : visited_order) {
190  auto u = graph.source(edge);
191  auto v = graph.target(edge);
192 
193  agg_cost[v] = agg_cost[u] + graph[edge].cost;
194  depth[v] = depth[u] + 1;
195 
196  if (max_depth >= depth[v]) {
197  results.push_back({
198  root,
199  depth[v],
200  graph[v].id,
201  graph[edge].id,
202  graph[edge].cost,
203  agg_cost[v]
204  });
205  }
206  }
207  return results;
208  }

Referenced by pgrouting::functions::Pgr_depthFirstSearch< G >::depthFirstSearch().


The documentation for this class was generated from the following file:
pgrouting::functions::Pgr_depthFirstSearch::depthFirstSearch_single_vertex
bool depthFirstSearch_single_vertex(G &graph, V root, std::vector< E > &visited_order, bool directed, int64_t max_depth)
Calls the Boost function.
Definition: pgr_depthFirstSearch.hpp:122
edge
Definition: trsp.h:41
pgrouting::functions::Pgr_depthFirstSearch::get_results
std::vector< pgr_mst_rt > get_results(T visited_order, int64_t root, int64_t max_depth, const G &graph)
to get the results
Definition: pgr_depthFirstSearch.hpp:179