PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 67 of file edge_disjoint_paths_driver.cpp.

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

Referenced by process().

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

Here is the call graph for this function:

Here is the caller graph for this function: