PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_c_edges_driver.cpp File Reference
#include "./test_c_edges_driver.h"
#include <sstream>
#include <iomanip>
#include <vector>
#include "./../../contraction/src/pgr_contractionGraph.hpp"
#include "./../../dijkstra/src/pgr_dijkstra.hpp"
#include "./../../common/src/pgr_assert.h"
Include dependency graph for test_c_edges_driver.cpp:

Go to the source code of this file.

Functions

bool do_pgr_test_c_edges (pgr_edge_t *data_edges, size_t total_edges, char **log_msg, char **err_msg)
 

Function Documentation

bool do_pgr_test_c_edges ( pgr_edge_t data_edges,
size_t  total_edges,
char **  log_msg,
char **  err_msg 
)

Definition at line 45 of file test_c_edges_driver.cpp.

References pgrouting::CH_edge::add_contracted_vertex(), edge::cost, pgrouting::CH_edge::cost, DIRECTED, edges, pgrouting::extract_vertices(), pgrouting::graph::Pgr_base_graph< G, Vertex, Edge >::get_V(), edge::id, pgrouting::CH_edge::id, pgrouting::graph::Pgr_base_graph< G, Vertex, Edge >::insert_edges(), pgassert, pgr_dijkstra(), edge::reverse_cost, edge::source, pgrouting::CH_edge::source, edge::target, pgrouting::CH_edge::target, UNDIRECTED, and AssertFailedException::what().

Referenced by process().

49  {
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
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
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

Here is the call graph for this function:

Here is the caller graph for this function: