PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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, Vertex, Edge >::insert_edges(), pgassert, pgr_alloc(), 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  log << "buuu";
65 
66  graphType gType = directed? DIRECTED: UNDIRECTED;
67 
68  std::deque< Path > paths;
69 
70  if (directed) {
71  pgrouting::DirectedGraph digraph(gType);
73  digraph.insert_edges(data_edges, total_edges);
74  paths = fn_yen.Yen(digraph, start_vid, end_vid, k, heap_paths);
75  } else {
76  pgrouting::UndirectedGraph undigraph(gType);
78  undigraph.insert_edges(data_edges, total_edges);
79  paths = fn_yen.Yen(undigraph, start_vid, end_vid, k, heap_paths);
80  }
81 
82 
83  auto count(count_tuples(paths));
84 
85  if (!(count == 0)) {
86  // get the space required to store all the paths
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  nullptr :
103  strdup(log.str().c_str());
104  *notice_msg = notice.str().empty()?
105  nullptr :
106  strdup(notice.str().c_str());
107  } catch (AssertFailedException &except) {
108  if (*return_tuples) free(*return_tuples);
109  (*return_count) = 0;
110  err << except.what();
111  *err_msg = strdup(err.str().c_str());
112  *log_msg = strdup(log.str().c_str());
113  } catch (std::exception& except) {
114  if (*return_tuples) free(*return_tuples);
115  (*return_count) = 0;
116  err << except.what();
117  *err_msg = strdup(err.str().c_str());
118  *log_msg = strdup(log.str().c_str());
119  } catch(...) {
120  if (*return_tuples) free(*return_tuples);
121  (*return_count) = 0;
122  err << "Caught unknown exception!";
123  *err_msg = strdup(err.str().c_str());
124  *log_msg = strdup(log.str().c_str());
125  }
126 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
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: