PGROUTING  3.2
withPoints_ksp_driver.h File Reference
#include <stddef.h>
#include "c_types/point_on_edge_t.h"
#include "c_types/pgr_edge_t.h"
#include "c_types/general_path_element_t.h"
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, size_t 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

◆ do_pgr_withPointsKsp()

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,
size_t  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 54 of file withPoints_ksp_driver.cpp.

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

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 pgrouting::yen::Pgr_ksp< G >::Yen().

Referenced by process().

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::yen::Pgr_ksp::Yen
std::deque< Path > Yen(G &graph, int64_t start_vertex, int64_t end_vertex, size_t K, bool heap_paths)
Definition: pgr_ksp.hpp:61
pgrouting::Pg_points_graph
Definition: pgr_withPoints.hpp:40
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
pgrouting::yen::Pgr_ksp
Definition: pgr_ksp.hpp:47
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