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_one_to_many_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: edge_disjoint_paths_one_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 
50 void
52  pgr_basic_edge_t *data_edges,
53  size_t total_tuples,
54  int64_t source_vertex,
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  set_source_vertices.insert(source_vertex);
67  std::set<int64_t> set_sink_vertices;
68  for (size_t i = 0; i < size_sink_verticesArr; ++i) {
69  set_sink_vertices.insert(sink_vertices[i]);
70  }
72 
73  // I use a directed graph since I'm dependent on directed graphs
74 
75  G.create_edge_disjoint_paths_graph(data_edges, total_tuples,
76  set_source_vertices,
77  set_sink_vertices, directed);
78  int64_t flow = G.boykov_kolmogorov();
79  G.get_edge_disjoint_paths(path_elements, flow);
80 
81  (*return_tuples) = pgr_alloc(path_elements.size(), (*return_tuples));
82  for (size_t i = 0; i < path_elements.size(); ++i) {
83  (*return_tuples)[i] = path_elements[i];
84  }
85  *return_count = path_elements.size();
86 
87 #ifndef DEBUG
88  *err_msg = strdup("OK");
89 #else
90  *err_msg = strdup(log.str().c_str());
91 #endif
92 
93  return;
94  } catch (...) {
95  log << "Caught unknown exception!\n";
96  *err_msg = strdup(log.str().c_str());
97  return;
98  }
99 }
100 
101 
102 
103 
104 
void do_pgr_edge_disjoint_paths_one_to_many(pgr_basic_edge_t *data_edges, size_t total_tuples, int64_t source_vertex, 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 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 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