PGROUTING  2.5
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, 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< int64_t > sources, std::vector< int64_t > targets, int heuristic, double factor, double epsilon, std::ostream &log, bool only_cost)
 

Function Documentation

void do_pgr_bdAstar ( Pgr_edge_xy_t 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,
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 97 of file bdAstar_driver.cpp.

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().

117  {
118  std::ostringstream log;
119  std::ostringstream err;
120  std::ostringstream notice;
121  try {
122  pgassert(!(*log_msg));
123  pgassert(!(*notice_msg));
124  pgassert(!(*err_msg));
125  pgassert(!(*return_tuples));
126  pgassert(*return_count == 0);
127  pgassert(total_edges != 0);
128 
129 
130  log << "Inserting vertices into a c++ vector structure";
131  std::vector<int64_t>
132  start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr);
133  std::vector< int64_t >
134  end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
135 
136  graphType gType = directed? DIRECTED: UNDIRECTED;
137 
138  std::deque<Path> paths;
139  log << "starting process\n";
140  if (directed) {
141  log << "Working with directed Graph\n";
143  pgrouting::extract_vertices(edges, total_edges),
144  gType);
145  digraph.insert_edges(edges, total_edges);
146 
147  paths = pgr_bdAstar(digraph,
148  start_vertices,
149  end_vertices,
150  heuristic,
151  factor,
152  epsilon,
153  log,
154  only_cost);
155  } else {
156  log << "Working with Undirected Graph\n";
158  pgrouting::extract_vertices(edges, total_edges),
159  gType);
160  undigraph.insert_edges(edges, total_edges);
161 
162  paths = pgr_bdAstar(
163  undigraph,
164  start_vertices,
165  end_vertices,
166  heuristic,
167  factor,
168  epsilon,
169  log,
170  only_cost);
171  }
172 
173  size_t count(0);
174  count = count_tuples(paths);
175 
176  if (count == 0) {
177  (*return_tuples) = NULL;
178  (*return_count) = 0;
179  notice <<
180  "No paths found";
181  *log_msg = pgr_msg(notice.str().c_str());
182  return;
183  }
184 
185  (*return_tuples) = pgr_alloc(count, (*return_tuples));
186  log << "\nConverting a set of paths into the tuples";
187  (*return_count) = (collapse_paths(return_tuples, paths));
188 
189 
190 #if 0
191  auto count = path.size();
192 
193  if (count == 0) {
194  (*return_tuples) = NULL;
195  (*return_count) = 0;
196  notice <<
197  "No paths found between start_vid and end_vid vertices";
198  } else {
199  (*return_tuples) = pgr_alloc(count, (*return_tuples));
200  size_t sequence = 0;
201  path.generate_postgres_data(return_tuples, sequence);
202  (*return_count) = sequence;
203  }
204 #endif
205 
206  pgassert(*err_msg == NULL);
207  *log_msg = log.str().empty()?
208  nullptr :
209  pgr_msg(log.str().c_str());
210  *notice_msg = notice.str().empty()?
211  nullptr :
212  pgr_msg(notice.str().c_str());
213  } catch (AssertFailedException &except) {
214  if (*return_tuples) free(*return_tuples);
215  (*return_count) = 0;
216  err << except.what();
217  *err_msg = pgr_msg(err.str().c_str());
218  *log_msg = pgr_msg(log.str().c_str());
219  } catch (std::exception& except) {
220  if (*return_tuples) free(*return_tuples);
221  (*return_count) = 0;
222  err << except.what();
223  *err_msg = pgr_msg(err.str().c_str());
224  *log_msg = pgr_msg(log.str().c_str());
225  } catch(...) {
226  if (*return_tuples) free(*return_tuples);
227  (*return_count) = 0;
228  err << "Caught unknown exception!";
229  *err_msg = pgr_msg(err.str().c_str());
230  *log_msg = pgr_msg(log.str().c_str());
231  }
232 }
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)
static std::deque< Path > pgr_bdAstar(G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, int heuristic, double factor, double epsilon, std::ostream &log, bool only_cost)
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::vector< Basic_vertex > extract_vertices(std::vector< Basic_vertex > vertices, const std::vector< pgr_edge_t > data_edges)
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:29
size_t count_tuples(const std::deque< Path > &paths)
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:68
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 >
static std::deque<Path> pgr_bdAstar ( G &  graph,
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.

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().

66  {
67  log << "entering static function\n";
68  std::sort(sources.begin(), sources.end());
69  sources.erase(
70  std::unique(sources.begin(), sources.end()),
71  sources.end());
72 
73  std::sort(targets.begin(), targets.end());
74  targets.erase(
75  std::unique(targets.begin(), targets.end()),
76  targets.end());
77 
78 
80  std::deque<Path> paths;
81  for (const auto source : sources) {
82  for (const auto target : targets) {
83  fn_bdAstar.clear();
84 
85  paths.push_back(fn_bdAstar.pgr_bdAstar(
86  graph.get_V(source), graph.get_V(target),
87  heuristic, factor, epsilon, only_cost));
88  }
89  }
90  log << fn_bdAstar.log();
91 
92  return paths;
93 }

Here is the call graph for this function:

Here is the caller graph for this function: