PGROUTING  3.2
withPoints_driver.h File Reference
Include dependency graph for withPoints_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_withPoints (pgr_edge_t *edges, size_t total_edges, Point_on_edge_t *points, size_t total_points, pgr_edge_t *edges_of_points, size_t total_edges_of_points, pgr_combination_t *combinations, size_t total_combinations, int64_t *start_pidsArr, size_t size_start_pidsArr, int64_t *end_pidsArr, size_t size_end_pidsArr, char driving_side, bool details, bool directed, 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_withPoints()

void do_pgr_withPoints ( pgr_edge_t edges,
size_t  total_edges,
Point_on_edge_t points,
size_t  total_points,
pgr_edge_t edges_of_points,
size_t  total_edges_of_points,
pgr_combination_t combinations,
size_t  total_combinations,
int64_t *  start_pidsArr,
size_t  size_start_pidsArr,
int64_t *  end_pidsArr,
size_t  size_end_pidsArr,
char  driving_side,
bool  details,
bool  directed,
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 93 of file withPoints_driver.cpp.

113  {
114  std::ostringstream log;
115  std::ostringstream notice;
116  std::ostringstream err;
117  try {
118  pgassert(!(*log_msg));
119  pgassert(!(*notice_msg));
120  pgassert(!(*err_msg));
121  pgassert(!(*return_tuples));
122  pgassert((*return_count) == 0);
123  pgassert(edges || edges_of_points);
124 
126  std::vector<Point_on_edge_t>(
127  points_p,
128  points_p + total_points),
129  std::vector< pgr_edge_t >(
130  edges_of_points,
131  edges_of_points + total_edges_of_points),
132  normal,
133  driving_side,
134  directed);
135 
136  if (pg_graph.has_error()) {
137  log << pg_graph.get_log();
138  err << pg_graph.get_error();
139  *log_msg = pgr_msg(log.str().c_str());
140  *err_msg = pgr_msg(err.str().c_str());
141  return;
142  }
143 
144 
145  std::vector<pgr_combination_t>
146  combinations_vector(combinations, combinations + total_combinations);
147  std::vector<int64_t>
148  start_vertices(start_pidsArr, start_pidsArr + size_start_pidsArr);
149  std::vector< int64_t >
150  end_vertices(end_pidsArr, end_pidsArr + size_end_pidsArr);
151 
152  auto vertices(pgrouting::extract_vertices(edges, total_edges));
153  vertices = pgrouting::extract_vertices(vertices, pg_graph.new_edges());
154 
155  graphType gType = directed? DIRECTED: UNDIRECTED;
156 
157  std::deque< Path > paths;
158 
159  if (directed) {
160  log << "Working with directed Graph\n";
161  pgrouting::DirectedGraph digraph(vertices, gType);
162  digraph.insert_edges(edges, total_edges);
163  digraph.insert_edges(pg_graph.new_edges());
164 
165  paths = pgr_dijkstra(
166  digraph,
167  combinations_vector,
168  start_vertices, end_vertices,
169  only_cost, normal);
170  } else {
171  log << "Working with Undirected Graph\n";
172  pgrouting::UndirectedGraph undigraph(vertices, gType);
173  undigraph.insert_edges(edges, total_edges);
174  undigraph.insert_edges(pg_graph.new_edges());
175  paths = pgr_dijkstra(
176  undigraph,
177  combinations_vector,
178  start_vertices, end_vertices,
179  only_cost, normal);
180  }
181 
182  if (!details) {
183  for (auto &path : paths) {
184  path = pg_graph.eliminate_details(path);
185  }
186  }
187 
188  /*
189  * order paths based on the start_pid, end_pid
190  */
191  std::sort(paths.begin(), paths.end(),
192  [](const Path &a, const Path &b)
193  -> bool {
194  if (b.start_id() != a.start_id()) {
195  return a.start_id() < b.start_id();
196  }
197  return a.end_id() < b.end_id();
198  });
199 
200  size_t count(0);
201  count = count_tuples(paths);
202 
203 
204  if (count == 0) {
205  (*return_tuples) = NULL;
206  (*return_count) = 0;
207  return;
208  }
209 
210  (*return_tuples) = pgr_alloc(count, (*return_tuples));
211  log << "Converting a set of paths into the tuples\n";
212  (*return_count) = (collapse_paths(return_tuples, paths));
213 
214  log << "************************************************";
215  log << pg_graph.get_log();
216  log << "************************************************";
217 
218  *log_msg = log.str().empty()?
219  *log_msg :
220  pgr_msg(log.str().c_str());
221  *notice_msg = notice.str().empty()?
222  *notice_msg :
223  pgr_msg(notice.str().c_str());
224  } catch (AssertFailedException &except) {
225  (*return_tuples) = pgr_free(*return_tuples);
226  (*return_count) = 0;
227  err << except.what();
228  *err_msg = pgr_msg(err.str().c_str());
229  *log_msg = pgr_msg(log.str().c_str());
230  } catch (std::exception &except) {
231  (*return_tuples) = pgr_free(*return_tuples);
232  (*return_count) = 0;
233  err << except.what();
234  *err_msg = pgr_msg(err.str().c_str());
235  *log_msg = pgr_msg(log.str().c_str());
236  } catch(...) {
237  (*return_tuples) = pgr_free(*return_tuples);
238  (*return_count) = 0;
239  err << "Caught unknown exception!";
240  *err_msg = pgr_msg(err.str().c_str());
241  *log_msg = pgr_msg(log.str().c_str());
242  }
243 }

References collapse_paths(), count_tuples(), DIRECTED, pgrouting::Pg_points_graph::eliminate_details(), Path::end_id(), pgrouting::extract_vertices(), pgrouting::Pgr_messages::get_error(), pgrouting::Pgr_messages::get_log(), pgrouting::Pgr_messages::has_error(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgrouting::Pg_points_graph::new_edges(), pgassert, pgr_alloc(), pgr_dijkstra(), pgr_msg(), and UNDIRECTED.

Referenced by process().

Path::end_id
int64_t end_id() const
Definition: basePath_SSEC.hpp:67
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
pgrouting::Pg_points_graph
Definition: pgr_withPoints.hpp:40
collapse_paths
size_t collapse_paths(General_path_element_t **ret_path, const std::deque< Path > &paths)
Definition: basePath_SSEC.cpp:310
pgr_dijkstra
std::deque< Path > pgr_dijkstra(G &graph, std::vector< pgr_combination_t > &combinations, std::vector< int64_t > sources, std::vector< int64_t > targets, bool only_cost, bool normal)
Definition: withPoints_driver.cpp:48
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
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139