PGROUTING  3.2
transitiveClosure_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: transitiveClosure_driver.cpp
3 Generated with Template by:
4 Copyright (c) 2015 pgRouting developers
6 Function's developer:
7 Copyright (c) 2019 Hang Wu
9 ------
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  ********************************************************************PGR-GNU*/
22 
24 
25 #include <string.h>
26 #include <sstream>
27 #include <deque>
28 #include <vector>
29 #include <algorithm>
30 
32 
34 #include "cpp_common/pgr_alloc.hpp"
37 
38 
39 
40 template < class G >
41 static
42 boost::adjacency_list <>
44  G &graph) {
45  Pgr_transitiveClosure< G > fn_transitiveClosure;
46  return fn_transitiveClosure.transitiveClosure(graph);
47 }
48 
49 
50 template <typename G>
51 static
53  G &graph,
54  transitiveClosure_rt **return_tuples,
55  size_t *count) {
56  boost::adjacency_list <> TC;
57  TC = pgr_transitiveClosure(graph);
58  (*count) = boost::num_vertices(TC);
59  (*return_tuples) = pgr_alloc((*count), (*return_tuples));
60  size_t sequence = 0;
61  boost::graph_traits < boost::adjacency_list <> >::vertex_iterator i, end;
62  boost::graph_traits < boost::adjacency_list <> >::adjacency_iterator ai, a_end;
63  int ii = 1;
64  for (boost::tie(i, end) = boost::vertices(TC); i != end; ++i) {
65  auto u = *i;
66  int64_t* target_array = nullptr;
67  auto uid = graph.graph[u].id;
68  boost::tie(ai, a_end) = adjacent_vertices(u, TC);
69  size_t adj_siz = static_cast<size_t>(a_end - ai);
70  target_array = pgr_alloc(adj_siz , target_array);
71  int number = 0;
72  for (; ai != a_end; ++ai) {
73  auto v = *ai;
74  int64_t vid = graph.graph[v].id;
75  target_array[number++] = vid;
76  }
77 
78  (*return_tuples)[sequence] = {
79  ii++,
80  uid,
81  target_array,
82  number};
83 
84  ++sequence;
85  }
86 }
87 
88 
89 
90 /************************************************************
91  edges_sql TEXT
92  ***********************************************************/
93 void
95  pgr_edge_t *data_edges,
96  size_t total_edges,
97  transitiveClosure_rt **return_tuples,
98  size_t *return_count,
99  char **log_msg,
100  char **notice_msg,
101  char **err_msg) {
102  std::ostringstream log;
103  std::ostringstream notice;
104  std::ostringstream err;
105  try {
106  pgassert(total_edges != 0);
107  pgassert(!(*log_msg));
108  pgassert(!(*notice_msg));
109  pgassert(!(*err_msg));
110  pgassert(!(*return_tuples));
111  pgassert(*return_count == 0);
112 
113  /*
114  * Converting to C++ structures
115  */
116  std::vector<pgr_edge_t> edges(data_edges, data_edges + total_edges);
117 
118 
119  graphType gType = DIRECTED;
120  pgrouting::DirectedGraph digraph(gType);
121  digraph.insert_edges(data_edges, total_edges);
122 
124  digraph,
125  return_tuples,
126  return_count);
127 
128  *log_msg = log.str().empty()?
129  *log_msg :
130  pgr_msg(log.str().c_str());
131  *notice_msg = notice.str().empty()?
132  *notice_msg :
133  pgr_msg(notice.str().c_str());
134  } catch (AssertFailedException &except) {
135  (*return_tuples) = pgr_free(*return_tuples);
136  (*return_count) = 0;
137  err << except.what();
138  *err_msg = pgr_msg(err.str().c_str());
139  *log_msg = pgr_msg(log.str().c_str());
140  } catch (std::exception &except) {
141  (*return_tuples) = pgr_free(*return_tuples);
142  (*return_count) = 0;
143  err << except.what();
144  *err_msg = pgr_msg(err.str().c_str());
145  *log_msg = pgr_msg(log.str().c_str());
146  } catch(...) {
147  (*return_tuples) = pgr_free(*return_tuples);
148  (*return_count) = 0;
149  err << "Caught unknown exception!";
150  *err_msg = pgr_msg(err.str().c_str());
151  *log_msg = pgr_msg(log.str().c_str());
152  }
153 }
pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
pgr_base_graph.hpp
pgr_edge_t
Definition: pgr_edge_t.h:37
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
get_postgres_result
static void get_postgres_result(G &graph, transitiveClosure_rt **return_tuples, size_t *count)
Definition: transitiveClosure_driver.cpp:52
pgr_transitiveClosure
static boost::adjacency_list pgr_transitiveClosure(G &graph)
Definition: transitiveClosure_driver.cpp:43
transitiveClosure_rt
Definition: transitiveClosure_rt.h:44
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgrouting::graph::Pgr_base_graph::insert_edges
void insert_edges(const T *edges, size_t count)
Inserts count edges of type T into the graph.
Definition: pgr_base_graph.hpp:357
pgr_alloc.hpp
transitiveClosure_driver.h
graphType
graphType
Definition: graph_enum.h:30
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
Pgr_transitiveClosure
Definition: pgr_transitiveClosure.hpp:43
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
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
Pgr_transitiveClosure::transitiveClosure
boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, boost::no_property, boost::no_property, boost::no_property, boost::listS > transitiveClosure(G &graph)
Definition: pgr_transitiveClosure.hpp:67
pgr_transitiveClosure.hpp
do_pgr_transitiveClosure
void do_pgr_transitiveClosure(pgr_edge_t *data_edges, size_t total_edges, transitiveClosure_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: transitiveClosure_driver.cpp:94
identifiers.hpp
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139
basePath_SSEC.hpp