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_one_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: edge_disjoint_paths_many_to_one_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_vertex,
56  bool directed,
57  General_path_element_t **return_tuples,
58  size_t *return_count,
59  char **err_msg) {
60  std::ostringstream log;
61 
62  try {
63  std::vector<General_path_element_t> path_elements;
64  std::set<int64_t> set_source_vertices;
65  std::set<int64_t> set_sink_vertices;
66  for (size_t i = 0; i < size_source_verticesArr; ++i) {
67  set_source_vertices.insert(source_vertices[i]);
68  }
69  set_sink_vertices.insert(sink_vertex);
71 
72  // I use a directed graph since I'm dependent on directed graphs
73 
74  G.create_edge_disjoint_paths_graph(data_edges, total_tuples,
75  set_source_vertices,
76  set_sink_vertices, directed);
77  int64_t flow = G.boykov_kolmogorov();
78  G.get_edge_disjoint_paths(path_elements, flow);
79 
80  (*return_tuples) = pgr_alloc(path_elements.size(), (*return_tuples));
81  for (size_t i = 0; i < path_elements.size(); ++i) {
82  (*return_tuples)[i] = path_elements[i];
83  }
84  *return_count = path_elements.size();
85 
86 #ifndef DEBUG
87  *err_msg = strdup("OK");
88 #else
89  *err_msg = strdup(log.str().c_str());
90 #endif
91 
92  return;
93  } catch (...) {
94  log << "Caught unknown exception!\n";
95  *err_msg = strdup(log.str().c_str());
96  return;
97  }
98 }
99 
100 
101 
102 
103 
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
void do_pgr_edge_disjoint_paths_many_to_one(pgr_basic_edge_t *data_edges, size_t total_tuples, int64_t *source_vertices, size_t size_source_verticesArr, int64_t sink_vertex, bool directed, General_path_element_t **return_tuples, size_t *return_count, char **err_msg)