PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
withPoints_ksp_driver.h File Reference
Include dependency graph for withPoints_ksp_driver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int do_pgr_withPointsKsp (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_pid, int64_t end_pid, int k, bool directed, bool heap_paths, char driving_side, bool details, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

int do_pgr_withPointsKsp ( 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_pid,
int64_t  end_pid,
int  k,
bool  directed,
bool  heap_paths,
char  driving_side,
bool  details,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 53 of file withPoints_ksp_driver.cpp.

References check_points(), count_tuples(), create_new_edges(), DIRECTED, eliminate_details(), pgrouting::extract_vertices(), pgrouting::graph::Pgr_base_graph< G, Vertex, Edge >::insert_edges(), pgassert, pgr_alloc(), UNDIRECTED, AssertFailedException::what(), and Pgr_ksp< G >::Yen().

Referenced by process().

68  {
69 
70  std::ostringstream log;
71  std::ostringstream err;
72  std::ostringstream notice;
73  try {
74  pgassert(!(*log_msg));
75  pgassert(!(*notice_msg));
76  pgassert(!(*err_msg));
77  pgassert(!(*return_tuples));
78  pgassert(*return_count == 0);
79  pgassert(total_edges != 0);
80 
81  log << "entering do_pgr_withPointsKsp\n";
82 
83  std::vector< Point_on_edge_t >
84  points(points_p, points_p + total_points);
85 
86  log << "total points" << points.size() << "\n";
87 
88  auto errcode = check_points(points, log);
89  if (errcode) {
90  *log_msg = strdup(log.str().c_str());
91  err << "Unexpected point(s) with same pid but different edge/fraction/side combination found.";
92  *err_msg = strdup(err.str().c_str());
93  return -1;
94  }
95 
96  std::vector< pgr_edge_t >
97  edges_to_modify(edges_of_points, edges_of_points + total_edges_of_points);
98 
99  std::vector< pgr_edge_t > new_edges;
100 
102  points,
103  edges_to_modify,
104  driving_side,
105  new_edges,
106  log);
107 
108 
109 
110  int64_t start_vid(start_pid);
111  int64_t end_vid(end_pid);
112 
113  log << "start_pid" << start_pid << "\n";
114  log << "end_pid" << end_pid << "\n";
115  log << "driving_side" << driving_side << "\n";
116  log << "start_vid" << start_vid << "\n";
117  log << "end_vid" << end_vid << "\n";
118  graphType gType = directed? DIRECTED: UNDIRECTED;
119 
120  std::deque< Path > paths;
121 
122  auto vertices(pgrouting::extract_vertices(edges, total_edges));
123  vertices = pgrouting::extract_vertices(vertices, new_edges);
124 
125  log << "extracted vertices: ";
126  for (const auto v : vertices) {
127  log << v.id << ", ";
128  }
129  log << "\n";
130 
131  if (directed) {
132  log << "Working with directed Graph\n";
133  pgrouting::DirectedGraph digraph(vertices, gType);
134  digraph.insert_edges(edges, total_edges);
135  log << "graph after inserting edges\n";
136  log << digraph << "\n";
137 
138  digraph.insert_edges(new_edges);
139  log << "graph after inserting new edges\n";
140  log << digraph << "\n";
141 
143  paths = fn_yen.Yen(digraph, start_vid, end_vid, k, heap_paths);
144  // pgassert(true==false);
145  } else {
146  log << "Working with undirected Graph\n";
147  pgrouting::UndirectedGraph undigraph(gType);
148  undigraph.insert_edges(edges, total_edges);
149  undigraph.insert_edges(new_edges);
151  paths = fn_yen.Yen(undigraph, start_vid, end_vid, k, heap_paths);
152  }
153 
154 
155  if (!details) {
156  for (auto &path : paths) {
157  eliminate_details(path, edges_to_modify);
158  }
159  }
160 
161  auto count(count_tuples(paths));
162 
163  if (count == 0) {
164  return 0;
165  }
166 
167 
168  *return_tuples = NULL;
169  *return_tuples = pgr_alloc(count, (*return_tuples));
170 
171  size_t sequence = 0;
172  int route_id = 0;
173  for (const auto &path : paths) {
174  if (path.size() > 0)
175  path.get_pg_ksp_path(return_tuples, sequence, route_id);
176  ++route_id;
177  }
178 
179  if (count != sequence) {
180  return 2;
181  }
182  (*return_count) = sequence;
183 
184 
185  *log_msg = strdup(log.str().c_str());
186  return 0;
187  } catch (AssertFailedException &except) {
188  if (*return_tuples) free(*return_tuples);
189  (*return_count) = 0;
190  err << except.what();
191  *err_msg = strdup(err.str().c_str());
192  *log_msg = strdup(log.str().c_str());
193  } catch (std::exception &except) {
194  if (*return_tuples) free(*return_tuples);
195  (*return_count) = 0;
196  err << except.what();
197  *err_msg = strdup(err.str().c_str());
198  *log_msg = strdup(log.str().c_str());
199  } catch(...) {
200  if (*return_tuples) free(*return_tuples);
201  (*return_count) = 0;
202  err << "Caught unknown exception!";
203  *err_msg = strdup(err.str().c_str());
204  *log_msg = strdup(log.str().c_str());
205  }
206  return 1000;
207 }
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)
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)
size_t count_tuples(const std::deque< Path > &paths)
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:64
virtual const char * what() const
Definition: pgr_assert.cpp:53
std::deque< Path > Yen(G &graph, int64_t source, int64_t target, int K, bool heap_paths)
Definition: pgr_ksp.hpp:148
graphType
Definition: graph_enum.h:30

Here is the call graph for this function:

Here is the caller graph for this function: