PGROUTING  3.2
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
7 
8 Function's developer:
9 Copyright (c) 2016 Andrea Nardelli
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 "cpp_common/pgr_alloc.hpp"
38 #include "cpp_common/pgr_assert.h"
39 
40 
41 void
43  pgr_basic_edge_t *data_edges,
44  size_t total_tuples,
45  bool directed,
46 
47  pgr_basic_edge_t **return_tuples,
48  size_t *return_count,
49 
50  char** log_msg,
51  char** notice_msg,
52  char **err_msg) {
53  std::ostringstream log;
54  std::ostringstream notice;
55  std::ostringstream err;
56 
57  try {
58  std::vector<pgr_basic_edge_t> matched_vertices;
59 
60  if (directed) {
62  matched_vertices = G.get_matched_vertices();
63  } else {
65  matched_vertices = G.get_matched_vertices();
66  }
67 
68  (*return_tuples) = pgr_alloc(matched_vertices.size(), (*return_tuples));
69  for (size_t i = 0; i < matched_vertices.size(); ++i) {
70  (*return_tuples)[i] = matched_vertices[i];
71  }
72  *return_count = matched_vertices.size();
73 
74  *log_msg = log.str().empty()?
75  *log_msg :
76  pgr_msg(log.str().c_str());
77  *notice_msg = notice.str().empty()?
78  *notice_msg :
79  pgr_msg(notice.str().c_str());
80  } catch (AssertFailedException &except) {
81  (*return_tuples) = pgr_free(*return_tuples);
82  (*return_count) = 0;
83  err << except.what();
84  *err_msg = pgr_msg(err.str().c_str());
85  *log_msg = pgr_msg(log.str().c_str());
86  } catch (std::exception &except) {
87  (*return_tuples) = pgr_free(*return_tuples);
88  (*return_count) = 0;
89  err << except.what();
90  *err_msg = pgr_msg(err.str().c_str());
91  *log_msg = pgr_msg(log.str().c_str());
92  } catch(...) {
93  (*return_tuples) = pgr_free(*return_tuples);
94  (*return_count) = 0;
95  err << "Caught unknown exception!";
96  *err_msg = pgr_msg(err.str().c_str());
97  *log_msg = pgr_msg(log.str().c_str());
98  }
99 }
100 
pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
pgr_msg
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
AssertFailedException::what
virtual const char * what() const
Definition: pgr_assert.cpp:67
pgr_alloc.hpp
do_pgr_maximum_cardinality_matching
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)
Definition: maximum_cardinality_matching_driver.cpp:42
pgr_maximumcardinalitymatching.hpp
pgr_assert.h
An assert functionality that uses C++ throw().
pgr_basic_edge_t
Definition: pgr_basic_edge_t.h:38
pgrouting::flow::PgrCardinalityGraph
Definition: pgr_maximumcardinalitymatching.hpp:55
pgrouting::alphashape::G
graph::Pgr_base_graph< BG, XY_vertex, Basic_edge > G
Definition: pgr_alphaShape.h:56
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
maximum_cardinality_matching_driver.h
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139