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

#include "pgr_binaryBreadthFirstSearch.hpp"

Public Types

typedef G::B_G B_G
 
typedef G::E E
 
typedef G::E_i E_i
 
typedef G::EO_i EO_i
 
typedef G::V V
 

Public Member Functions

std::deque< PathbinaryBreadthFirstSearch (G &graph, const std::vector< pgr_combination_t > &combinations)
 
std::deque< PathbinaryBreadthFirstSearch (G &graph, std::vector< int64_t > start_vertex, std::vector< int64_t > end_vertex)
 

Private Member Functions

Path getPath (G &graph, V bgl_start_vertex, int64_t target, V bgl_target_vertex, std::vector< E > &from_edge, std::vector< double > &current_cost)
 
std::deque< Pathone_to_many_binaryBreadthFirstSearch (G &graph, int64_t start_vertex, std::vector< int64_t > end_vertex)
 
void updateVertexCosts (G &graph, std::vector< double > &current_cost, std::vector< E > &from_edge, std::deque< V > &dq, V &head_vertex)
 

Private Attributes

E DEFAULT_EDGE
 

Detailed Description

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

Definition at line 44 of file pgr_binaryBreadthFirstSearch.hpp.

Member Typedef Documentation

◆ B_G

template<class G >
typedef G::B_G pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::B_G

Definition at line 48 of file pgr_binaryBreadthFirstSearch.hpp.

◆ E

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

Definition at line 47 of file pgr_binaryBreadthFirstSearch.hpp.

◆ E_i

template<class G >
typedef G::E_i pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::E_i

Definition at line 50 of file pgr_binaryBreadthFirstSearch.hpp.

◆ EO_i

template<class G >
typedef G::EO_i pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::EO_i

Definition at line 49 of file pgr_binaryBreadthFirstSearch.hpp.

◆ V

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

Definition at line 46 of file pgr_binaryBreadthFirstSearch.hpp.

Member Function Documentation

◆ binaryBreadthFirstSearch() [1/2]

template<class G >
std::deque<Path> pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::binaryBreadthFirstSearch ( G &  graph,
const std::vector< pgr_combination_t > &  combinations 
)
inline

Definition at line 82 of file pgr_binaryBreadthFirstSearch.hpp.

84  {
85  std::deque<Path> paths;
86 
87  // group targets per distinct source
88  std::map< int64_t, std::vector<int64_t> > vertex_map;
89  for (const pgr_combination_t &comb : combinations) {
90  std::map< int64_t, std::vector<int64_t> >::iterator it = vertex_map.find(comb.source);
91  if (it != vertex_map.end()) {
92  it->second.push_back(comb.target);
93  } else {
94  std::vector<int64_t > targets{comb.target};
95  vertex_map[comb.source] = targets;
96  }
97  }
98 
99  for (const auto &start_ends : vertex_map) {
100  std::deque<Path> result_paths = one_to_many_binaryBreadthFirstSearch(
101  graph,
102  start_ends.first,
103  start_ends.second);
104  paths.insert(
105  paths.begin(),
106  std::make_move_iterator(result_paths.begin()),
107  std::make_move_iterator(result_paths.end()));
108  }
109 
110  std::sort(paths.begin(), paths.end(),
111  [](const Path &e1, const Path &e2) -> bool {
112  return e1.end_id() < e2.end_id();
113  });
114  std::stable_sort(paths.begin(), paths.end(),
115  [](const Path &e1, const Path &e2) -> bool {
116  return e1.start_id() < e2.start_id();
117  });
118 
119  return paths;
120  }

References pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::one_to_many_binaryBreadthFirstSearch().

◆ binaryBreadthFirstSearch() [2/2]

template<class G >
std::deque<Path> pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::binaryBreadthFirstSearch ( G &  graph,
std::vector< int64_t >  start_vertex,
std::vector< int64_t >  end_vertex 
)
inline

Definition at line 52 of file pgr_binaryBreadthFirstSearch.hpp.

55  {
56  std::deque<Path> paths;
57 
58  for (auto source : start_vertex) {
59  std::deque<Path> result_paths = one_to_many_binaryBreadthFirstSearch(
60  graph,
61  source,
62  end_vertex);
63  paths.insert(
64  paths.begin(),
65  std::make_move_iterator(result_paths.begin()),
66  std::make_move_iterator(result_paths.end()));
67  }
68 
69  std::sort(paths.begin(), paths.end(),
70  [](const Path &e1, const Path &e2) -> bool {
71  return e1.end_id() < e2.end_id();
72  });
73  std::stable_sort(paths.begin(), paths.end(),
74  [](const Path &e1, const Path &e2) -> bool {
75  return e1.start_id() < e2.start_id();
76  });
77 
78  return paths;
79  }

References pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::one_to_many_binaryBreadthFirstSearch().

Referenced by pgr_binaryBreadthFirstSearch().

◆ getPath()

template<class G >
Path pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::getPath ( G &  graph,
V  bgl_start_vertex,
int64_t  target,
V  bgl_target_vertex,
std::vector< E > &  from_edge,
std::vector< double > &  current_cost 
)
inlineprivate

Definition at line 171 of file pgr_binaryBreadthFirstSearch.hpp.

177  {
178  auto current_node = bgl_target_vertex;
179 
180  Path path = Path(graph[bgl_start_vertex].id, graph[current_node].id);
181 
182  path.push_back({target, -1, 0, current_cost[current_node]});
183 
184  do {
185  E e = from_edge[current_node];
186  auto from = graph.source(e);
187 
188  path.push_back({graph[from].id, graph[e].id, graph[e].cost, current_cost[from]});
189 
190  current_node = from;
191  } while (from_edge[current_node] != DEFAULT_EDGE);
192 
193  std::reverse(path.begin(), path.end());
194  return path;
195  }

