PGROUTING  2.6
dijkstra_driver.cpp File Reference
#include "drivers/dijkstra/dijkstra_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include <algorithm>
#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.

Functions

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, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 
template<class G >
std::deque< Pathpgr_dijkstra (G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, bool only_cost, bool normal)
 

Function Documentation

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,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 79 of file dijkstra_driver.cpp.

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

Referenced by process().

93  {
94  std::ostringstream log;
95  std::ostringstream err;
96  std::ostringstream notice;
97 
98  try {
99  pgassert(total_edges != 0);
100  pgassert(!(*log_msg));
101  pgassert(!(*notice_msg));
102  pgassert(!(*err_msg));
103  pgassert(!(*return_tuples));
104  pgassert(*return_count == 0);
105 
106  graphType gType = directed? DIRECTED: UNDIRECTED;
107 
108  log << "Inserting vertices into a c++ vector structure";
109  std::vector<int64_t>
110  start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr);
111  std::vector< int64_t >
112  end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
113 
114  std::deque< Path >paths;
115  if (directed) {
116  log << "\nWorking with directed Graph";
117  pgrouting::DirectedGraph digraph(gType);
118  digraph.insert_edges(data_edges, total_edges);
119  paths = pgr_dijkstra(
120  digraph,
121  start_vertices, end_vertices,
122  only_cost, normal);
123  } else {
124  log << "\nWorking with Undirected Graph";
125  pgrouting::UndirectedGraph undigraph(gType);
126  undigraph.insert_edges(data_edges, total_edges);
127  paths = pgr_dijkstra(
128  undigraph,
129  start_vertices, end_vertices,
130  only_cost, normal);
131  }
132 
133  size_t count(0);
134  count = count_tuples(paths);
135 
136  if (count == 0) {
137  (*return_tuples) = NULL;
138  (*return_count) = 0;
139  notice <<
140  "No paths found";
141  *log_msg = pgr_msg(notice.str().c_str());
142  return;
143  }
144 
145  (*return_tuples) = pgr_alloc(count, (*return_tuples));
146  log << "\nConverting a set of paths into the tuples";
147  (*return_count) = (collapse_paths(return_tuples, paths));
148 
149  *log_msg = log.str().empty()?
150  *log_msg :
151  pgr_msg(log.str().c_str());
152  *notice_msg = notice.str().empty()?
153  *notice_msg :
154  pgr_msg(notice.str().c_str());
155  } catch (AssertFailedException &except) {
156  (*return_tuples) = pgr_free(*return_tuples);
157  (*return_count) = 0;
158  err << except.what();
159  *err_msg = pgr_msg(err.str().c_str());
160  *log_msg = pgr_msg(log.str().c_str());
161  } catch (std::exception &except) {
162  (*return_tuples) = pgr_free(*return_tuples);
163  (*return_count) = 0;
164  err << except.what();
165  *err_msg = pgr_msg(err.str().c_str());
166  *log_msg = pgr_msg(log.str().c_str());
167  } catch(...) {
168  (*return_tuples) = pgr_free(*return_tuples);
169  (*return_count) = 0;
170  err << "Caught unknown exception!";
171  *err_msg = pgr_msg(err.str().c_str());
172  *log_msg = pgr_msg(log.str().c_str());
173  }
174 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
size_t collapse_paths(General_path_element_t **ret_path, const std::deque< Path > &paths)
std::deque< Path > pgr_dijkstra(G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, bool only_cost, bool normal)
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
size_t count_tuples(const std::deque< Path > &paths)
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
virtual const char * what() const
Definition: pgr_assert.cpp:53
graphType
Definition: graph_enum.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

template<class G >
std::deque< Path > pgr_dijkstra ( G &  graph,
std::vector< int64_t >  sources,
std::vector< int64_t >  targets,
bool  only_cost,
bool  normal 
)

Definition at line 44 of file dijkstra_driver.cpp.

References Pgr_dijkstra< G >::dijkstra(), and Path::reverse().

Referenced by do_pgr_many_to_many_dijkstra(), and pgRouting::pgr_dijkstraVia().

49  {
50  std::sort(sources.begin(), sources.end());
51  sources.erase(
52  std::unique(sources.begin(), sources.end()),
53  sources.end());
54 
55  std::sort(targets.begin(), targets.end());
56  targets.erase(
57  std::unique(targets.begin(), targets.end()),
58  targets.end());
59 
60  Pgr_dijkstra< G > fn_dijkstra;
61  auto paths = fn_dijkstra.dijkstra(graph, sources, targets, only_cost);
62 
63  if (!normal) {
64  for (auto &path : paths) {
65  path.reverse();
66  }
67  }
68  return paths;
69 }
void reverse()
Path dijkstra(G &graph, int64_t start_vertex, int64_t end_vertex, bool only_cost=false)
Dijkstra 1 to 1.

Here is the call graph for this function:

Here is the caller graph for this function: