PGROUTING  3.2
dagShortestPath_driver.cpp File Reference
#include "drivers/dagShortestPath/dagShortestPath_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include <algorithm>
#include "dagShortestPath/pgr_dagShortestPath.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
Include dependency graph for dagShortestPath_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_dagShortestPath (pgr_edge_t *data_edges, size_t total_edges, pgr_combination_t *combinations, size_t total_combinations, 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 >
std::deque< Pathpgr_dagShortestPath (G &graph, std::vector< pgr_combination_t > &combinations, std::vector< int64_t > sources, std::vector< int64_t > targets, bool only_cost=false)
 

Function Documentation

◆ do_pgr_dagShortestPath()

void do_pgr_dagShortestPath ( pgr_edge_t data_edges,
size_t  total_edges,
pgr_combination_t combinations,
size_t  total_combinations,
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 74 of file dagShortestPath_driver.cpp.

90  {
91  std::ostringstream log;
92  std::ostringstream err;
93  std::ostringstream notice;
94  try {
95  pgassert(!(*log_msg));
96  pgassert(!(*notice_msg));
97  pgassert(!(*err_msg));
98  pgassert(!(*return_tuples));
99  pgassert(*return_count == 0);
100  pgassert(total_edges != 0);
101  pgassert(data_edges);
102  pgassert((start_vidsArr && end_vidsArr) || combinations);
103  pgassert((size_start_vidsArr && size_end_vidsArr) || total_combinations);
104 
105  graphType gType = directed? DIRECTED: UNDIRECTED;
106 
107  log << "Inserting vertices into a c++ vector structure";
108  std::vector<int64_t>
109  start_vertices(start_vidsArr, start_vidsArr + size_start_vidsArr);
110  std::vector< int64_t >
111  end_vertices(end_vidsArr, end_vidsArr + size_end_vidsArr);
112  std::vector< pgr_combination_t >
113  combinations_vector(combinations, combinations + total_combinations);
114 
115  std::deque< Path >paths;
116 
117  if (directed) {
118  log << "Working with directed Graph\n";
119  pgrouting::DirectedGraph digraph(gType);
120  digraph.insert_edges(data_edges, total_edges);
121  paths = pgr_dagShortestPath(digraph,
122  combinations_vector,
123  start_vertices,
124  end_vertices,
125  only_cost);
126  } else {
127  log << "Working with Undirected Graph\n";
128  pgrouting::UndirectedGraph undigraph(gType);
129  undigraph.insert_edges(data_edges, total_edges);
130  paths = pgr_dagShortestPath(
131  undigraph,
132  combinations_vector,
133  start_vertices,
134  end_vertices,
135  only_cost);
136  }
137 
138  size_t count(0);
139  count = count_tuples(paths);
140 
141  if (count == 0) {
142  (*return_tuples) = NULL;
143  (*return_count) = 0;
144  notice <<
145  "No paths found between start_vid and end_vid vertices";
146  return;
147  }
148 
149  (*return_tuples) = pgr_alloc(count, (*return_tuples));
150  log << "\nConverting a set of paths into the tuples";
151  (*return_count) = (collapse_paths(return_tuples, paths));
152 
153  *log_msg = log.str().empty()?
154  *log_msg :
155  pgr_msg(log.str().c_str());
156  *notice_msg = notice.str().empty()?
157  *notice_msg :
158  pgr_msg(notice.str().c_str());
159  } catch (AssertFailedException &except) {
160  (*return_tuples) = pgr_free(*return_tuples);
161  (*return_count) = 0;
162  err << except.what();
163  *err_msg = pgr_msg(err.str().c_str());
164  *log_msg = pgr_msg(log.str().c_str());
165  } catch (std::exception &except) {
166  (*return_tuples) = pgr_free(*return_tuples);
167  (*return_count) = 0;
168  err << except.what();
169  *err_msg = pgr_msg(err.str().c_str());
170  *log_msg = pgr_msg(log.str().c_str());
171  } catch(...) {
172  (*return_tuples) = pgr_free(*return_tuples);
173  (*return_count) = 0;
174  err << "Caught unknown exception!";
175  *err_msg = pgr_msg(err.str().c_str());
176  *log_msg = pgr_msg(log.str().c_str());
177  }
178 }

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

Referenced by process().

◆ pgr_dagShortestPath()

template<class G >
std::deque< Path > pgr_dagShortestPath ( G &  graph,
std::vector< pgr_combination_t > &  combinations,
std::vector< int64_t >  sources,
std::vector< int64_t >  targets,
bool  only_cost = false 
)

Definition at line 47 of file dagShortestPath_driver.cpp.

52  {
53  std::sort(sources.begin(), sources.end());
54  sources.erase(
55  std::unique(sources.begin(), sources.end()),
56  sources.end());
57 
58  std::sort(targets.begin(), targets.end());
59  targets.erase(
60  std::unique(targets.begin(), targets.end()),
61  targets.end());
62 
63 
64  Pgr_dag< G > fn_dag;
65  auto paths = combinations.empty() ?
66  fn_dag.dag(graph, sources, targets, only_cost)
67  : fn_dag.dag(graph, combinations, only_cost);
68 
69  return paths;
70 }

References Pgr_dag< G >::dag().

Referenced by do_pgr_dagShortestPath().

Pgr_dag::dag
Path dag(G &graph, int64_t start_vertex, int64_t end_vertex, bool only_cost=false)
Dijkstra 1 to 1.
Definition: pgr_dagShortestPath.hpp:56
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
collapse_paths
size_t collapse_paths(General_path_element_t **ret_path, const std::deque< Path > &paths)
Definition: basePath_SSEC.cpp:310
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
graphType
graphType
Definition: graph_enum.h:30
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
pgr_dagShortestPath
std::deque< Path > pgr_dagShortestPath(G &graph, std::vector< pgr_combination_t > &combinations, std::vector< int64_t > sources, std::vector< int64_t > targets, bool only_cost=false)
Definition: dagShortestPath_driver.cpp:47
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
Pgr_dag
Definition: pgr_dagShortestPath.hpp:49