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
max_flow_one_to_one_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: max_flow_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 
36 #include <sstream>
37 #include <vector>
38 #include <set>
39 
40 #include "./pgr_maxflow.hpp"
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_edge_t *data_edges,
52  size_t total_tuples,
53  int64_t source_vertex,
54  int64_t sink_vertex,
55  char *algorithm,
56  pgr_flow_t **return_tuples,
57  size_t *return_count,
58  char **err_msg) {
59  std::ostringstream log;
60 
61  try {
63  std::set<int64_t> set_source_vertices;
64  set_source_vertices.insert(source_vertex);
65  std::set<int64_t> set_sink_vertices;
66  set_sink_vertices.insert(sink_vertex);
67 
68  G.create_flow_graph(data_edges,
69  total_tuples,
70  set_source_vertices,
71  set_sink_vertices,
72  algorithm);
73 
74  if (strcmp(algorithm, "push_relabel") == 0) {
75  G.push_relabel();
76  } else if (strcmp(algorithm, "edmonds_karp") == 0) {
77  G.edmonds_karp();
78  } else if (strcmp(algorithm, "boykov_kolmogorov") == 0) {
80  } else {
81  log << "Unspecified algorithm!\n";
82  (*return_tuples) = NULL;
83  (*return_count) = 0;
84  *err_msg = strdup(log.str().c_str());
85  return;
86  }
87 
88  std::vector<pgr_flow_t> flow_edges;
89  G.get_flow_edges(flow_edges);
90 
91  (*return_tuples) = pgr_alloc(flow_edges.size(), (*return_tuples));
92  for (size_t i = 0; i < flow_edges.size(); ++i) {
93  (*return_tuples)[i] = flow_edges[i];
94  }
95  *return_count = flow_edges.size();
96 
97 #ifndef DEBUG
98  *err_msg = strdup("OK");
99 #else
100  *err_msg = strdup(log.str().c_str());
101 #endif
102 
103  return;
104  } catch (...) {
105  log << "Caught unknown exception!\n";
106  *err_msg = strdup(log.str().c_str());
107  return;
108  }
109 }
110 
111 
112 
113 
114 
void create_flow_graph(pgr_edge_t *data_edges, size_t total_tuples, const std::set< int64_t > &source_vertices, const std::set< int64_t > &sink_vertices, char *algorithm)
int64_t push_relabel()
int64_t edmonds_karp()
void do_pgr_max_flow_one_to_one(pgr_edge_t *data_edges, size_t total_tuples, int64_t source_vertex, int64_t sink_vertex, char *algorithm, pgr_flow_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
void get_flow_edges(std::vector< pgr_flow_t > &flow_edges)
int64_t boykov_kolmogorov()