pgRouting
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
boost_interface_drivedist.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 #if defined(__MINGW32__) || defined(_MSC_VER)
26 #include <winsock2.h>
27 #include <windows.h>
28 #ifdef open
29 #undef open
30 #endif
31 #endif
32 
34 #include <sstream>
35 #include <deque>
36 #include <vector>
37 #include <set>
38 
39 #include "./../../common/src/pgr_types.h"
40 #include "../../common/src/pgr_alloc.hpp"
41 #include "./../../dijkstra/src/pgr_dijkstra.hpp"
42 
43 
44 
45 
46 void
48  pgr_edge_t *data_edges, size_t total_tuples,
49  int64_t *start_vertex, size_t s_len,
50  double distance,
51  bool directedFlag,
52  bool equiCostFlag,
53  General_path_element_t **ret_path, size_t *path_count,
54  char ** err_msg) {
55  try {
56  *ret_path = NULL;
57  *path_count = 0;
58 
59  graphType gType = directedFlag? DIRECTED: UNDIRECTED;
60 
61  std::deque< Path >paths;
62  std::set< int64_t > s_start_vertices(start_vertex, start_vertex + s_len);
63  std::vector< int64_t > start_vertices(s_start_vertices.begin(), s_start_vertices.end());
64 
65  if (directedFlag) {
66  pgrouting::DirectedGraph digraph(gType);
67  digraph.graph_insert_data(data_edges, total_tuples);
68  pgr_drivingDistance(digraph, paths, start_vertices, distance, equiCostFlag);
69  } else {
70  pgrouting::UndirectedGraph undigraph(gType);
71  undigraph.graph_insert_data(data_edges, total_tuples);
72  pgr_drivingDistance(undigraph, paths, start_vertices, distance, equiCostFlag);
73  }
74 
75  size_t count(count_tuples(paths));
76 
77 
78  if (count == 0) {
79  *err_msg = strdup("NOTICE: No return values was found");
80  return;
81  }
82  *ret_path = pgr_alloc(count, (*ret_path));
83  auto trueCount(collapse_paths(ret_path, paths));
84  *path_count = trueCount;
85 
86 
87 #ifndef DEBUG
88  *err_msg = strdup("OK");
89 #else
90  *err_msg = strdup(log.str().c_str());
91 #endif
92  return;
93  } catch ( ... ) {
94  *err_msg = strdup("Caught unknown exception!");
95  if (ret_path) free(ret_path);
96  *path_count = 0;
97  return;
98  }
99 }
100 
101 
102 
103 
104 void
106  pgr_edge_t *data_edges, size_t total_edges,
107  int64_t start_vertex,
108  double distance,
109  bool directedFlag,
110  General_path_element_t **ret_path, size_t *path_count,
111  char **err_msg) {
112  std::ostringstream log;
113  try {
114  // if it already has values there will be a leak
115  // call with pointing to NULL
116  *ret_path = NULL;
117  *path_count = 0;
118 
119  log << "NOTICE: Started processing pgr_drivingDistance for 1 start_vid\n";
120  // in c code this should have been checked:
121  // 1) start_vertex is in the data_edges DONE
122 
123  graphType gType = directedFlag? DIRECTED: UNDIRECTED;
124 
125  Path path;
126 
127 
128  if (directedFlag) {
129  log << "NOTICE: Processing Directed graph\n";
130  pgrouting::DirectedGraph digraph(gType);
131  digraph.graph_insert_data(data_edges, total_edges);
132  pgr_drivingDistance(digraph, path, start_vertex, distance);
133  } else {
134  log << "NOTICE: Processing Undirected graph\n";
135  pgrouting::UndirectedGraph undigraph(gType);
136  undigraph.graph_insert_data(data_edges, total_edges);
137  pgr_drivingDistance(undigraph, path, start_vertex, distance);
138  }
139 
140  log << "Returning number of tuples" << path.size() << "\n";
141  if (path.empty()) {
142  log << "NOTICE: it should have at least the one for it self";
143  *err_msg = strdup(log.str().c_str());
144  return;
145  }
146 
147  log << "NOTICE: Calculating the number of tuples \n";
148  auto count = path.size();
149 
150  log << "NOTICE Count: " << count << " tuples\n";
151 
152  *ret_path = pgr_alloc(count, (*ret_path));
153 
154  size_t sequence = 0;
155  path.get_pg_dd_path(ret_path, sequence);
156  *path_count = count;
157 
158 #ifndef DEBUG
159  *err_msg = strdup("OK");
160 #else
161  *err_msg = strdup(log.str().c_str());
162 #endif
163 
164  return;
165  } catch ( ... ) {
166  log << "NOTICE: unknown exception cought";
167  *err_msg = strdup(log.str().c_str());
168  if (ret_path) free(ret_path);
169  *path_count = 0;
170  return;
171  }
172 }
173 
int path_count
Definition: BDATester.cpp:51
void get_pg_dd_path(General_path_element_t **ret_path, size_t &sequence) const
void do_pgr_driving_distance(pgr_edge_t *data_edges, size_t total_edges, int64_t start_vertex, double distance, bool directedFlag, General_path_element_t **ret_path, size_t *path_count, char **err_msg)
void do_pgr_driving_many_to_dist(pgr_edge_t *data_edges, size_t total_tuples, int64_t *start_vertex, size_t s_len, double distance, bool directedFlag, bool equiCostFlag, General_path_element_t **ret_path, size_t *path_count, char **err_msg)
graphType
Definition: pgr_types.h:192
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:52
bool empty() const
path_element_t * path
Definition: BDATester.cpp:49
void pgr_drivingDistance(G &graph, std::deque< Path > &paths, std::vector< int64_t > start_vids, double distance, bool equicost)
char * err_msg
Definition: BDATester.cpp:50
size_t size() const
void graph_insert_data(const T *edges, int64_t count)
Inserts count edges of type T into the graph.