pgRouting
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
edge_disjoint_paths_many_to_many_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 
30 #if defined(__MINGW32__) || defined(_MSC_VER)
31 #include <winsock2.h>
32 #include <windows.h>
33 #endif
34 
35 
36 #include <sstream>
37 #include <vector>
38 #include <set>
39 
42 #include "../../common/src/pgr_alloc.hpp"
43 
44 // #define DEBUG
45 extern "C" {
46 #include "./../../common/src/pgr_types.h"
47 }
48 
49 void
51  pgr_basic_edge_t *data_edges,
52  size_t total_tuples,
53  int64_t *source_vertices,
54  size_t size_source_verticesArr,
55  int64_t *sink_vertices,
56  size_t size_sink_verticesArr,
57  bool directed,
58  General_path_element_t **return_tuples,
59  size_t *return_count,
60  char **err_msg) {
61  std::ostringstream log;
62 
63  try {
64  std::vector<General_path_element_t> path_elements;
65  std::set<int64_t> set_source_vertices;
66  std::set<int64_t> set_sink_vertices;
67  for (size_t i = 0; i < size_source_verticesArr; ++i) {
68  set_source_vertices.insert(source_vertices[i]);
69  }
70  for (size_t i = 0; i < size_sink_verticesArr; ++i) {
71  set_sink_vertices.insert(sink_vertices[i]);
72  }
74 
75  // I use a directed graph since I'm dependent on directed graphs
76 
77  G.create_edge_disjoint_paths_graph(data_edges, total_tuples,
78  set_source_vertices,
79  set_sink_vertices, directed);
80  int64_t flow = G.boykov_kolmogorov();
81  G.get_edge_disjoint_paths(path_elements, flow);
82 
83  (*return_tuples) = pgr_alloc(path_elements.size(), (*return_tuples));
84  for (size_t i = 0; i < path_elements.size(); ++i) {
85  (*return_tuples)[i] = path_elements[i];
86  }
87  *return_count = path_elements.size();
88 
89 #ifndef DEBUG
90  *err_msg = strdup("OK");
91 #else
92  *err_msg = strdup(log.str().c_str());
93 #endif
94 
95  return;
96  } catch (...) {
97  log << "Caught unknown exception!\n";
98  *err_msg = strdup(log.str().c_str());
99  return;
100  }
101 }
102 
103 
104 
105 
106 
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)
void do_pgr_edge_disjoint_paths_many_to_many(pgr_basic_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 **err_msg)
void get_edge_disjoint_paths(std::vector< General_path_element_t > &path_elements, int64_t flow)
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:52
char * err_msg
Definition: BDATester.cpp:50