PGROUTING  2.6
edge_disjoint_paths_driver.h File Reference
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, 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

void do_pgr_edge_disjoint_paths ( pgr_edge_t data_edges,
size_t  total_tuples,
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.

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

Referenced by process().

78  {
79  std::ostringstream log;
80  std::ostringstream notice;
81  std::ostringstream err;
82  try {
83  std::set<int64_t> set_source_vertices(
84  sources, sources + size_source_verticesArr);
85  std::set<int64_t> set_sink_vertices(
86  sinks, sinks + size_sink_verticesArr);
87  std::vector<pgr_edge_t> edges(
88  data_edges, data_edges + total_edges);
89 
90 
91  std::vector<General_path_element_t> paths;
92  for (const auto &s : set_source_vertices) {
93  for (const auto &t : set_sink_vertices) {
94  auto path = single_execution(
95  edges,
96  s,
97  t,
98  directed);
99  paths.insert(paths.end(), path.begin(), path.end());
100  }
101  }
102 
103  if (paths.empty()) {
104  *return_tuples = nullptr;
105  *return_count = 0;
106  return;
107  }
108 
109  /*
110  * Initializing the cost
111  */
112  for (auto &r : paths) {
113  r.agg_cost = r.cost = 0;
114  }
115 
116  /*
117  * Calculating the cost
118  */
119  auto found = paths.size();
120  for (const auto &e : edges) {
121  for (auto &r : paths) {
122  if (r.edge == e.id) {
123  r.cost = (r.node == e.source) ?
124  e.cost : e.reverse_cost;
125  --found;
126  }
127  }
128  if (found == 0) break;
129  }
130 
131  /*
132  * Calculating the agg_cost
133  */
134  auto prev = paths[0];
135  for (auto &r : paths) {
136  if (r.seq == 1) {
137  r.agg_cost = 0;
138  } else {
139  r.agg_cost = prev.agg_cost + prev.cost;
140  }
141  prev = r;
142  }
143 
144  /*
145  * Numbering the paths
146  */
147  int path_id(0);
148  for (auto &r : paths) {
149  r.start_id = path_id;
150  if (r.edge == -1) ++path_id;
151  }
152 
153 
154  (*return_tuples) = pgr_alloc(paths.size(), (*return_tuples));
155  for (size_t i = 0; i < paths.size(); ++i) {
156  (*return_tuples)[i] = paths[i];
157  }
158  *return_count = paths.size();
159 
160 
161  *log_msg = log.str().empty()?
162  *log_msg :
163  pgr_msg(log.str().c_str());
164  *notice_msg = notice.str().empty()?
165  *notice_msg :
166  pgr_msg(notice.str().c_str());
167  } catch (AssertFailedException &except) {
168  (*return_tuples) = pgr_free(*return_tuples);
169  (*return_count) = 0;
170  err << except.what();
171  *err_msg = pgr_msg(err.str().c_str());
172  *log_msg = pgr_msg(log.str().c_str());
173  } catch (std::exception &except) {
174  (*return_tuples) = pgr_free(*return_tuples);
175  (*return_count) = 0;
176  err << except.what();
177  *err_msg = pgr_msg(err.str().c_str());
178  *log_msg = pgr_msg(log.str().c_str());
179  } catch(...) {
180  (*return_tuples) = pgr_free(*return_tuples);
181  (*return_count) = 0;
182  err << "Caught unknown exception!";
183  *err_msg = pgr_msg(err.str().c_str());
184  *log_msg = pgr_msg(log.str().c_str());
185  }
186 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
static std::vector< General_path_element_t > single_execution(std::vector< pgr_edge_t > edges, int64_t source, int64_t target, bool directed)
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
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

Here is the call graph for this function:

Here is the caller graph for this function: