PGROUTING  3.2
edge_disjoint_paths_driver.h File Reference
#include <stddef.h>
#include "c_types/pgr_edge_t.h"
#include "c_types/pgr_combination_t.h"
#include "c_types/general_path_element_t.h"
Include dependency graph for edge_disjoint_paths_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_edge_disjoint_paths (pgr_edge_t *data_edges, size_t total_tuples, pgr_combination_t *combinations, size_t total_combinations, int64_t *source_vertices, size_t size_source_verticesArr, int64_t *sink_vertices, size_t size_sink_verticesArr, bool directed, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

◆ do_pgr_edge_disjoint_paths()

void do_pgr_edge_disjoint_paths ( pgr_edge_t data_edges,
size_t  total_tuples,
pgr_combination_t combinations,
size_t  total_combinations,
int64_t *  source_vertices,
size_t  size_source_verticesArr,
int64_t *  sink_vertices,
size_t  size_sink_verticesArr,
bool  directed,
General_path_element_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 66 of file edge_disjoint_paths_driver.cpp.

80  {
81  std::ostringstream log;
82  std::ostringstream notice;
83  std::ostringstream err;
84  try {
85  pgassert(!(*log_msg));
86  pgassert(!(*notice_msg));
87  pgassert(!(*err_msg));
88  pgassert(!(*return_tuples));
89  pgassert(*return_count == 0);
90  pgassert(data_edges);
91  pgassert(total_edges != 0);
92  pgassert((sources && sinks) || combinations);
93  pgassert((size_source_verticesArr && size_sink_verticesArr) || total_combinations);
94 
95  std::set<int64_t> set_source_vertices(
96  sources, sources + size_source_verticesArr);
97  std::set<int64_t> set_sink_vertices(
98  sinks, sinks + size_sink_verticesArr);
99  std::vector< pgr_combination_t > combinations_vector(
100  combinations, combinations + total_combinations);
101  std::vector<pgr_edge_t> edges(
102  data_edges, data_edges + total_edges);
103 
104  if (!combinations_vector.empty()) {
105  pgassert(set_source_vertices.empty());
106  pgassert(set_sink_vertices.empty());
107 
108  for (const pgr_combination_t &comb : combinations_vector) {
109  set_source_vertices.insert(comb.source);
110  set_sink_vertices.insert(comb.target);
111  }
112  }
113 
114 
115  std::vector<General_path_element_t> paths;
116  for (const auto &s : set_source_vertices) {
117  for (const auto &t : set_sink_vertices) {
118  auto path = single_execution(
119  edges,
120  s,
121  t,
122  directed);
123  paths.insert(paths.end(), path.begin(), path.end());
124  }
125  }
126 
127  if (paths.empty()) {
128  *return_tuples = nullptr;
129  *return_count = 0;
130  return;
131  }
132 
133  /*
134  * Initializing the cost
135  */
136  for (auto &r : paths) {
137  r.agg_cost = r.cost = 0;
138  }
139 
140  /*
141  * Calculating the cost
142  */
143  auto found = paths.size();
144  for (const auto &e : edges) {
145  for (auto &r : paths) {
146  if (r.edge == e.id) {
147  r.cost = (r.node == e.source) ?
148  e.cost : e.reverse_cost;
149  --found;
150  }
151  }
152  if (found == 0) break;
153  }
154 
155  /*
156  * Calculating the agg_cost
157  */
158  auto prev = paths[0];
159  for (auto &r : paths) {
160  if (r.seq == 1) {
161  r.agg_cost = 0;
162  } else {
163  r.agg_cost = prev.agg_cost + prev.cost;
164  }
165  prev = r;
166  }
167 
168  /*
169  * Numbering the paths
170  */
171  int path_id(0);
172  for (auto &r : paths) {
173  r.start_id = path_id;
174  if (r.edge == -1) ++path_id;
175  }
176 
177 
178  (*return_tuples) = pgr_alloc(paths.size(), (*return_tuples));
179  for (size_t i = 0; i < paths.size(); ++i) {
180  (*return_tuples)[i] = paths[i];
181  }
182  *return_count = paths.size();
183 
184 
185  *log_msg = log.str().empty()?
186  *log_msg :
187  pgr_msg(log.str().c_str());
188  *notice_msg = notice.str().empty()?
189  *notice_msg :
190  pgr_msg(notice.str().c_str());
191  } catch (AssertFailedException &except) {
192  (*return_tuples) = pgr_free(*return_tuples);
193  (*return_count) = 0;
194  err << except.what();
195  *err_msg = pgr_msg(err.str().c_str());
196  *log_msg = pgr_msg(log.str().c_str());
197  } catch (std::exception &except) {
198  (*return_tuples) = pgr_free(*return_tuples);
199  (*return_count) = 0;
200  err << except.what();
201  *err_msg = pgr_msg(err.str().c_str());
202  *log_msg = pgr_msg(log.str().c_str());
203  } catch(...) {
204  (*return_tuples) = pgr_free(*return_tuples);
205  (*return_count) = 0;
206  err << "Caught unknown exception!";
207  *err_msg = pgr_msg(err.str().c_str());
208  *log_msg = pgr_msg(log.str().c_str());
209  }
210 }

References General_path_element_t::agg_cost, pgassert, pgr_alloc(), pgr_free(), pgr_msg(), single_execution(), and AssertFailedException::what().

Referenced by process().

pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
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
single_execution
static std::vector< General_path_element_t > single_execution(std::vector< pgr_edge_t > edges, int64_t source, int64_t target, bool directed)
Definition: edge_disjoint_paths_driver.cpp:45
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgr_combination_t
Definition: pgr_combination_t.h:43
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
General_path_element_t::agg_cost
double agg_cost
Definition: general_path_element_t.h:44
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139