PGROUTING  3.2
bdAstar_driver.h File Reference
#include <stddef.h>
#include "c_types/pgr_edge_xy_t.h"
#include "c_types/pgr_combination_t.h"
#include "c_types/general_path_element_t.h"
Include dependency graph for bdAstar_driver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void do_pgr_bdAstar (Pgr_edge_xy_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, 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)
 

Function Documentation

◆ do_pgr_bdAstar()

void do_pgr_bdAstar ( Pgr_edge_xy_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,
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
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
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
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
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139