PGROUTING  3.2
bdAstar_driver.cpp File Reference
#include "drivers/bdAstar/bdAstar_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include <algorithm>
#include "bdAstar/pgr_bdAstar.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
Include dependency graph for bdAstar_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_bdAstar (Pgr_edge_xy_t *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, int heuristic, double factor, double epsilon, 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_bdAstar (G &graph, std::vector< pgr_combination_t > &combinations, std::vector< int64_t > sources, std::vector< int64_t > targets, int heuristic, double factor, double epsilon, std::ostream &log, bool only_cost)
 

Function Documentation

◆ do_pgr_bdAstar()

void do_pgr_bdAstar ( Pgr_edge_xy_t 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,
int  heuristic,
double  factor,
double  epsilon,
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 141 of file bdAstar_driver.cpp.

163  {
164  std::ostringstream log;
165  std::ostringstream err;
166  std::ostringstream notice;
167  try {
168  pgassert(!(*log_msg));
169  pgassert(!(*notice_msg));
170  pgassert(!(*err_msg));
171  pgassert(!(*return_tuples));
172  pgassert(*return_count == 0);
173  pgassert(total_edges != 0);
174 
175 
176  log << "Inserting vertices into a c++ vector structure";
177  std::vector<int64_t>
178  start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr);
179  std::vector< int64_t >
180  end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
181  std::vector< pgr_combination_t >
182  combinations_vector(combinations, combinations + total_combinations);
183 
184  graphType gType = directed? DIRECTED: UNDIRECTED;
185 
186  std::deque<Path> paths;
187  log << "starting process\n";
188  if (directed) {
189  log << "Working with directed Graph\n";
191  pgrouting::extract_vertices(edges, total_edges),
192  gType);
193  digraph.insert_edges(edges, total_edges);
194 
195  paths = pgr_bdAstar(digraph,
196  combinations_vector,
197  start_vertices,
198  end_vertices,
199  heuristic,
200  factor,
201  epsilon,
202  log,
203  only_cost);
204  } else {
205  log << "Working with Undirected Graph\n";
207  pgrouting::extract_vertices(edges, total_edges),
208  gType);
209  undigraph.insert_edges(edges, total_edges);
210 
211  paths = pgr_bdAstar(
212  undigraph,
213  combinations_vector,
214  start_vertices,
215  end_vertices,
216  heuristic,
217  factor,
218  epsilon,
219  log,
220  only_cost);
221  }
222 
223  size_t count(0);
224  count = count_tuples(paths);
225 
226  if (count == 0) {
227  (*return_tuples) = NULL;
228  (*return_count) = 0;
229  notice <<
230  "No paths found";
231  *log_msg = pgr_msg(notice.str().c_str());
232  return;
233  }
234 
235  (*return_tuples) = pgr_alloc(count, (*return_tuples));
236  log << "\nConverting a set of paths into the tuples";
237  (*return_count) = (collapse_paths(return_tuples, paths));
238 
239 
240 #if 0
241  auto count = path.size();
242 
243  if (count == 0) {
244  (*return_tuples) = NULL;
245  (*return_count) = 0;
246  notice <<
247  "No paths found between start_vid and end_vid vertices";
248  } else {
249  (*return_tuples) = pgr_alloc(count, (*return_tuples));
250  size_t sequence = 0;
251  path.generate_postgres_data(return_tuples, sequence);
252  (*return_count) = sequence;
253  }
254 #endif
255 
256  pgassert(*err_msg == NULL);
257  *log_msg = log.str().empty()?
258  nullptr :
259  pgr_msg(log.str().c_str());
260  *notice_msg = notice.str().empty()?
261  nullptr :
262  pgr_msg(notice.str().c_str());
263  } catch (AssertFailedException &except) {
264  if (*return_tuples) free(*return_tuples);
265  (*return_count) = 0;
266  err << except.what();
267  *err_msg = pgr_msg(err.str().c_str());
268  *log_msg = pgr_msg(log.str().c_str());
269  } catch (std::exception& except) {
270  if (*return_tuples) free(*return_tuples);
271  (*return_count) = 0;
272  err << except.what();
273  *err_msg = pgr_msg(err.str().c_str());
274  *log_msg = pgr_msg(log.str().c_str());
275  } catch(...) {
276  if (*return_tuples) free(*return_tuples);
277  (*return_count) = 0;
278  err << "Caught unknown exception!";
279  *err_msg = pgr_msg(err.str().c_str());
280  *log_msg = pgr_msg(log.str().c_str());
281  }
282 }

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

Referenced by process().

◆ pgr_bdAstar()

template<class G >
static std::deque<Path> pgr_bdAstar ( G &  graph,
std::vector< pgr_combination_t > &  combinations,
std::vector< int64_t >  sources,
std::vector< int64_t >  targets,
int  heuristic,
double  factor,
double  epsilon,
std::ostream &  log,
bool  only_cost 
)
static

Definition at line 57 of file bdAstar_driver.cpp.

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

References pgrouting::bidirectional::Pgr_bidirectional< G >::clear(), pgrouting::bidirectional::Pgr_bidirectional< G >::log(), and pgrouting::bidirectional::Pgr_bdAstar< G >::pgr_bdAstar().

Referenced by do_pgr_bdAstar().

pgr_bdAstar
static std::deque< Path > pgr_bdAstar(G &graph, std::vector< pgr_combination_t > &combinations, std::vector< int64_t > sources, std::vector< int64_t > targets, int heuristic, double factor, double epsilon, std::ostream &log, bool only_cost)
Definition: bdAstar_driver.cpp:57
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::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
pgrouting::extract_vertices
std::vector< Basic_vertex > extract_vertices(std::vector< Basic_vertex > vertices, const std::vector< pgr_edge_t > data_edges)
Definition: basic_vertex.cpp:59
pgrouting::bidirectional::Pgr_bdAstar
Definition: pgr_bdAstar.hpp:50
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139