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
testXYedges_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: testXYedges_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) 2015 Celia Virginia Vergara Castillo
10 Mail:
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 
30 
31 #if defined(__MINGW32__) || defined(_MSC_VER)
32 #include <winsock2.h>
33 #include <windows.h>
34 #endif
35 
36 #include <sstream>
37 #include <iomanip>
38 #include <vector>
39 #include "./testXYedges_driver.h"
40 
41 
42 #include "./../../common/src/pgr_types.h"
43 #include "./../../dijkstra/src/pgr_dijkstra.hpp"
44 #include "./../../common/src/pgr_base_graph.hpp"
45 #include "./../../common/src/pgr_assert.h"
46 
47 /************************************************************
48  edges_sql TEXT
49  ***********************************************************/
50 bool
52  Pgr_edge_xy_t *data_edges,
53  size_t total_edges,
54  char ** log_msg,
55  char ** err_msg) {
56  std::ostringstream log;
57  std::ostringstream err;
58  try {
59  pgassert(!(*log_msg));
60  pgassert(!(*err_msg));
61 
62  std::vector< Pgr_edge_xy_t > edges(data_edges, data_edges + total_edges);
63  auto vertices(pgrouting::extract_vertices(edges));
64 
65 
66  log << "Original: \n" <<
67  std::setprecision(32);
68  for (const auto edge : edges) {
69  log << "id = " << edge.id
70  << "\tsource = " << edge.source
71  << "\ttarget = " << edge.target
72  << "\tcost = " << edge.cost
73  << "\treverse_cost = " << edge.reverse_cost
74  << "\n\t(x1,y1) = (" << edge.x1 << "," << edge.y1 << ")"
75  << "\t(x2,y2) = (" << edge.x2 << "," << edge.y2 << ")\n";
76  }
77 
78  {
79  log << "Testing Directed , insertion using vector\n";
81  log << " - Created graph:\n";
82  log << graph;
83 
84  log << " - Inserting Edges:\n";
85  graph.graph_insert_data(edges);
86  log << graph;
87 
88  log << " - Can do a dijKstra:\n";
89  Path path;
90  pgr_dijkstra(graph, path, 2, 3, true);
91  }
92  {
93  log << "Testing Directed , insertion using C array\n";
95  log << " - Created graph:\n";
96  log << graph;
97 
98  log << " - Inserting Edges:\n";
99  graph.graph_insert_data(data_edges, total_edges);
100  log << graph;
101 
102  log << " - Can do a dijKstra:\n";
103  Path path;
104  pgr_dijkstra(graph, path, 2, 3, true);
105  }
106  {
107  log << "Testing Directed , creating with vertices, insertion using vector\n";
108  pgrouting::xyDirectedGraph graph(vertices, DIRECTED);
109  log << " - Created graph:\n";
110  log << graph;
111 
112  log << " - Inserting Edges:\n";
113  graph.graph_insert_data(edges);
114  log << graph;
115 
116  log << " - Can do a dijKstra:\n";
117  Path path;
118  pgr_dijkstra(graph, path, 2, 3, true);
119  }
120  {
121  log << "Testing Directed , creating with vertices, insertion using C array\n";
122  pgrouting::xyDirectedGraph graph(vertices, DIRECTED);
123  log << " - Created graph:\n";
124  log << graph;
125 
126  log << " - Inserting Edges:\n";
127  graph.graph_insert_data(data_edges, total_edges);
128  log << graph;
129 
130  log << " - Can do a dijKstra:\n";
131  Path path;
132  pgr_dijkstra(graph, path, 2, 3, true);
133  }
134 
135  {
136  log << "Testing Undirected , insertion using vector\n";
138  log << " - Created graph:\n";
139  log << graph;
140 
141  log << " - Inserting Edges:\n";
142  graph.graph_insert_data(edges);
143  log << graph;
144 
145  log << " - Can do a dijKstra:\n";
146  Path path;
147  pgr_dijkstra(graph, path, 2, 3, true);
148  }
149  {
150  log << "Testing Directed , insertion using C array\n";
152  log << " - Created graph:\n";
153  log << graph;
154 
155  log << " - Inserting Edges:\n";
156  graph.graph_insert_data(data_edges, total_edges);
157  log << graph;
158 
159  log << " - Can do a dijKstra:\n";
160  Path path;
161  pgr_dijkstra(graph, path, 2, 3, true);
162  }
163  {
164  log << "Testing Undirected , insertion using C array\n";
166  log << " - Created graph:\n";
167  log << graph;
168 
169  log << " - Inserting Edges:\n";
170  graph.graph_insert_data(data_edges, total_edges);
171  log << graph;
172 
173  log << " - Can do a dijKstra:\n";
174  Path path;
175  pgr_dijkstra(graph, path, 2, 3, true);
176  }
177  {
178  log << "Testing Undirected , creating with vertices, insertion using vector\n";
179  pgrouting::xyUndirectedGraph graph(vertices, UNDIRECTED);
180  log << " - Created graph:\n";
181  log << graph;
182 
183  log << " - Inserting Edges:\n";
184  graph.graph_insert_data(edges);
185  log << graph;
186 
187  log << " - Can do a dijKstra:\n";
188  Path path;
189  pgr_dijkstra(graph, path, 2, 3, true);
190  }
191 
192  *err_msg = NULL;
193  *log_msg = strdup(log.str().c_str());
194  return true;
195  } catch (AssertFailedException &except) {
196  log << except.what() << "\n";
197  *err_msg = strdup(log.str().c_str());
198  return false;
199  } catch (std::exception& except) {
200  log << except.what() << "\n";
201  *err_msg = strdup(log.str().c_str());
202  return false;
203  } catch(...) {
204  log << "Caught unknown exception!\n";
205  *err_msg = strdup(log.str().c_str());
206  return false;
207  }
208 }
double cost
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
void pgr_dijkstra(G &graph, Path &path, int64_t source, int64_t target, bool only_cost=false)
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
edge_astar_t * edges
Definition: BDATester.cpp:46
std::vector< Basic_vertex > extract_vertices(std::vector< Basic_vertex > vertices, const std::vector< pgr_edge_t > data_edges)
path_element_t * path
Definition: BDATester.cpp:49
virtual const char * what() const
Definition: pgr_assert.cpp:62
bool do_pgr_testXYedges(Pgr_edge_xy_t *data_edges, size_t total_edges, char **log_msg, char **err_msg)
char * err_msg
Definition: BDATester.cpp:50
double reverse_cost
void graph_insert_data(const T *edges, int64_t count)
Inserts count edges of type T into the graph.