PGROUTING  2.6
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, 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

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