PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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, Vertex, Edge >::insert_edges(), pgassert, pgr_alloc(), pgr_bdDijkstra(), 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 #if 0
166  auto count = path.size();
167 
168  if (count == 0) {
169  (*return_tuples) = NULL;
170  (*return_count) = 0;
171  notice <<
172  "No paths found between start_vid and end_vid vertices";
173  } else {
174  (*return_tuples) = pgr_alloc(count, (*return_tuples));
175  size_t sequence = 0;
176  path.generate_postgres_data(return_tuples, sequence);
177  (*return_count) = sequence;
178  }
179 #endif
180  pgassert(*err_msg == NULL);
181  *log_msg = log.str().empty()?
182  nullptr :
183  strdup(log.str().c_str());
184  *notice_msg = notice.str().empty()?
185  nullptr :
186  strdup(notice.str().c_str());
187  } catch (AssertFailedException &except) {
188  if (*return_tuples) free(*return_tuples);
189  (*return_count) = 0;
190  err << except.what();
191  *err_msg = strdup(err.str().c_str());
192  *log_msg = strdup(log.str().c_str());
193  } catch (std::exception& except) {
194  if (*return_tuples) free(*return_tuples);
195  (*return_count) = 0;
196  err << except.what();
197  *err_msg = strdup(err.str().c_str());
198  *log_msg = strdup(log.str().c_str());
199  } catch(...) {
200  if (*return_tuples) free(*return_tuples);
201  (*return_count) = 0;
202  err << "Caught unknown exception!";
203  *err_msg = strdup(err.str().c_str());
204  *log_msg = strdup(log.str().c_str());
205  }
206 }
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)
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:29
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
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: