PGROUTING  3.2
dijkstra_driver.cpp File Reference
#include "drivers/dijkstra/dijkstra_driver.h"
#include <c_types/pgr_combination_t.h>
#include <sstream>
#include <deque>
#include <vector>
#include <algorithm>
#include <limits>
#include "dijkstra/pgr_dijkstra.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
Include dependency graph for dijkstra_driver.cpp:

Go to the source code of this file.

Namespaces

 detail
 

Functions

void do_pgr_combinations_dijkstra (pgr_edge_t *data_edges, size_t total_edges, pgr_combination_t *combinations, size_t total_combinations, bool directed, bool only_cost, bool normal, int64_t n_goals, bool global, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 
void do_pgr_many_to_many_dijkstra (pgr_edge_t *data_edges, size_t total_edges, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, bool only_cost, bool normal, int64_t n_goals, bool global, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 
template<class G >
std::deque< Pathdetail::pgr_dijkstra (G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, bool only_cost, bool normal, size_t n_goals, bool global)
 
template<class G >
std::deque< Pathdetail::pgr_dijkstra (G &graph, std::vector< pgr_combination_t > &combinations, bool only_cost, bool normal, size_t n_goals, bool global)
 
void detail::post_process (std::deque< Path > &paths, bool only_cost, bool normal, size_t n_goals, bool global)
 

Function Documentation

◆ do_pgr_combinations_dijkstra()

void do_pgr_combinations_dijkstra ( pgr_edge_t data_edges,
size_t  total_edges,
pgr_combination_t combinations,
size_t  total_combinations,
bool  directed,
bool  only_cost,
bool  normal,
int64_t  n_goals,
bool  global,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 262 of file dijkstra_driver.cpp.

277  {
278  std::ostringstream log;
279  std::ostringstream err;
280  std::ostringstream notice;
281 
282  try {
283  pgassert(total_edges != 0);
284  pgassert(total_combinations != 0);
285  pgassert(!(*log_msg));
286  pgassert(!(*notice_msg));
287  pgassert(!(*err_msg));
288  pgassert(!(*return_tuples));
289  pgassert(*return_count == 0);
290 
291  graphType gType = directed? DIRECTED: UNDIRECTED;
292 
293 
294  std::vector<pgr_combination_t>
295  combinations_vector(combinations, combinations + total_combinations);
296 
297  size_t n = n_goals <= 0? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);
298 
299  std::deque< Path >paths;
300  if (directed) {
301  pgrouting::DirectedGraph digraph(gType);
302  digraph.insert_edges(data_edges, total_edges);
303  paths = detail::pgr_dijkstra(
304  digraph,
305  combinations_vector,
306  only_cost, normal, n, global);
307  } else {
308  pgrouting::UndirectedGraph undigraph(gType);
309  undigraph.insert_edges(data_edges, total_edges);
310  paths = detail::pgr_dijkstra(
311  undigraph,
312  combinations_vector,
313  only_cost, normal, n, global);
314  }
315  combinations_vector.clear();
316  size_t count(0);
317  count = count_tuples(paths);
318 
319  if (count == 0) {
320  (*return_tuples) = NULL;
321  (*return_count) = 0;
322  notice << "No paths found";
323  *log_msg = pgr_msg(notice.str().c_str());
324  return;
325  }
326 
327  (*return_tuples) = pgr_alloc(count, (*return_tuples));
328  (*return_count) = (collapse_paths(return_tuples, paths));
329 
330  *log_msg = log.str().empty()?
331  *log_msg :
332  pgr_msg(log.str().c_str());
333  *notice_msg = notice.str().empty()?
334  *notice_msg :
335  pgr_msg(notice.str().c_str());
336  } catch (AssertFailedException &except) {
337  (*return_tuples) = pgr_free(*return_tuples);
338  (*return_count) = 0;
339  err << except.what();
340  *err_msg = pgr_msg(err.str().c_str());
341  *log_msg = pgr_msg(log.str().c_str());
342  } catch (std::exception &except) {
343  (*return_tuples) = pgr_free(*return_tuples);
344  (*return_count) = 0;
345  err << except.what();
346  *err_msg = pgr_msg(err.str().c_str());
347  *log_msg = pgr_msg(log.str().c_str());
348  } catch(...) {
349  (*return_tuples) = pgr_free(*return_tuples);
350  (*return_count) = 0;
351  err << "Caught unknown exception!";
352  *err_msg = pgr_msg(err.str().c_str());
353  *log_msg = pgr_msg(log.str().c_str());
354  }
355 }

References collapse_paths(), count_tuples(), DIRECTED, pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_alloc(), detail::pgr_dijkstra(), pgr_free(), pgr_msg(), UNDIRECTED, and AssertFailedException::what().

Referenced by process_combinations().

◆ do_pgr_many_to_many_dijkstra()

void do_pgr_many_to_many_dijkstra ( pgr_edge_t data_edges,
size_t  total_edges,
int64_t *  start_vidsArr,
size_t  size_start_vidsArr,
int64_t *  end_vidsArr,
size_t  size_end_vidsArr,
bool  directed,
bool  only_cost,
bool  normal,
int64_t  n_goals,
bool  global,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 158 of file dijkstra_driver.cpp.

175  {
176  std::ostringstream log;
177  std::ostringstream err;
178  std::ostringstream notice;
179 
180  try {
181  pgassert(total_edges != 0);
182  pgassert(!(*log_msg));
183  pgassert(!(*notice_msg));
184  pgassert(!(*err_msg));
185  pgassert(!(*return_tuples));
186  pgassert(*return_count == 0);
187 
188  graphType gType = directed? DIRECTED: UNDIRECTED;
189 
190  std::vector<int64_t>
191  start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr);
192  std::vector< int64_t >
193  end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
194 
195  size_t n = n_goals <= 0? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);
196 
197  std::deque< Path >paths;
198  if (directed) {
199  pgrouting::DirectedGraph digraph(gType);
200  digraph.insert_edges(data_edges, total_edges);
201  paths = detail::pgr_dijkstra(
202  digraph,
203  start_vertices, end_vertices,
204  only_cost, normal, n, global);
205  } else {
206  pgrouting::UndirectedGraph undigraph(gType);
207  undigraph.insert_edges(data_edges, total_edges);
208  paths = detail::pgr_dijkstra(
209  undigraph,
210  start_vertices, end_vertices,
211  only_cost, normal, n, global);
212  }
213 
214  size_t count(0);
215  count = count_tuples(paths);
216 
217  if (count == 0) {
218  (*return_tuples) = NULL;
219  (*return_count) = 0;
220  notice <<
221  "No paths found";
222  *log_msg = pgr_msg(notice.str().c_str());
223  return;
224  }
225 
226  (*return_tuples) = pgr_alloc(count, (*return_tuples));
227  (*return_count) = (collapse_paths(return_tuples, paths));
228 
229  *log_msg = log.str().empty()?
230  *log_msg :
231  pgr_msg(log.str().c_str());
232  *notice_msg = notice.str().empty()?
233  *notice_msg :
234  pgr_msg(notice.str().c_str());
235  } catch (AssertFailedException &except) {
236  (*return_tuples) = pgr_free(*return_tuples);
237  (*return_count) = 0;
238  err << except.what();
239  *err_msg = pgr_msg(err.str().c_str());
240  *log_msg = pgr_msg(log.str().c_str());
241  } catch (std::exception &except) {
242  (*return_tuples) = pgr_free(*return_tuples);
243  (*return_count) = 0;
244  err << except.what();
245  *err_msg = pgr_msg(err.str().c_str());
246  *log_msg = pgr_msg(log.str().c_str());
247  } catch(...) {
248  (*return_tuples) = pgr_free(*return_tuples);
249  (*return_count) = 0;
250  err << "Caught unknown exception!";
251  *err_msg = pgr_msg(err.str().c_str());
252  *log_msg = pgr_msg(log.str().c_str());
253  }
254 }

References collapse_paths(), count_tuples(), DIRECTED, pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_alloc(), detail::pgr_dijkstra(), pgr_free(), pgr_msg(), UNDIRECTED, and AssertFailedException::what().

Referenced by process().

pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
count_tuples
size_t count_tuples(const std::deque< Path > &paths)
Definition: basePath_SSEC.cpp:387
pgr_msg
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
AssertFailedException::what
virtual const char * what() const
Definition: pgr_assert.cpp:67
collapse_paths
size_t collapse_paths(General_path_element_t **ret_path, const std::deque< Path > &paths)
Definition: basePath_SSEC.cpp:310
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
detail::pgr_dijkstra
std::deque< Path > pgr_dijkstra(G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, bool only_cost, bool normal, size_t n_goals, bool global)
Definition: dijkstra_driver.cpp:100
graphType
graphType
Definition: graph_enum.h:30
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139