PGROUTING  3.2
astar_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 astar_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_astarManyToMany (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, bool normal, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

◆ do_pgr_astarManyToMany()

void do_pgr_astarManyToMany ( 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,
bool  normal,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 86 of file astar_driver.cpp.

103  {
104  std::ostringstream log;
105  std::ostringstream notice;
106  std::ostringstream err;
107  try {
108  pgassert(!(*log_msg));
109  pgassert(!(*err_msg));
110  pgassert(!(*return_tuples));
111  pgassert(*return_count == 0);
112  pgassert(total_edges != 0);
113 
114 
115  log << "Inserting target vertices into a c++ vector structure\n";
116  std::vector<pgr_combination_t>
117  combinations_vector(combinations, combinations + total_combinations);
118  std::vector< int64_t > end_vids(
119  end_vidsArr,
120  end_vidsArr + size_end_vidsArr);
121  std::vector< int64_t > start_vids(
122  start_vidsArr,
123  start_vidsArr + size_start_vidsArr);
124 
125  graphType gType = directed? DIRECTED: UNDIRECTED;
126 
127  std::deque< Path >paths;
128  if (directed) {
129  log << "Working with directed Graph\n";
131  pgrouting::extract_vertices(edges, total_edges),
132  gType);
133  digraph.insert_edges(edges, total_edges);
134  paths = pgr_astar(digraph, combinations_vector, start_vids, end_vids,
135  heuristic, factor, epsilon, only_cost, normal);
136  } else {
137  log << "Working with Undirected Graph\n";
139  pgrouting::extract_vertices(edges, total_edges),
140  gType);
141  undigraph.insert_edges(edges, total_edges);
142  paths = pgr_astar(undigraph, combinations_vector, start_vids, end_vids,
143  heuristic, factor, epsilon, only_cost, normal);
144  }
145 
146  size_t count(0);
147  count = count_tuples(paths);
148 
149 
150  if (count == 0) {
151  (*return_tuples) = NULL;
152  (*return_count) = 0;
153  notice <<
154  "No paths found\n";
155  *log_msg = pgr_msg(notice.str().c_str());
156  return;
157  }
158 
159  (*return_tuples) = pgr_alloc(count, (*return_tuples));
160  log << "Converting a set of paths into the tuples\n";
161  (*return_count) = (collapse_paths(return_tuples, paths));
162 
163  *log_msg = log.str().empty()?
164  *log_msg :
165  pgr_msg(log.str().c_str());
166  *notice_msg = notice.str().empty()?
167  *notice_msg :
168  pgr_msg(notice.str().c_str());
169  } catch (AssertFailedException &except) {
170  (*return_tuples) = pgr_free(*return_tuples);
171  (*return_count) = 0;
172  err << except.what();
173  *err_msg = pgr_msg(err.str().c_str());
174  *log_msg = pgr_msg(log.str().c_str());
175  } catch (std::exception &except) {
176  (*return_tuples) = pgr_free(*return_tuples);
177  (*return_count) = 0;
178  err << except.what();
179  *err_msg = pgr_msg(err.str().c_str());
180  *log_msg = pgr_msg(log.str().c_str());
181  } catch(...) {
182  (*return_tuples) = pgr_free(*return_tuples);
183  (*return_count) = 0;
184  err << "Caught unknown exception!";
185  *err_msg = pgr_msg(err.str().c_str());
186  *log_msg = pgr_msg(log.str().c_str());
187  }
188 }

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_astar(), 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
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
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
pgr_astar
std::deque< Path > pgr_astar(G &graph, std::vector< pgr_combination_t > &combinations, std::vector< int64_t > sources, std::vector< int64_t > targets, int heuristic, double factor, double epsilon, bool only_cost, bool normal)
Definition: astar_driver.cpp:46
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139