PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
drivedist_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: boost_interface_drivedist.cpp
3 
4 Copyright (c) 2015 Celia Virginia Vergara Castillo
5 vicky_vergara@hotmail.com
6 
7 ------
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13 
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 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 
23  ********************************************************************PGR-GNU*/
24 
25 #include "./drivedist_driver.h"
26 
27 #include <sstream>
28 #include <deque>
29 #include <vector>
30 
31 #include "./../../dijkstra/src/pgr_dijkstra.hpp"
32 
33 #include "../../common/src/pgr_alloc.hpp"
34 #include "./../../common/src/pgr_assert.h"
35 #include "./../../common/src/pgr_types.h"
36 
37 
38 
39 
40 void
42  pgr_edge_t *data_edges, size_t total_edges,
43  int64_t *start_vertex, size_t s_len,
44  double distance,
45  bool directedFlag,
46  bool equiCostFlag,
47  General_path_element_t **return_tuples, size_t *return_count,
48  char **log_msg,
49  char **notice_msg,
50  char **err_msg) {
51  std::ostringstream log;
52  std::ostringstream err;
53  std::ostringstream notice;
54 
55  try {
56  pgassert(total_edges != 0);
57  pgassert(!(*log_msg));
58  pgassert(!(*notice_msg));
59  pgassert(!(*err_msg));
60  pgassert(!(*return_tuples));
61  pgassert(*return_count == 0);
62  pgassert((*return_tuples) == NULL);
63 
64  graphType gType = directedFlag? DIRECTED: UNDIRECTED;
65 
66  std::deque<Path> paths;
67  std::vector<int64_t> start_vertices(start_vertex, start_vertex + s_len);
68 
69  if (directedFlag) {
70  pgrouting::DirectedGraph digraph(gType);
71  digraph.insert_edges(data_edges, total_edges);
72  paths = pgr_drivingDistance(
73  digraph, start_vertices, distance, equiCostFlag);
74  } else {
75  pgrouting::UndirectedGraph undigraph(gType);
76  undigraph.insert_edges(data_edges, total_edges);
77  paths = pgr_drivingDistance(
78  undigraph, start_vertices, distance, equiCostFlag);
79  }
80 
81  size_t count(count_tuples(paths));
82 
83 
84  if (count == 0) {
85  *notice_msg = pgr_msg("No return values was found");
86  return;
87  }
88  *return_tuples = pgr_alloc(count, (*return_tuples));
89  auto trueCount(collapse_paths(return_tuples, paths));
90  *return_count = trueCount;
91 
92 
93  *log_msg = log.str().empty()?
94  *log_msg :
95  pgr_msg(log.str().c_str());
96  *notice_msg = notice.str().empty()?
97  *notice_msg :
98  pgr_msg(notice.str().c_str());
99  } catch (AssertFailedException &except) {
100  (*return_tuples) = pgr_free(*return_tuples);
101  (*return_count) = 0;
102  err << except.what();
103  *err_msg = pgr_msg(err.str().c_str());
104  *log_msg = pgr_msg(log.str().c_str());
105  } catch (std::exception &except) {
106  (*return_tuples) = pgr_free(*return_tuples);
107  (*return_count) = 0;
108  err << except.what();
109  *err_msg = pgr_msg(err.str().c_str());
110  *log_msg = pgr_msg(log.str().c_str());
111  } catch(...) {
112  (*return_tuples) = pgr_free(*return_tuples);
113  (*return_count) = 0;
114  err << "Caught unknown exception!";
115  *err_msg = pgr_msg(err.str().c_str());
116  *log_msg = pgr_msg(log.str().c_str());
117  }
118 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
void insert_edges(const T *edges, int64_t count)
Inserts count edges of type T into the graph.
std::deque< Path > pgr_drivingDistance(G &graph, std::vector< int64_t > start_vids, double distance, bool equicost)
void do_pgr_driving_many_to_dist(pgr_edge_t *data_edges, size_t total_edges, int64_t *start_vertex, size_t s_len, double distance, bool directedFlag, bool equiCostFlag, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:73
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
graphType
Definition: pgr_types.h:222
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