PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
biconnectedComponents_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: biconnectedComponents_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) 2017 Celia Virginia Vergara Castillo
10 Mail: vicky_vergara@hotmail.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 <deque>
34 #include <vector>
35 
37 
38 #include "cpp_common/pgr_alloc.hpp"
39 #include "cpp_common/pgr_assert.h"
40 
41 
42 
43 
44 
45 /************************************************************
46  TEXT,
47  BIGINT,
48  BIGINT,
49  ***********************************************************/
50 
51 template < class G >
52 static
53 std::vector<pgr_components_rt>
55  G &graph) {
56  std::vector<pgr_components_rt> results;
57  Pgr_components< G > fn_components;
58  return fn_components.biconnectedComponents(graph);
59 }
60 
61 
62 void
64  pgr_edge_t *data_edges,
65  size_t total_edges,
66  pgr_components_rt **return_tuples,
67  size_t *return_count,
68  char ** log_msg,
69  char ** notice_msg,
70  char ** err_msg) {
71  std::ostringstream log;
72  std::ostringstream err;
73  std::ostringstream notice;
74  try {
75  pgassert(!(*log_msg));
76  pgassert(!(*notice_msg));
77  pgassert(!(*err_msg));
78  pgassert(!(*return_tuples));
79  pgassert(*return_count == 0);
80  pgassert(total_edges != 0);
81 
82  graphType gType = DIRECTED;
83 
84  std::vector<pgr_components_rt> results;
85 
86  log << "Working with Undirected Graph\n";
87  pgrouting::ComponentsUndiGraph undigraph(gType);
88  undigraph.insert_edges(data_edges, total_edges);
89  results = pgr_biconnectedComponents(
90  undigraph);
91 
92  auto count = results.size();
93 
94  if (count == 0) {
95  (*return_tuples) = NULL;
96  (*return_count) = 0;
97  notice <<
98  "No paths found between start_vid and end_vid vertices";
99  return;
100  }
101 
102  (*return_tuples) = pgr_alloc(count, (*return_tuples));
103  for (size_t i = 0; i < count; i++) {
104  *((*return_tuples) + i) = results[i];
105  }
106  (*return_count) = count;
107 
108  pgassert(*err_msg == NULL);
109  *log_msg = log.str().empty()?
110  *log_msg :
111  pgr_msg(log.str().c_str());
112  *notice_msg = notice.str().empty()?
113  *notice_msg :
114  pgr_msg(notice.str().c_str());
115  } catch (AssertFailedException &except) {
116  (*return_tuples) = pgr_free(*return_tuples);
117  (*return_count) = 0;
118  err << except.what();
119  *err_msg = pgr_msg(err.str().c_str());
120  *log_msg = pgr_msg(log.str().c_str());
121  } catch (std::exception &except) {
122  (*return_tuples) = pgr_free(*return_tuples);
123  (*return_count) = 0;
124  err << except.what();
125  *err_msg = pgr_msg(err.str().c_str());
126  *log_msg = pgr_msg(log.str().c_str());
127  } catch(...) {
128  (*return_tuples) = pgr_free(*return_tuples);
129  (*return_count) = 0;
130  err << "Caught unknown exception!";
131  *err_msg = pgr_msg(err.str().c_str());
132  *log_msg = pgr_msg(log.str().c_str());
133  }
134 }
135 
std::vector< pgr_components_rt > biconnectedComponents(G &graph)
Biconnected Components.
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:75
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
static std::vector< pgr_components_rt > pgr_biconnectedComponents(G &graph)
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:64
Assertions Handling.
virtual const char * what() const
Definition: pgr_assert.cpp:53
void do_pgr_biconnectedComponents(pgr_edge_t *data_edges, size_t total_edges, pgr_components_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
graphType
Definition: graph_enum.h:30
void insert_edges(const T *edges, int64_t count)