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_many_to_one_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: max_flow_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 
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_vertices,
54  size_t size_source_verticesArr,
55  int64_t sink_vertex,
56  char *algorithm,
57  pgr_flow_t **return_tuples,
58  size_t *return_count,
59  char **err_msg) {
60  std::ostringstream log;
61 
62  try {
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);
70 
71  G.create_flow_graph(data_edges,
72  total_tuples,
73  set_source_vertices,
74  set_sink_vertices,
75  algorithm);
76 
77  if (strcmp(algorithm, "push_relabel") == 0) {
78  G.push_relabel();
79  } else if (strcmp(algorithm, "edmonds_karp") == 0) {
80  G.edmonds_karp();
81  } else if (strcmp(algorithm, "boykov_kolmogorov") == 0) {
83  } else {
84  log << "Unspecified algorithm!\n";
85  (*return_tuples) = NULL;
86  (*return_count) = 0;
87  *err_msg = strdup(log.str().c_str());
88  return;
89  }
90 
91  std::vector<pgr_flow_t> flow_edges;
92  G.get_flow_edges(flow_edges);
93 
94  (*return_tuples) = pgr_alloc(flow_edges.size(), (*return_tuples));
95  for (size_t i = 0; i < flow_edges.size(); ++i) {
96  (*return_tuples)[i] = flow_edges[i];
97  }
98  *return_count = flow_edges.size();
99 
100 #ifndef DEBUG
101  *err_msg = strdup("OK");
102 #else
103  *err_msg = strdup(log.str().c_str());
104 #endif
105 
106  return;
107  } catch (...) {
108  log << "Caught unknown exception!\n";
109  *err_msg = strdup(log.str().c_str());
110  return;
111  }
112 }
113 
114 
115 
116 
117 
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()
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:52
void do_pgr_max_flow_many_to_one(pgr_edge_t *data_edges, size_t total_tuples, int64_t *source_vertices, size_t size_source_verticesArr, int64_t sink_vertex, char *algorithm, pgr_flow_t **return_tuples, size_t *return_count, char **err_msg)
char * err_msg
Definition: BDATester.cpp:50
void get_flow_edges(std::vector< pgr_flow_t > &flow_edges)
int64_t boykov_kolmogorov()