PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
maximum_cardinality_matching_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: maximum_cardinality_matching_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 
31 
32 #include <sstream>
33 #include <vector>
34 
36 
37 #include "./../../common/src/pgr_alloc.hpp"
38 #include "../../common/src/pgr_assert.h"
39 #include "./../../common/src/pgr_types.h"
40 
41 
42 void
44  pgr_basic_edge_t *data_edges,
45  size_t total_tuples,
46  bool directed,
47 
48  pgr_basic_edge_t **return_tuples,
49  size_t *return_count,
50 
51  char** log_msg,
52  char** notice_msg,
53  char **err_msg) {
54  std::ostringstream log;
55  std::ostringstream notice;
56  std::ostringstream err;
57 
58  try {
59  std::vector<pgr_basic_edge_t> matched_vertices;
60 
61  if (directed) {
64  G.create_max_cardinality_graph(data_edges, total_tuples);
65  std::vector<int64_t> mate_map(boost::num_vertices(G.boost_graph));
66  G.maximum_cardinality_matching(mate_map);
67  G.get_matched_vertices(matched_vertices, mate_map);
68  } else {
71  G.create_max_cardinality_graph(data_edges, total_tuples);
72  std::vector<int64_t> mate_map(boost::num_vertices(G.boost_graph));
73  G.maximum_cardinality_matching(mate_map);
74  G.get_matched_vertices(matched_vertices, mate_map);
75  }
76 
77  (*return_tuples) = pgr_alloc(matched_vertices.size(), (*return_tuples));
78  for (size_t i = 0; i < matched_vertices.size(); ++i) {
79  (*return_tuples)[i] = matched_vertices[i];
80  }
81  *return_count = matched_vertices.size();
82 
83  *log_msg = log.str().empty()?
84  *log_msg :
85  pgr_msg(log.str().c_str());
86  *notice_msg = notice.str().empty()?
87  *notice_msg :
88  pgr_msg(notice.str().c_str());
89  } catch (AssertFailedException &except) {
90  (*return_tuples) = pgr_free(*return_tuples);
91  (*return_count) = 0;
92  err << except.what();
93  *err_msg = pgr_msg(err.str().c_str());
94  *log_msg = pgr_msg(log.str().c_str());
95  } catch (std::exception &except) {
96  (*return_tuples) = pgr_free(*return_tuples);
97  (*return_count) = 0;
98  err << except.what();
99  *err_msg = pgr_msg(err.str().c_str());
100  *log_msg = pgr_msg(log.str().c_str());
101  } catch(...) {
102  (*return_tuples) = pgr_free(*return_tuples);
103  (*return_count) = 0;
104  err << "Caught unknown exception!";
105  *err_msg = pgr_msg(err.str().c_str());
106  *log_msg = pgr_msg(log.str().c_str());
107  }
108 }
109 
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
void do_pgr_maximum_cardinality_matching(pgr_basic_edge_t *data_edges, size_t total_tuples, bool directed, pgr_basic_edge_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
boost::adjacency_list< boost::listS, boost::vecS, boost::directedS > BasicDirectedGraph
boost::adjacency_list< boost::listS, boost::vecS, boost::undirectedS > BasicUndirectedGraph
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:73
void create_max_cardinality_graph(pgr_basic_edge_t *data_edges, size_t total_tuples)
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:29
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:62
virtual const char * what() const
Definition: pgr_assert.cpp:53
char * err_msg
Definition: BDATester.cpp:50