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