PGROUTING  2.5
withPoints_driver.cpp File Reference
#include "drivers/withPoints/withPoints_driver.h"
#include <algorithm>
#include <sstream>
#include <deque>
#include <vector>
#include <cassert>
#include "dijkstra/pgr_dijkstra.hpp"
#include "./pgr_withPoints.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
Include dependency graph for withPoints_driver.cpp:

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_p, size_t total_points, pgr_edge_t *edges_of_points, size_t total_edges_of_points, 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)
 
template<class G >
std::deque< Pathpgr_dijkstra (G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, bool only_cost, bool normal)
 

Function Documentation

void do_pgr_withPoints ( pgr_edge_t edges,
size_t  total_edges,
Point_on_edge_t points_p,
size_t  total_points,
pgr_edge_t edges_of_points,
size_t  total_edges_of_points,
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 83 of file withPoints_driver.cpp.

References check_points(), collapse_paths(), count_tuples(), create_new_edges(), DIRECTED, eliminate_details(), Path::end_id(), pgrouting::extract_vertices(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_alloc(), pgr_dijkstra(), pgr_free(), pgr_msg(), Path::start_id(), UNDIRECTED, and AssertFailedException::what().

Referenced by process().

100  {
101  std::ostringstream log;
102  std::ostringstream notice;
103  std::ostringstream err;
104  try {
105  pgassert(!(*log_msg));
106  pgassert(!(*notice_msg));
107  pgassert(!(*err_msg));
108  pgassert(!(*return_tuples));
109  pgassert((*return_count) == 0);
110  pgassert(edges || edges_of_points);
111  pgassert(points_p);
112  pgassert(start_pidsArr);
113  pgassert(end_pidsArr);
114 
115  std::vector< Point_on_edge_t >
116  points(points_p, points_p + total_points);
117 
118  if (!normal) {
119  for (auto &point : points) {
120  if (point.side == 'r') {
121  point.side = 'l';
122  } else if (point.side == 'l') {
123  point.side = 'r';
124  }
125  point.fraction = 1 - point.fraction;
126  }
127  if (driving_side == 'r') {
128  driving_side = 'l';
129  } else if (driving_side == 'l') {
130  driving_side = 'r';
131  }
132  }
133 
134  int errcode = check_points(points, log);
135  if (errcode) {
136  *log_msg = strdup(log.str().c_str());
137  err << "Unexpected point(s) with same pid"
138  << " but different edge/fraction/side combination found.";
139  *err_msg = pgr_msg(err.str().c_str());
140  return;
141  }
142 
143 
144  std::vector< pgr_edge_t >
145  edges_to_modify(
146  edges_of_points, edges_of_points + total_edges_of_points);
147 
148  std::vector< pgr_edge_t > new_edges;
150  points,
151  edges_to_modify,
152  driving_side,
153  new_edges, log);
154 
155 
156  std::vector<int64_t>
157  start_vertices(start_pidsArr, start_pidsArr + size_start_pidsArr);
158  std::vector< int64_t >
159  end_vertices(end_pidsArr, end_pidsArr + size_end_pidsArr);
160 
161  auto vertices(pgrouting::extract_vertices(edges, total_edges));
162  vertices = pgrouting::extract_vertices(vertices, new_edges);
163 
164  graphType gType = directed? DIRECTED: UNDIRECTED;
165 
166  std::deque< Path > paths;
167 
168  if (directed) {
169  log << "Working with directed Graph\n";
170  pgrouting::DirectedGraph digraph(vertices, gType);
171  digraph.insert_edges(edges, total_edges);
172  digraph.insert_edges(new_edges);
173 
174  paths = pgr_dijkstra(
175  digraph,
176  start_vertices, end_vertices,
177  only_cost, normal);
178  } else {
179  log << "Working with Undirected Graph\n";
180  pgrouting::UndirectedGraph undigraph(vertices, gType);
181  undigraph.insert_edges(edges, total_edges);
182  undigraph.insert_edges(new_edges);
183  paths = pgr_dijkstra(
184  undigraph,
185  start_vertices, end_vertices,
186  only_cost, normal);
187  }
188 
189  if (!details) {
190  for (auto &path : paths) {
191  eliminate_details(path, edges_to_modify);
192  }
193  }
194 
195  /*
196  * order paths based on the start_pid, end_pid
197  */
198  std::sort(paths.begin(), paths.end(),
199  [](const Path &a, const Path &b)
200  -> bool {
201  if (b.start_id() != a.start_id()) {
202  return a.start_id() < b.start_id();
203  }
204  return a.end_id() < b.end_id();
205  });
206 
207  size_t count(0);
208  count = count_tuples(paths);
209 
210 
211  if (count == 0) {
212  (*return_tuples) = NULL;
213  (*return_count) = 0;
214 #if 0
215  log <<
216  "No paths found";
217  *err_msg = pgr_msg(log.str().c_str());
218 #endif
219  return;
220  }
221 
222  (*return_tuples) = pgr_alloc(count, (*return_tuples));
223  log << "Converting a set of paths into the tuples\n";
224  (*return_count) = (collapse_paths(return_tuples, paths));
225 
226  *log_msg = log.str().empty()?
227  *log_msg :
228  pgr_msg(log.str().c_str());
229  *notice_msg = notice.str().empty()?
230  *notice_msg :
231  pgr_msg(notice.str().c_str());
232  } catch (AssertFailedException &except) {
233  (*return_tuples) = pgr_free(*return_tuples);
234  (*return_count) = 0;
235  err << except.what();
236  *err_msg = pgr_msg(err.str().c_str());
237  *log_msg = pgr_msg(log.str().c_str());
238  } catch (std::exception &except) {
239  (*return_tuples) = pgr_free(*return_tuples);
240  (*return_count) = 0;
241  err << except.what();
242  *err_msg = pgr_msg(err.str().c_str());
243  *log_msg = pgr_msg(log.str().c_str());
244  } catch(...) {
245  (*return_tuples) = pgr_free(*return_tuples);
246  (*return_count) = 0;
247  err << "Caught unknown exception!";
248  *err_msg = pgr_msg(err.str().c_str());
249  *log_msg = pgr_msg(log.str().c_str());
250  }
251 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
void eliminate_details(Path &path, const std::vector< pgr_edge_t > &point_edges)
size_t collapse_paths(General_path_element_t **ret_path, const std::deque< Path > &paths)
std::deque< Path > pgr_dijkstra(G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, bool only_cost, bool normal)
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:79
int64_t end_id() const
int check_points(std::vector< Point_on_edge_t > &points, std::ostringstream &log)
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
bool create_new_edges(std::vector< Point_on_edge_t > &points, const std::vector< pgr_edge_t > &edges, char driving_side, std::vector< pgr_edge_t > &new_edges)
std::vector< Basic_vertex > extract_vertices(std::vector< Basic_vertex > vertices, const std::vector< pgr_edge_t > data_edges)
int64_t start_id() const
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 >
std::deque< Path > pgr_dijkstra ( G &  graph,
std::vector< int64_t >  sources,
std::vector< int64_t >  targets,
bool  only_cost,
bool  normal 
)

Definition at line 47 of file withPoints_driver.cpp.

References Pgr_dijkstra< G >::dijkstra(), and Path::reverse().

Referenced by do_pgr_withPoints().

52  {
53  std::sort(sources.begin(), sources.end());
54  sources.erase(
55  std::unique(sources.begin(), sources.end()),
56  sources.end());
57 
58  std::sort(targets.begin(), targets.end());
59  targets.erase(
60  std::unique(targets.begin(), targets.end()),
61  targets.end());
62 
63  Pgr_dijkstra< G > fn_dijkstra;
64  auto paths = fn_dijkstra.dijkstra(graph, sources, targets, only_cost);
65 
66  if (!normal) {
67  for (auto &path : paths) {
68  path.reverse();
69  }
70  }
71  return paths;
72 }
void reverse()
Path dijkstra(G &graph, int64_t start_vertex, int64_t end_vertex, bool only_cost=false)
Dijkstra 1 to 1.

Here is the call graph for this function:

Here is the caller graph for this function: