PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_c_edges_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 Rohith Reddy
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 "./test_c_edges_driver.h"
31 
32 #include <sstream>
33 #include <iomanip>
34 #include <vector>
35 
36 #include "./../../contraction/src/pgr_contractionGraph.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_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_t> edges(data_edges, data_edges + total_edges);
58  auto vertices(pgrouting::extract_vertices(edges));
59 
60  log << "Original: \n" <<
61  std::setprecision(9);
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";
69  }
70 
71  {
72  log << "Testing Directed , insertion using vector\n";
74  log << " - Created graph:\n";
75  log << graph;
76 
77  log << " - Inserting Edges:\n";
78  graph.insert_edges(edges);
79  log << graph;
80 
81  log << " - Can do a dijKstra:\n";
82  pgr_dijkstra(graph, 2, 3, true);
83 
84  }
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 
101  {
102  log << "Testing Undirected , insertion using vector\n";
104  log << " - Created graph:\n";
105  log << graph;
106 
107  log << " - Inserting Edges:\n";
108  graph.insert_edges(edges);
109  log << graph;
110 
111  log << " - Can do a dijKstra:\n";
112  pgr_dijkstra(graph, 2, 3, true);
113  }
114 
115  {
116  log << "Testing Undirected , insertion using C array\n";
118  log << " - Created graph:\n";
119  log << graph;
120 
121  log << " - Inserting Edges:\n";
122  graph.insert_edges(data_edges, total_edges);
123  log << graph;
124 
125  log << " - Can do a dijKstra:\n";
126  pgr_dijkstra(graph, 2, 3, true);
127  }
128 
129  {
130  log << "Testing Identifiers\n";
132  graph.insert_edges(edges);
133 
134  Identifiers<int64_t> all_vertices, contracted_vertices, remaining_vertices;
135 
136  for (const auto vertex: vertices) {
137  all_vertices.insert(graph.get_V(vertex.id));
138  }
139  /*
140  Contracted vertices:
141  1, 7, 8, 13, 14, 16
142  */
143  contracted_vertices.insert(graph.get_V(1));
144  contracted_vertices.insert(graph.get_V(7));
145  contracted_vertices.insert(graph.get_V(8));
146  contracted_vertices.insert(graph.get_V(13));
147  contracted_vertices.insert(graph.get_V(14));
148  contracted_vertices.insert(graph.get_V(16));
149 
150  remaining_vertices = all_vertices - contracted_vertices;
151 
152  log << " - All vertices: "
153  << all_vertices
154  << "\n - Contracted vertices: "
155  << contracted_vertices
156  << "\n - Remaining vertices: "
157  << remaining_vertices
158  << "\n";
159  }
160 
161  {
162  log << "Testing CH_vertex class\n";
163 
165  graph.insert_edges(edges);
166 
167  log << "id ----- V\n";
168  for (int64_t i = 1; i < 18; ++i) {
169  log << " " << i << " ----- " << graph.get_V(i) << "\n";
170  }
171  auto vid1 = graph.get_V(1);
172  auto vid2 = graph.get_V(2);
173 
174  auto v1 = graph[vid1];
175  auto v2 = graph[vid2];
176 
177 
178  log << " - Dead end contraction:\n";
179  // vertex 1 is contracted to vertex 2
180  v2.add_contracted_vertex(v1, vid1);
181  log << "Vertex 1 is contracted to Vertex 2:\n";
182  log << vid1 << v1 << "\n";
183  log << vid2 << v2 << "\n";
184 
185  log << " - Linear contraction:\n";
190 
191  // vertex 2 is contracted to edge -1
192  log << "Vertex 1 is contracted to edge -1:\n";
193  e1.id = -1;
194  e1.cost = 0;
195  e1.source = 3;
196  e1.target = 5;
197  e1.add_contracted_vertex(v2, vid2);
198  log << vid2 << v2 << "\n";
199  log << e1 << "\n";
200  log << vid2 << v2 << "\n";
201  }
202 
203  *err_msg = NULL;
204  *log_msg = strdup(log.str().c_str());
205  return true;
206 
207  } catch (AssertFailedException &except) {
208  log << except.what() << "\n";
209  *err_msg = strdup(log.str().c_str());
210  return false;
211  } catch (std::exception& except) {
212  log << except.what() << "\n";
213  *err_msg = strdup(log.str().c_str());
214  return false;
215  } catch(...) {
216  log << "Caught unknown exception!\n";
217  *err_msg = strdup(log.str().c_str());
218  return false;
219  }
220 }
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
bool do_pgr_test_c_edges(pgr_edge_t *data_edges, size_t total_edges, char **log_msg, char **err_msg)
int64_t target
Definition: ch_edge.h:63
V get_V(const T_V &vertex)
get the vertex descriptor of the vertex
void add_contracted_vertex(CH_vertex &v, int64_t vid)
Definition: ch_edge.cpp:54
void insert(const Identifiers< T > &other)
Inserts a set of identifiers of type Identifiers<T> to this set.
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
int64_t source
Definition: ch_edge.h:62
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
char * err_msg
Definition: BDATester.cpp:50