PGROUTING  2.6-dev
ksp_driver.h File Reference
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, int no_paths, 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

void do_pgr_ksp ( pgr_edge_t data_edges,
size_t  total_edges,
int64_t  start_vid,
int64_t  end_vid,
int  no_paths,
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 41 of file ksp_driver.cpp.

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

Referenced by compute().

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