PGROUTING  2.6-dev
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 count_tuples(), DIRECTED, pgrouting::Pg_points_graph::eliminate_details(), 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_free(), pgr_msg(), UNDIRECTED, AssertFailedException::what(), and Pgr_ksp< G >::Yen().

Referenced by process().

68  {
69  std::ostringstream log;
70  std::ostringstream err;
71  std::ostringstream notice;
72  try {
73  pgassert(!(*log_msg));
74  pgassert(!(*notice_msg));
75  pgassert(!(*err_msg));
76  pgassert(!(*return_tuples));
77  pgassert(*return_count == 0);
78  pgassert(total_edges != 0);
79 
81  std::vector<Point_on_edge_t>(
82  points_p,
83  points_p + total_points),
84  std::vector< pgr_edge_t >(
85  edges_of_points,
86  edges_of_points + total_edges_of_points),
87  true,
88  driving_side,
89  directed);
90 
91  if (pg_graph.has_error()) {
92  log << pg_graph.get_log();
93  err << pg_graph.get_error();
94  *log_msg = pgr_msg(log.str().c_str());
95  *err_msg = pgr_msg(err.str().c_str());
96  return -1;
97  }
98 
99 
100  int64_t start_vid(start_pid);
101  int64_t end_vid(end_pid);
102 
103  log << "start_pid" << start_pid << "\n";
104  log << "end_pid" << end_pid << "\n";
105  log << "driving_side" << driving_side << "\n";
106  log << "start_vid" << start_vid << "\n";
107  log << "end_vid" << end_vid << "\n";
108  graphType gType = directed? DIRECTED: UNDIRECTED;
109 
110  std::deque< Path > paths;
111 
112  auto vertices(pgrouting::extract_vertices(edges, total_edges));
113  vertices = pgrouting::extract_vertices(vertices, pg_graph.new_edges());
114 
115  log << "extracted vertices: ";
116  for (const auto v : vertices) {
117  log << v.id << ", ";
118  }
119  log << "\n";
120 
121  if (directed) {
122  log << "Working with directed Graph\n";
123  pgrouting::DirectedGraph digraph(vertices, gType);
124  digraph.insert_edges(edges, total_edges);
125  log << "graph after inserting edges\n";
126  log << digraph << "\n";
127 
128  digraph.insert_edges(pg_graph.new_edges());
129  log << "graph after inserting new edges\n";
130  log << digraph << "\n";
131 
133  paths = fn_yen.Yen(digraph, start_vid, end_vid, k, heap_paths);
134  // pgassert(true==false);
135  } else {
136  log << "Working with undirected Graph\n";
137  pgrouting::UndirectedGraph undigraph(gType);
138  undigraph.insert_edges(edges, total_edges);
139  undigraph.insert_edges(pg_graph.new_edges());
140 
142  paths = fn_yen.Yen(undigraph, start_vid, end_vid, k, heap_paths);
143  }
144 
145 
146  if (!details) {
147  for (auto &path : paths) {
148  path = pg_graph.eliminate_details(path);
149  }
150  }
151 
152  auto count(count_tuples(paths));
153 
154  if (count == 0) {
155  return 0;
156  }
157 
158 
159  *return_tuples = NULL;
160  *return_tuples = pgr_alloc(count, (*return_tuples));
161 
162  size_t sequence = 0;
163  int route_id = 0;
164  for (const auto &path : paths) {
165  if (path.size() > 0)
166  path.get_pg_ksp_path(return_tuples, sequence, route_id);
167  ++route_id;
168  }
169 
170  if (count != sequence) {
171  return 2;
172  }
173  (*return_count) = sequence;
174 
175  *log_msg = log.str().empty()?
176  *log_msg :
177  pgr_msg(log.str().c_str());
178  *notice_msg = notice.str().empty()?
179  *notice_msg :
180  pgr_msg(notice.str().c_str());
181  return 0;
182  } catch (AssertFailedException &except) {
183  (*return_tuples) = pgr_free(*return_tuples);
184  (*return_count) = 0;
185  err << except.what();
186  *err_msg = pgr_msg(err.str().c_str());
187  *log_msg = pgr_msg(log.str().c_str());
188  } catch (std::exception &except) {
189  (*return_tuples) = pgr_free(*return_tuples);
190  (*return_count) = 0;
191  err << except.what();
192  *err_msg = pgr_msg(err.str().c_str());
193  *log_msg = pgr_msg(log.str().c_str());
194  } catch(...) {
195  (*return_tuples) = pgr_free(*return_tuples);
196  (*return_count) = 0;
197  err << "Caught unknown exception!";
198  *err_msg = pgr_msg(err.str().c_str());
199  *log_msg = pgr_msg(log.str().c_str());
200  }
201  return 1000;
202 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
#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)
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
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: