PGROUTING  3.2
binaryBreadthFirstSearch_driver.h File Reference
#include <stddef.h>
#include "c_types/pgr_edge_t.h"
#include "c_types/pgr_combination_t.h"
#include "c_types/general_path_element_t.h"
Include dependency graph for binaryBreadthFirstSearch_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_binaryBreadthFirstSearch (pgr_edge_t *data_edges, size_t total_tuples, 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, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

◆ do_pgr_binaryBreadthFirstSearch()

void do_pgr_binaryBreadthFirstSearch ( pgr_edge_t data_edges,
size_t  total_tuples,
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,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 106 of file binaryBreadthFirstSearch_driver.cpp.

121  {
122  std::ostringstream log;
123  std::ostringstream err;
124  std::ostringstream notice;
125 
126  try {
127  pgassert(total_edges != 0);
128  pgassert(!(*log_msg));
129  pgassert(!(*notice_msg));
130  pgassert(!(*err_msg));
131  pgassert(!(*return_tuples));
132  pgassert(*return_count == 0);
133  pgassert(data_edges);
134  pgassert((start_vidsArr && end_vidsArr) || combinations);
135  pgassert((size_start_vidsArr && size_end_vidsArr) || total_combinations);
136 
137  graphType gType = directed? DIRECTED: UNDIRECTED;
138 
139  // log << "Inserting vertices into a c++ vector structure";
140  std::vector<int64_t>
141  start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr);
142  std::vector< int64_t >
143  end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
144  std::vector< pgr_combination_t >
145  combinations_vector(combinations, combinations + total_combinations);
146 
147  std::deque< Path >paths;
148  if (directed) {
149  // log << "\nWorking with directed Graph";
150  pgrouting::DirectedGraph digraph(gType);
151  digraph.insert_edges(data_edges, total_edges);
152 
153  if (!(costCheck(digraph))) {
154  err << COST_ERR_MSG;
155  *err_msg = pgr_msg(err.str().c_str());
156  return;
157  }
159  digraph,
160  combinations_vector,
161  start_vertices,
162  end_vertices);
163 
164  } else {
165  // log << "\nWorking with Undirected Graph";
166  pgrouting::UndirectedGraph undigraph(gType);
167  undigraph.insert_edges(data_edges, total_edges);
168 
169  if (!(costCheck(undigraph))) {
170  err << COST_ERR_MSG;
171  *err_msg = pgr_msg(err.str().c_str());
172  return;
173  }
174 
176  undigraph,
177  combinations_vector,
178  start_vertices,
179  end_vertices);
180  }
181 
182  size_t count(0);
183  count = count_tuples(paths);
184 
185  if (count == 0) {
186  (*return_tuples) = NULL;
187  (*return_count) = 0;
188  notice <<
189  "No paths found";
190  *log_msg = pgr_msg(notice.str().c_str());
191  return;
192  }
193 
194  (*return_tuples) = pgr_alloc(count, (*return_tuples));
195  log << "\nConverting a set of paths into the tuples";
196  (*return_count) = (collapse_paths(return_tuples, paths));
197 
198  *log_msg = log.str().empty()?
199  *log_msg :
200  pgr_msg(log.str().c_str());
201  *notice_msg = notice.str().empty()?
202  *notice_msg :
203  pgr_msg(notice.str().c_str());
204  } catch (AssertFailedException &except) {
205  (*return_tuples) = pgr_free(*return_tuples);
206  (*return_count) = 0;
207  err << except.what();
208  *err_msg = pgr_msg(err.str().c_str());
209  *log_msg = pgr_msg(log.str().c_str());
210  } catch (std::exception &except) {
211  (*return_tuples) = pgr_free(*return_tuples);
212  (*return_count) = 0;
213  err << except.what();
214  *err_msg = pgr_msg(err.str().c_str());
215  *log_msg = pgr_msg(log.str().c_str());
216  } catch(...) {
217  (*return_tuples) = pgr_free(*return_tuples);
218  (*return_count) = 0;
219  err << "Caught unknown exception!";
220  *err_msg = pgr_msg(err.str().c_str());
221  *log_msg = pgr_msg(log.str().c_str());
222  }
223 }

References collapse_paths(), COST_ERR_MSG, costCheck(), count_tuples(), DIRECTED, pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_alloc(), pgr_binaryBreadthFirstSearch(), 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
pgr_binaryBreadthFirstSearch
std::deque< Path > pgr_binaryBreadthFirstSearch(G &graph, std::vector< pgr_combination_t > &combinations, std::vector< int64_t > sources, std::vector< int64_t > targets)
Definition: binaryBreadthFirstSearch_driver.cpp:47
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
COST_ERR_MSG
const char COST_ERR_MSG[]
Definition: binaryBreadthFirstSearch_driver.cpp:71
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
costCheck
bool costCheck(G &graph)
Definition: binaryBreadthFirstSearch_driver.cpp:75
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139