PGROUTING  2.6
bdDijkstra_driver.cpp File Reference
#include "drivers/bdDijkstra/bdDijkstra_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include <algorithm>
#include "bdDijkstra/pgr_bdDijkstra.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
#include "cpp_common/pgr_base_graph.hpp"
Include dependency graph for bdDijkstra_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_bdDijkstra (pgr_edge_t *data_edges, size_t total_edges, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, bool only_cost, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 
template<class G >
static std::deque< Pathpgr_bdDijkstra (G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, std::ostream &log, bool only_cost)
 

Function Documentation

void do_pgr_bdDijkstra ( pgr_edge_t data_edges,
size_t  total_edges,
int64_t *  start_vidsArr,
size_t  size_start_vidsArr,
int64_t *  end_vidsArr,
size_t  size_end_vidsArr,
bool  directed,
bool  only_cost,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 87 of file bdDijkstra_driver.cpp.

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

Referenced by process().

102  {
103  std::ostringstream log;
104  std::ostringstream err;
105  std::ostringstream notice;
106  try {
107  pgassert(total_edges != 0);
108  pgassert(size_start_vidsArr != 0);
109  pgassert(size_end_vidsArr != 0);
110 
111  pgassert(!(*log_msg));
112  pgassert(!(*notice_msg));
113  pgassert(!(*err_msg));
114  pgassert(!(*return_tuples));
115  pgassert(*return_count == 0);
116 
117  log << "Inserting vertices into a c++ vector structure";
118  std::vector<int64_t>
119  start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr);
120  std::vector< int64_t >
121  end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
122 
123  graphType gType = directed? DIRECTED: UNDIRECTED;
124 
125  std::deque<Path> paths;
126 
127  log << "starting process\n";
128  if (directed) {
129  log << "Working with directed Graph\n";
130  pgrouting::DirectedGraph digraph(gType);
131  digraph.insert_edges(data_edges, total_edges);
132  paths = pgr_bdDijkstra(digraph,
133  start_vertices,
134  end_vertices,
135  log,
136  only_cost);
137  } else {
138  log << "Working with Undirected Graph\n";
139  pgrouting::UndirectedGraph undigraph(gType);
140  undigraph.insert_edges(data_edges, total_edges);
141  paths = pgr_bdDijkstra(
142  undigraph,
143  start_vertices,
144  end_vertices,
145  log,
146  only_cost);
147  }
148 
149  size_t count(0);
150  count = count_tuples(paths);
151 
152  if (count == 0) {
153  (*return_tuples) = NULL;
154  (*return_count) = 0;
155  notice <<
156  "No paths found";
157  *log_msg = pgr_msg(notice.str().c_str());
158  return;
159  }
160 
161  (*return_tuples) = pgr_alloc(count, (*return_tuples));
162  log << "\nConverting a set of paths into the tuples";
163  (*return_count) = (collapse_paths(return_tuples, paths));
164 
165  pgassert(*err_msg == NULL);
166  *log_msg = log.str().empty()?
167  *log_msg :
168  pgr_msg(log.str().c_str());
169  *notice_msg = notice.str().empty()?
170  *notice_msg :
171  pgr_msg(notice.str().c_str());
172  } catch (AssertFailedException &except) {
173  (*return_tuples) = pgr_free(*return_tuples);
174  (*return_count) = 0;
175  err << except.what();
176  *err_msg = pgr_msg(err.str().c_str());
177  *log_msg = pgr_msg(log.str().c_str());
178  } catch (std::exception &except) {
179  (*return_tuples) = pgr_free(*return_tuples);
180  (*return_count) = 0;
181  err << except.what();
182  *err_msg = pgr_msg(err.str().c_str());
183  *log_msg = pgr_msg(log.str().c_str());
184  } catch(...) {
185  (*return_tuples) = pgr_free(*return_tuples);
186  (*return_count) = 0;
187  err << "Caught unknown exception!";
188  *err_msg = pgr_msg(err.str().c_str());
189  *log_msg = pgr_msg(log.str().c_str());
190  }
191 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
size_t collapse_paths(General_path_element_t **ret_path, const std::deque< Path > &paths)
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
graphType
Definition: graph_enum.h:30
static std::deque< Path > pgr_bdDijkstra(G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, std::ostream &log, bool only_cost)

Here is the call graph for this function:

Here is the caller graph for this function:

template<class G >
static std::deque<Path> pgr_bdDijkstra ( G &  graph,
std::vector< int64_t >  sources,
std::vector< int64_t >  targets,
std::ostream &  log,
bool  only_cost 
)
static

Definition at line 51 of file bdDijkstra_driver.cpp.

References pgrouting::bidirectional::Pgr_bidirectional< G >::clear(), pgrouting::bidirectional::Pgr_bidirectional< G >::log(), and pgrouting::bidirectional::Pgr_bdDijkstra< G >::pgr_bdDijkstra().

Referenced by do_pgr_bdDijkstra().

57  {
58  log << "entering static function\n";
59  std::sort(sources.begin(), sources.end());
60  sources.erase(
61  std::unique(sources.begin(), sources.end()),
62  sources.end());
63 
64  std::sort(targets.begin(), targets.end());
65  targets.erase(
66  std::unique(targets.begin(), targets.end()),
67  targets.end());
68 
70 
71  std::deque<Path> paths;
72  for (const auto source : sources) {
73  for (const auto target : targets) {
74  fn_bdDijkstra.clear();
75  paths.push_back(fn_bdDijkstra.pgr_bdDijkstra(
76  graph.get_V(source), graph.get_V(target), only_cost));
77  }
78  }
79 
80  log << fn_bdDijkstra.log();
81 
82  return paths;
83 }

Here is the call graph for this function:

Here is the caller graph for this function: