PGROUTING  3.2
ksp_driver.h File Reference
#include <stddef.h>
#include "c_types/pgr_edge_t.h"
#include "c_types/general_path_element_t.h"
Include dependency graph for ksp_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_ksp (pgr_edge_t *data_edges, size_t total_edges, int64_t start_vid, int64_t end_vid, size_t K, bool directed, bool heap_paths, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

◆ do_pgr_ksp()

void do_pgr_ksp ( pgr_edge_t data_edges,
size_t  total_edges,
int64_t  start_vid,
int64_t  end_vid,
size_t  K,
bool  directed,
bool  heap_paths,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 43 of file ksp_driver.cpp.

55  {
56  std::ostringstream err;
57  std::ostringstream log;
58  std::ostringstream notice;
59  try {
60  pgassert(!(*log_msg));
61  pgassert(!(*notice_msg));
62  pgassert(!(*err_msg));
63  pgassert(!(*return_tuples));
64  pgassert(*return_count == 0);
65  pgassert(total_edges != 0);
66 
67  graphType gType = directed? DIRECTED: UNDIRECTED;
68 
69  std::deque< Path > paths;
70 
71  if (directed) {
72  pgrouting::DirectedGraph digraph(gType);
74  digraph.insert_edges(data_edges, total_edges);
75  paths = fn_yen.Yen(digraph, start_vid, end_vid, k, heap_paths);
76  } else {
77  pgrouting::UndirectedGraph undigraph(gType);
79  undigraph.insert_edges(data_edges, total_edges);
80  paths = fn_yen.Yen(undigraph, start_vid, end_vid, k, heap_paths);
81  }
82 
83 
84  auto count(count_tuples(paths));
85 
86  if (!(count == 0)) {
87  *return_tuples = NULL;
88  *return_tuples = pgr_alloc(count, (*return_tuples));
89 
90  size_t sequence = 0;
91  int route_id = 0;
92  for (const auto &path : paths) {
93  if (path.size() > 0)
94  path.get_pg_ksp_path(return_tuples, sequence, route_id);
95  ++route_id;
96  }
97  }
98  *return_count = count;
99 
100  pgassert(*err_msg == NULL);
101  *log_msg = log.str().empty()?
102  *log_msg :
103  pgr_msg(log.str().c_str());
104  *notice_msg = notice.str().empty()?
105  *notice_msg :
106  pgr_msg(notice.str().c_str());
107  } catch (AssertFailedException &except) {
108  (*return_tuples) = pgr_free(*return_tuples);
109  (*return_count) = 0;
110  err << except.what();
111  *err_msg = pgr_msg(err.str().c_str());
112  *log_msg = pgr_msg(log.str().c_str());
113  } catch (std::exception &except) {
114  (*return_tuples) = pgr_free(*return_tuples);
115  (*return_count) = 0;
116  err << except.what();
117  *err_msg = pgr_msg(err.str().c_str());
118  *log_msg = pgr_msg(log.str().c_str());
119  } catch(...) {
120  (*return_tuples) = pgr_free(*return_tuples);
121  (*return_count) = 0;
122  err << "Caught unknown exception!";
123  *err_msg = pgr_msg(err.str().c_str());
124  *log_msg = pgr_msg(log.str().c_str());
125  }
126 }

References count_tuples(), DIRECTED, pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_alloc(), pgr_free(), pgr_msg(), UNDIRECTED, AssertFailedException::what(), and pgrouting::yen::Pgr_ksp< G >::Yen().

Referenced by compute().

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
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
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139