References Path::begin(), pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::DEFAULT_EDGE, Path::end(), and Path::push_back().

Referenced by pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::one_to_many_binaryBreadthFirstSearch().

◆ one_to_many_binaryBreadthFirstSearch()

template<class G >
std::deque<Path> pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::one_to_many_binaryBreadthFirstSearch ( G &  graph,
int64_t  start_vertex,
std::vector< int64_t >  end_vertex 
)
inlineprivate

Definition at line 125 of file pgr_binaryBreadthFirstSearch.hpp.

128  {
129  std::deque<Path> paths;
130 
131  if (graph.has_vertex(start_vertex) == false) {
132  return paths;
133  }
134 
135  std::vector<double> current_cost(graph.num_vertices(), std::numeric_limits<double>::infinity());
136  std::vector<E> from_edge(graph.num_vertices());
137  std::deque<V> dq;
138  DEFAULT_EDGE = from_edge[0];
139 
140  auto bgl_start_vertex = graph.get_V(start_vertex);
141 
142  current_cost[bgl_start_vertex] = 0;
143  dq.push_front(bgl_start_vertex);
144 
145  while (dq.empty() == false) {
146  auto head_vertex = dq.front();
147 
148  dq.pop_front();
149 
150  updateVertexCosts(graph, current_cost, from_edge, dq, head_vertex);
151  }
152 
153  for (auto target_vertex : end_vertex) {
154  if (graph.has_vertex(target_vertex) == false) {
155  continue;
156  }
157 
158  auto bgl_target_vertex = graph.get_V(target_vertex);
159 
160  if (from_edge[bgl_target_vertex] == DEFAULT_EDGE) {
161  continue;
162  }
163 
164  paths.push_front(
165  getPath(graph, bgl_start_vertex, target_vertex, bgl_target_vertex, from_edge, current_cost));
166  }
167 
168  return paths;
169  }

References pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::DEFAULT_EDGE, pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::getPath(), and pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::updateVertexCosts().

Referenced by pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::binaryBreadthFirstSearch().

◆ updateVertexCosts()

template<class G >
void pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::updateVertexCosts ( G &  graph,
std::vector< double > &  current_cost,
std::vector< E > &  from_edge,
std::deque< V > &  dq,
V head_vertex 
)
inlineprivate

Definition at line 198 of file pgr_binaryBreadthFirstSearch.hpp.

203  {
204  auto out_edges = boost::out_edges(head_vertex, graph.graph);
205  E e;
206  EO_i out_i;
207  EO_i out_end;
208  V v_source, v_target;
209 
210  for (boost::tie(out_i, out_end) = out_edges;
211  out_i != out_end; ++out_i) {
212  e = *out_i;
213  v_target = graph.target(e);
214  v_source = graph.source(e);
215  double edge_cost = graph[e].cost;
216 
217  if (std::isinf(current_cost[v_target]) || current_cost[v_source] + edge_cost < current_cost[v_target]) {
218  current_cost[v_target] = current_cost[v_source] + edge_cost;
219 
220  from_edge[v_target] = e;
221 
222  if (edge_cost != 0) {
223  dq.push_back(v_target);
224  } else {
225  dq.push_front(v_target);
226  }
227  }
228  }
229  }

Referenced by pgrouting::functions::Pgr_binaryBreadthFirstSearch< G >::one_to_many_binaryBreadthFirstSearch().

Member Data Documentation

◆ DEFAULT_EDGE


The documentation for this class was generated from the following file:
Path
Definition: basePath_SSEC.hpp:47
pgrouting::functions::Pgr_binaryBreadthFirstSearch::EO_i
G::EO_i EO_i
Definition: pgr_binaryBreadthFirstSearch.hpp:49
Path::push_back
void push_back(Path_t data)
Definition: basePath_SSEC.cpp:52
pgrouting::functions::Pgr_binaryBreadthFirstSearch::one_to_many_binaryBreadthFirstSearch
std::deque< Path > one_to_many_binaryBreadthFirstSearch(G &graph, int64_t start_vertex, std::vector< int64_t > end_vertex)
Definition: pgr_binaryBreadthFirstSearch.hpp:125
pgrouting::functions::Pgr_binaryBreadthFirstSearch::V
G::V V
Definition: pgr_binaryBreadthFirstSearch.hpp:46
Path::end
pthIt end()
Definition: basePath_SSEC.hpp:82
pgr_combination_t
Definition: pgr_combination_t.h:43
pgrouting::functions::Pgr_binaryBreadthFirstSearch::getPath
Path getPath(G &graph, V bgl_start_vertex, int64_t target, V bgl_target_vertex, std::vector< E > &from_edge, std::vector< double > &current_cost)
Definition: pgr_binaryBreadthFirstSearch.hpp:171
pgrouting::functions::Pgr_binaryBreadthFirstSearch::DEFAULT_EDGE
E DEFAULT_EDGE
Definition: pgr_binaryBreadthFirstSearch.hpp:123
pgrouting::functions::Pgr_binaryBreadthFirstSearch::E
G::E E
Definition: pgr_binaryBreadthFirstSearch.hpp:47
pgrouting::functions::Pgr_binaryBreadthFirstSearch::updateVertexCosts
void updateVertexCosts(G &graph, std::vector< double > &current_cost, std::vector< E > &from_edge, std::deque< V > &dq, V &head_vertex)
Definition: pgr_binaryBreadthFirstSearch.hpp:198
Path::begin
pthIt begin()
Definition: basePath_SSEC.hpp:81