PGROUTING  2.5
 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 
41 /************************************************************
42  edges_sql TEXT
43  ***********************************************************/
44 bool
46  pgr_edge_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_t> edges(data_edges, data_edges + total_edges);
57  auto vertices(pgrouting::extract_vertices(edges));
58 
59  log << "Original: \n" <<
60  std::setprecision(9);
61  for (const auto edge: edges) {
62  log << "id = " << edge.id
63  << "\tsource = " << edge.source
64  << "\ttarget = " << edge.target
65  << "\tcost = " << edge.cost
66  << "\treverse_cost = " << edge.reverse_cost
67  << ")\n";
68  }
69 
70  {
71  log << "Testing Directed , insertion using vector\n";
73  log << " - Created graph:\n";
74  log << graph;
75 
76  log << " - Inserting Edges:\n";
77  graph.insert_edges(edges);
78  log << graph;
79 
80  log << " - Can do a dijKstra:\n";
81  pgr_dijkstra(graph, 2, 3, true);
82 
83  }
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 
100  {
101  log << "Testing Undirected , insertion using vector\n";
103  log << " - Created graph:\n";
104  log << graph;
105 
106  log << " - Inserting Edges:\n";
107  graph.insert_edges(edges);
108  log << graph;
109 
110  log << " - Can do a dijKstra:\n";
111  pgr_dijkstra(graph, 2, 3, true);
112  }
113 
114  {
115  log << "Testing Undirected , insertion using C array\n";
117  log << " - Created graph:\n";
118  log << graph;
119 
120  log << " - Inserting Edges:\n";
121  graph.insert_edges(data_edges, total_edges);
122  log << graph;
123 
124  log << " - Can do a dijKstra:\n";
125  pgr_dijkstra(graph, 2, 3, true);
126  }
127 
128  {
129  log << "Testing Identifiers\n";
131  graph.insert_edges(edges);
132 
133  Identifiers<int64_t> all_vertices, contracted_vertices, remaining_vertices;
134 
135  for (const auto vertex: vertices) {
136  all_vertices.insert(graph.get_V(vertex.id));
137  }
138  /*
139  Contracted vertices:
140  1, 7, 8, 13, 14, 16
141  */
142  contracted_vertices.insert(graph.get_V(1));
143  contracted_vertices.insert(graph.get_V(7));
144  contracted_vertices.insert(graph.get_V(8));
145  contracted_vertices.insert(graph.get_V(13));
146  contracted_vertices.insert(graph.get_V(14));
147  contracted_vertices.insert(graph.get_V(16));
148 
149  remaining_vertices = all_vertices - contracted_vertices;
150 
151  log << " - All vertices: "
152  << all_vertices
153  << "\n - Contracted vertices: "
154  << contracted_vertices
155  << "\n - Remaining vertices: "
156  << remaining_vertices
157  << "\n";
158  }
159 
160  {
161  log << "Testing CH_vertex class\n";
162 
164  graph.insert_edges(edges);
165 
166  log << "id ----- V\n";
167  for (int64_t i = 1; i < 18; ++i) {
168  log << " " << i << " ----- " << graph.get_V(i) << "\n";
169  }
170  auto vid1 = graph.get_V(1);
171  auto vid2 = graph.get_V(2);
172 
173  auto v1 = graph[vid1];
174  auto v2 = graph[vid2];
175 
176 
177  log << " - Dead end contraction:\n";
178  // vertex 1 is contracted to vertex 2
179  v2.add_contracted_vertex(v1, vid1);
180  log << "Vertex 1 is contracted to Vertex 2:\n";
181  log << vid1 << v1 << "\n";
182  log << vid2 << v2 << "\n";
183 
184  log << " - Linear contraction:\n";
189 
190  // vertex 2 is contracted to edge -1
191  log << "Vertex 1 is contracted to edge -1:\n";
192  e1.id = -1;
193  e1.cost = 0;
194  e1.source = 3;
195  e1.target = 5;
196  e1.add_contracted_vertex(v2, vid2);
197  log << vid2 << v2 << "\n";
198  log << e1 << "\n";
199  log << vid2 << v2 << "\n";
200  }
201 
202  *err_msg = NULL;
203  *log_msg = strdup(log.str().c_str());
204  return true;
205 
206  } catch (AssertFailedException &except) {
207  log << except.what() << "\n";
208  *err_msg = strdup(log.str().c_str());
209  return false;
210  } catch (std::exception& except) {
211  log << except.what() << "\n";
212  *err_msg = strdup(log.str().c_str());
213  return false;
214  } catch(...) {
215  log << "Caught unknown exception!\n";
216  *err_msg = strdup(log.str().c_str());
217  return false;
218  }
219 }
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.
bool do_pgr_test_c_edges(pgr_edge_t *data_edges, size_t total_edges, char **log_msg, char **err_msg)
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
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
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
int64_t source
Definition: ch_edge.h:62
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
long target
Definition: trsp.h:34
float8 reverse_cost
Definition: trsp.h:36
long source
Definition: trsp.h:33