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_one_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: edge_disjoint_paths_one_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 #include <sstream>
36 #include <vector>
37 #include <set>
38 
41 #include "../../common/src/pgr_alloc.hpp"
42 
43 // #define DEBUG
44 extern "C" {
45 #include "./../../common/src/pgr_types.h"
46 }
47 
48 void
50  pgr_basic_edge_t *data_edges,
51  size_t total_tuples,
52  int64_t source_vertex,
53  int64_t sink_vertex,
54  bool directed,
55  General_path_element_t **return_tuples,
56  size_t *return_count,
57  char **err_msg) {
58  std::ostringstream log;
59 
60  try {
61  std::vector<General_path_element_t> path_elements;
62  std::set<int64_t> set_source_vertices;
63  set_source_vertices.insert(source_vertex);
64  std::set<int64_t> set_sink_vertices;
65  set_sink_vertices.insert(sink_vertex);
67 
68  // I use a directed graph since I'm dependent on directed graphs
69 
70  G.create_edge_disjoint_paths_graph(data_edges, total_tuples,
71  set_source_vertices,
72  set_sink_vertices, directed);
73  int64_t flow = G.boykov_kolmogorov();
74  G.get_edge_disjoint_paths(path_elements, flow);
75 
76  (*return_tuples) = pgr_alloc(path_elements.size(), (*return_tuples));
77  for (size_t i = 0; i < path_elements.size(); ++i) {
78  (*return_tuples)[i] = path_elements[i];
79  }
80  *return_count = path_elements.size();
81 
82 #ifndef DEBUG
83  *err_msg = strdup("OK");
84 #else
85  *err_msg = strdup(log.str().c_str());
86 #endif
87 
88  return;
89  } catch (...) {
90  log << "Caught unknown exception!\n";
91  *err_msg = strdup(log.str().c_str());
92  return;
93  }
94 }
95 
96 
97 
98 
99 
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)
void do_pgr_edge_disjoint_paths_one_to_one(pgr_basic_edge_t *data_edges, size_t total_tuples, int64_t source_vertex, int64_t sink_vertex, bool directed, General_path_element_t **return_tuples, size_t *return_count, char **err_msg)
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:52
char * err_msg
Definition: BDATester.cpp:50