PGROUTING  3.2
bdDijkstra_driver.cpp File Reference
#include "drivers/bdDijkstra/bdDijkstra_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include <algorithm>
#include "bdDijkstra/pgr_bdDijkstra.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
#include "cpp_common/pgr_base_graph.hpp"
Include dependency graph for bdDijkstra_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_bdDijkstra (pgr_edge_t *data_edges, size_t total_edges, pgr_combination_t *combinations, size_t total_combinations, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, bool only_cost, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 
template<class G >
static std::deque< Pathpgr_bdDijkstra (G &graph, std::vector< pgr_combination_t > &combinations, std::vector< int64_t > sources, std::vector< int64_t > targets, std::ostream &log, bool only_cost)
 

Function Documentation

◆ do_pgr_bdDijkstra()

void do_pgr_bdDijkstra ( pgr_edge_t data_edges,
size_t  total_edges,
pgr_combination_t combinations,
size_t  total_combinations,
int64_t *  start_vidsArr,
size_t  size_start_vidsArr,
int64_t *  end_vidsArr,
size_t  size_end_vidsArr,
bool  directed,
bool  only_cost,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 129 of file bdDijkstra_driver.cpp.

146  {
147  std::ostringstream log;
148  std::ostringstream err;
149  std::ostringstream notice;
150  try {
151  pgassert(total_edges != 0);
152  pgassert(!(*log_msg));
153  pgassert(!(*notice_msg));
154  pgassert(!(*err_msg));
155  pgassert(!(*return_tuples));
156  pgassert(*return_count == 0);
157 
158  log << "Inserting vertices into a c++ vector structure";
159  std::vector<int64_t>
160  start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr);
161  std::vector< int64_t >
162  end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
163  std::vector< pgr_combination_t >
164  combinations_vector(combinations, combinations + total_combinations);
165 
166  graphType gType = directed? DIRECTED: UNDIRECTED;
167 
168  std::deque<Path> paths;
169 
170  log << "starting process\n";
171  if (directed) {
172  log << "Working with directed Graph\n";
173  pgrouting::DirectedGraph digraph(gType);
174  digraph.insert_edges(data_edges, total_edges);
175  paths = pgr_bdDijkstra(digraph,
176  combinations_vector,
177  start_vertices,
178  end_vertices,
179  log,
180  only_cost);
181  } else {
182  log << "Working with Undirected Graph\n";
183  pgrouting::UndirectedGraph undigraph(gType);
184  undigraph.insert_edges(data_edges, total_edges);
185  paths = pgr_bdDijkstra(
186  undigraph,
187  combinations_vector,
188  start_vertices,
189  end_vertices,
190  log,
191  only_cost);
192  }
193 
194  size_t count(0);
195  count = count_tuples(paths);
196 
197  if (count == 0) {
198  (*return_tuples) = NULL;
199  (*return_count) = 0;
200  notice <<
201  "No paths found";
202  *log_msg = pgr_msg(notice.str().c_str());
203  return;
204  }
205 
206  (*return_tuples) = pgr_alloc(count, (*return_tuples));
207  log << "\nConverting a set of paths into the tuples";
208  (*return_count) = (collapse_paths(return_tuples, paths));
209 
210  pgassert(*err_msg == NULL);
211  *log_msg = log.str().empty()?
212  *log_msg :
213  pgr_msg(log.str().c_str());
214  *notice_msg = notice.str().empty()?
215  *notice_msg :
216  pgr_msg(notice.str().c_str());
217  } catch (AssertFailedException &except) {
218  (*return_tuples) = pgr_free(*return_tuples);
219  (*return_count) = 0;
220  err << except.what();
221  *err_msg = pgr_msg(err.str().c_str());
222  *log_msg = pgr_msg(log.str().c_str());
223  } catch (std::exception &except) {
224  (*return_tuples) = pgr_free(*return_tuples);
225  (*return_count) = 0;
226  err << except.what();
227  *err_msg = pgr_msg(err.str().c_str());
228  *log_msg = pgr_msg(log.str().c_str());
229  } catch(...) {
230  (*return_tuples) = pgr_free(*return_tuples);
231  (*return_count) = 0;
232  err << "Caught unknown exception!";
233  *err_msg = pgr_msg(err.str().c_str());
234  *log_msg = pgr_msg(log.str().c_str());
235  }
236 }

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

Referenced by process().

◆ pgr_bdDijkstra()

template<class G >
static std::deque<Path> pgr_bdDijkstra ( G &  graph,
std::vector< pgr_combination_t > &  combinations,
std::vector< int64_t >  sources,
std::vector< int64_t >  targets,
std::ostream &  log,
bool  only_cost 
)
static

Definition at line 51 of file bdDijkstra_driver.cpp.

58  {
59  log << "entering static function\n";
60 
62  std::deque<Path> paths;
63 
64  if (combinations.empty()) {
65  std::sort(sources.begin(), sources.end());
66  sources.erase(
67  std::unique(sources.begin(), sources.end()),
68  sources.end());
69 
70  std::sort(targets.begin(), targets.end());
71  targets.erase(
72  std::unique(targets.begin(), targets.end()),
73  targets.end());
74 
75  for (const auto source : sources) {
76  for (const auto target : targets) {
77  fn_bdDijkstra.clear();
78 
79  if (!graph.has_vertex(source)
80  || !graph.has_vertex(target)) {
81  paths.push_back(Path(source, target));
82  continue;
83  }
84 
85  paths.push_back(fn_bdDijkstra.pgr_bdDijkstra(
86  graph.get_V(source), graph.get_V(target), only_cost));
87  }
88  }
89 
90  } else {
91  std::sort(combinations.begin(), combinations.end(),
92  [](const pgr_combination_t &lhs, const pgr_combination_t &rhs)->bool {
93  return lhs.target < rhs.target;
94  });
95  std::stable_sort(combinations.begin(), combinations.end(),
96  [](const pgr_combination_t &lhs, const pgr_combination_t &rhs)->bool {
97  return lhs.source < rhs.source;
98  });
99 
100  pgr_combination_t previousCombination{0, 0};
101 
102  for (const pgr_combination_t &comb : combinations) {
103  fn_bdDijkstra.clear();
104  if (comb.source == previousCombination.source &&
105  comb.target == previousCombination.target) {
106  continue;
107  }
108 
109  if (!graph.has_vertex(comb.source)
110  || !graph.has_vertex(comb.target)) {
111  paths.push_back(Path(comb.source, comb.target));
112  continue;
113  }
114 
115  paths.push_back(fn_bdDijkstra.pgr_bdDijkstra(
116  graph.get_V(comb.source), graph.get_V(comb.target), only_cost));
117 
118  previousCombination = comb;
119  }
120  }
121 
122  log << fn_bdDijkstra.log();
123 
124  return paths;
125 }

References pgrouting::bidirectional::Pgr_bidirectional< G >::clear(), pgrouting::bidirectional::Pgr_bidirectional< G >::log(), and pgrouting::bidirectional::Pgr_bdDijkstra< G >::pgr_bdDijkstra().

Referenced by do_pgr_bdDijkstra().

Path
Definition: basePath_SSEC.hpp:47
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
pgr_combination_t
Definition: pgr_combination_t.h:43
graphType
graphType
Definition: graph_enum.h:30
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
pgrouting::bidirectional::Pgr_bdDijkstra
Definition: pgr_bdDijkstra.hpp:49
pgr_bdDijkstra
static std::deque< Path > pgr_bdDijkstra(G &graph, std::vector< pgr_combination_t > &combinations, std::vector< int64_t > sources, std::vector< int64_t > targets, std::ostream &log, bool only_cost)
Definition: bdDijkstra_driver.cpp:51
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