PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
edge_disjoint_paths_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: edge_disjoint_paths_many_to_many_driver.cpp
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 Function's developer:
9 Copyright (c) 2016 Andrea Nardelli
10 Mail: nrd.nardelli@gmail.com
11 
12 ------
13 
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 
28 ********************************************************************PGR-GNU*/
29 
31 
32 #include <sstream>
33 #include <vector>
34 #include <set>
35 
36 #include "./../../common/src/pgr_alloc.hpp"
37 #include "./../../common/src/pgr_assert.h"
38 #include "./../../common/src/pgr_types.h"
39 
41 
42 void
44  pgr_basic_edge_t *data_edges,
45  size_t total_edges,
46  int64_t *source_vertices,
47  size_t size_source_verticesArr,
48  int64_t *sink_vertices,
49  size_t size_sink_verticesArr,
50  bool directed,
51  General_path_element_t **return_tuples,
52  size_t *return_count,
53  char** log_msg,
54  char** notice_msg,
55  char **err_msg) {
56  std::ostringstream log;
57  std::ostringstream notice;
58  std::ostringstream err;
59  try {
60  std::vector<General_path_element_t> path_elements;
61  std::set<int64_t> set_source_vertices;
62  std::set<int64_t> set_sink_vertices;
63  for (size_t i = 0; i < size_source_verticesArr; ++i) {
64  set_source_vertices.insert(source_vertices[i]);
65  }
66  for (size_t i = 0; i < size_sink_verticesArr; ++i) {
67  set_sink_vertices.insert(sink_vertices[i]);
68  }
69 
71 
72  /*
73  * boykov_kolmogorov is only for directed graphs
74  */
75 
76  G.create_edge_disjoint_paths_graph(data_edges, total_edges,
77  set_source_vertices,
78  set_sink_vertices, directed);
79  auto flow = G.boykov_kolmogorov();
80  G.get_edge_disjoint_paths(path_elements, flow);
81 
82  (*return_tuples) = pgr_alloc(path_elements.size(), (*return_tuples));
83  for (size_t i = 0; i < path_elements.size(); ++i) {
84  (*return_tuples)[i] = path_elements[i];
85  }
86  *return_count = path_elements.size();
87 
88 
89  *log_msg = log.str().empty()?
90  *log_msg :
91  pgr_msg(log.str().c_str());
92  *notice_msg = notice.str().empty()?
93  *notice_msg :
94  pgr_msg(notice.str().c_str());
95  } catch (AssertFailedException &except) {
96  (*return_tuples) = pgr_free(*return_tuples);
97  (*return_count) = 0;
98  err << except.what();
99  *err_msg = pgr_msg(err.str().c_str());
100  *log_msg = pgr_msg(log.str().c_str());
101  } catch (std::exception &except) {
102  (*return_tuples) = pgr_free(*return_tuples);
103  (*return_count) = 0;
104  err << except.what();
105  *err_msg = pgr_msg(err.str().c_str());
106  *log_msg = pgr_msg(log.str().c_str());
107  } catch(...) {
108  (*return_tuples) = pgr_free(*return_tuples);
109  (*return_count) = 0;
110  err << "Caught unknown exception!";
111  *err_msg = pgr_msg(err.str().c_str());
112  *log_msg = pgr_msg(log.str().c_str());
113  }
114 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
void do_pgr_edge_disjoint_paths(pgr_basic_edge_t *data_edges, size_t total_edges, 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)
void get_edge_disjoint_paths(std::vector< General_path_element_t > &path_elements, int64_t flow)
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:73
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:62
void create_edge_disjoint_paths_graph(pgr_basic_edge_t *data_edges, size_t total_tuples, const std::set< int64_t > &source_vertices, const std::set< int64_t > &sink_vertices, bool directed)
virtual const char * what() const
Definition: pgr_assert.cpp:53
char * err_msg
Definition: BDATester.cpp:50