PGROUTING  2.4
 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 #include "./testXYedges_driver.h"
31 
32 #include <sstream>
33 #include <iomanip>
34 #include <vector>
35 
36 #include "./../../common/src/pgr_base_graph.hpp"
37 #include "./../../dijkstra/src/pgr_dijkstra.hpp"
38 
39 #include "./../../common/src/pgr_assert.h"
40 #include "./../../common/src/pgr_types.h"
41 
42 /************************************************************
43  edges_sql TEXT
44  ***********************************************************/
45 bool
47  Pgr_edge_xy_t *data_edges,
48  size_t total_edges,
49  char ** log_msg,
50  char ** err_msg) {
51  std::ostringstream log;
52  std::ostringstream err;
53  try {
54  pgassert(!(*log_msg));
55  pgassert(!(*err_msg));
56 
57  std::vector< Pgr_edge_xy_t > edges(data_edges, data_edges + total_edges);
58  auto vertices(pgrouting::extract_vertices(edges));
59 
60 
61  log << "Original: \n" <<
62  std::setprecision(32);
63  for (const auto edge : edges) {
64  log << "id = " << edge.id
65  << "\tsource = " << edge.source
66  << "\ttarget = " << edge.target
67  << "\tcost = " << edge.cost
68  << "\treverse_cost = " << edge.reverse_cost
69  << "\n\t(x1,y1) = (" << edge.x1 << "," << edge.y1 << ")"
70  << "\t(x2,y2) = (" << edge.x2 << "," << edge.y2 << ")\n";
71  }
72 
73  {
74  log << "Testing Directed , insertion using vector\n";
76  log << " - Created graph:\n";
77  log << graph;
78 
79  log << " - Inserting Edges:\n";
80  graph.insert_edges(edges);
81  log << graph;
82 
83  log << " - Can do a dijKstra:\n";
84  pgr_dijkstra(graph, 2, 3, true);
85  }
86  {
87  log << "Testing Directed , insertion using C array\n";
89  log << " - Created graph:\n";
90  log << graph;
91 
92  log << " - Inserting Edges:\n";
93  graph.insert_edges(data_edges, total_edges);
94  log << graph;
95 
96  log << " - Can do a dijKstra:\n";
97  pgr_dijkstra(graph, 2, 3, true);
98  }
99  {
100  log << "Testing Directed , creating with vertices, insertion using vector\n";
101  pgrouting::xyDirectedGraph graph(vertices, DIRECTED);
102  log << " - Created graph:\n";
103  log << graph;
104 
105  log << " - Inserting Edges:\n";
106  graph.insert_edges(edges);
107  log << graph;
108 
109  log << " - Can do a dijKstra:\n";
110  pgr_dijkstra(graph, 2, 3, true);
111  }
112  {
113  log << "Testing Directed , creating with vertices, insertion using C array\n";
114  pgrouting::xyDirectedGraph graph(vertices, DIRECTED);
115  log << " - Created graph:\n";
116  log << graph;
117 
118  log << " - Inserting Edges:\n";
119  graph.insert_edges(data_edges, total_edges);
120  log << graph;
121 
122  log << " - Can do a dijKstra:\n";
123  pgr_dijkstra(graph, 2, 3, true);
124  }
125 
126  {
127  log << "Testing Undirected , insertion using vector\n";
129  log << " - Created graph:\n";
130  log << graph;
131 
132  log << " - Inserting Edges:\n";
133  graph.insert_edges(edges);
134  log << graph;
135 
136  log << " - Can do a dijKstra:\n";
137  pgr_dijkstra(graph, 2, 3, true);
138  }
139  {
140  log << "Testing Directed , insertion using C array\n";
142  log << " - Created graph:\n";
143  log << graph;
144 
145  log << " - Inserting Edges:\n";
146  graph.insert_edges(data_edges, total_edges);
147  log << graph;
148 
149  log << " - Can do a dijKstra:\n";
150  pgr_dijkstra(graph, 2, 3, true);
151  }
152  {
153  log << "Testing Undirected , insertion using C array\n";
155  log << " - Created graph:\n";
156  log << graph;
157 
158  log << " - Inserting Edges:\n";
159  graph.insert_edges(data_edges, total_edges);
160  log << graph;
161 
162  log << " - Can do a dijKstra:\n";
163  pgr_dijkstra(graph, 2, 3, true);
164  }
165  {
166  log << "Testing Undirected , creating with vertices, insertion using vector\n";
167  pgrouting::xyUndirectedGraph graph(vertices, UNDIRECTED);
168  log << " - Created graph:\n";
169  log << graph;
170 
171  log << " - Inserting Edges:\n";
172  graph.insert_edges(edges);
173  log << graph;
174 
175  log << " - Can do a dijKstra:\n";
176  pgr_dijkstra(graph, 2, 3, true);
177  }
178 
179  *err_msg = NULL;
180  *log_msg = strdup(log.str().c_str());
181  return true;
182  } catch (AssertFailedException &except) {
183  log << except.what() << "\n";
184  *err_msg = strdup(log.str().c_str());
185  return false;
186  } catch (std::exception& except) {
187  log << except.what() << "\n";
188  *err_msg = strdup(log.str().c_str());
189  return false;
190  } catch(...) {
191  log << "Caught unknown exception!\n";
192  *err_msg = strdup(log.str().c_str());
193  return false;
194  }
195 }
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.
double cost
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::deque< Path > pgr_dijkstra(G &graph, std::vector< int64_t > sources, std::vector< int64_t > targets, bool only_cost, bool normal)
double reverse_cost
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)
virtual const char * what() const
Definition: pgr_assert.cpp:53
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