PGROUTING  2.6
contractGraph_driver.h File Reference
Include dependency graph for contractGraph_driver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void do_pgr_contractGraph (pgr_edge_t *data_edges, size_t total_tuples, int64_t *forbidden_vertices, size_t size_forbidden_vertices, int64_t *contraction_order, size_t size_contraction_order, int64_t max_cycles, bool directed, contracted_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

void do_pgr_contractGraph ( pgr_edge_t data_edges,
size_t  total_tuples,
int64_t *  forbidden_vertices,
size_t  size_forbidden_vertices,
int64_t *  contraction_order,
size_t  size_contraction_order,
int64_t  max_cycles,
bool  directed,
contracted_rt **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 172 of file contractGraph_driver.cpp.

References edge::cost, DIRECTED, get_postgres_result(), edge::id, is_valid_contraction(), pgassert, pgr_free(), pgr_msg(), process_contraction(), edge::reverse_cost, Identifiers< T >::size(), edge::source, edge::target, UNDIRECTED, and AssertFailedException::what().

Referenced by process().

185  {
186  std::ostringstream log;
187  std::ostringstream notice;
188  std::ostringstream err;
189  try {
190  pgassert(total_edges != 0);
191  pgassert(size_contraction_order != 0);
192  pgassert(max_cycles != 0);
193  pgassert(!(*log_msg));
194  pgassert(!(*notice_msg));
195  pgassert(!(*err_msg));
196  pgassert(!(*return_tuples));
197  pgassert(*return_count == 0);
198 
199  std::ostringstream debug;
200  /*
201  * Converting to C++ structures
202  */
203  std::vector<pgr_edge_t> edges(data_edges, data_edges + total_edges);
204  std::vector<int64_t> forbid(
205  forbidden_vertices,
206  forbidden_vertices + size_forbidden_vertices);
207  std::vector<int64_t> ordering(
208  contraction_order,
209  contraction_order + size_contraction_order);
210 
211  for (const auto o : ordering) {
212  if (!is_valid_contraction(o)) {
213  *err_msg = pgr_msg("Invalid Contraction Type found");
214  log << "Contraction type " << o << " not valid";
215  *log_msg = pgr_msg(log.str().c_str());
216  return;
217  }
218  }
219 
220 
221  /*
222  * Extracting vertices of the graph
223  */
224  Identifiers<int64_t> remaining_vertices;
225  std::vector< pgrouting::CH_edge > shortcut_edges;
226 
227 #ifndef NDEBUG
228  log << "Original Graph: \n" <<
229  std::setprecision(32);
230  for (const auto edge : edges) {
231  log << "id = " << edge.id
232  << "\tsource = " << edge.source
233  << "\ttarget = " << edge.target
234  << "\tcost = " << edge.cost
235  << "\treverse_cost = " << edge.reverse_cost
236  << ")\n";
237  }
238  log << "size_contraction_order " << ordering.size() << "\n";
239  log << "contraction_order: " <<"{ ";
240  for (const auto o : ordering) {
241  log << o << ", ";
242  }
243  log << " }\n";
244 
245  log << "size_forbidden_vertices " << forbid.size() << "\n";
246  log << "forbidden_vertices" << "{ ";
247  for (const auto vertex : forbid) {
248  log << vertex << ", ";
249  }
250  log << " }\n";
251  log << "max_cycles " << max_cycles << "\n";
252  log << "directed " << directed << "\n";
253 #endif
254 
255  graphType gType = directed? DIRECTED: UNDIRECTED;
256  if (directed) {
257  log << "Working with directed Graph\n";
258  pgrouting::CHDirectedGraph digraph(gType);
259 
260  process_contraction(digraph, edges, forbid, ordering,
261  max_cycles,
262  remaining_vertices, shortcut_edges,
263  log, err);
264 
266  digraph,
267  remaining_vertices,
268  shortcut_edges,
269  return_tuples);
270  } else {
271  log << "Working with Undirected Graph\n";
272 
273  pgrouting::CHUndirectedGraph undigraph(gType);
274  process_contraction(undigraph, edges, forbid, ordering,
275  max_cycles,
276  remaining_vertices, shortcut_edges,
277  log, err);
278 
280  undigraph,
281  remaining_vertices,
282  shortcut_edges,
283  return_tuples);
284  }
285 
286  (*return_count) = remaining_vertices.size()+shortcut_edges.size();
287 
288 
289  *log_msg = log.str().empty()?
290  *log_msg :
291  pgr_msg(log.str().c_str());
292  *notice_msg = notice.str().empty()?
293  *notice_msg :
294  pgr_msg(notice.str().c_str());
295  } catch (AssertFailedException &except) {
296  (*return_tuples) = pgr_free(*return_tuples);
297  (*return_count) = 0;
298  err << except.what();
299  *err_msg = pgr_msg(err.str().c_str());
300  *log_msg = pgr_msg(log.str().c_str());
301  } catch (std::exception &except) {
302  (*return_tuples) = pgr_free(*return_tuples);
303  (*return_count) = 0;
304  err << except.what();
305  *err_msg = pgr_msg(err.str().c_str());
306  *log_msg = pgr_msg(log.str().c_str());
307  } catch(...) {
308  (*return_tuples) = pgr_free(*return_tuples);
309  (*return_count) = 0;
310  err << "Caught unknown exception!";
311  *err_msg = pgr_msg(err.str().c_str());
312  *log_msg = pgr_msg(log.str().c_str());
313  }
314 }
static void process_contraction(G &graph, const std::vector< pgr_edge_t > &edges, const std::vector< int64_t > forbidden_vertices, const std::vector< int64_t > contraction_order, int64_t max_cycles, Identifiers< int64_t > &remaining_vertices, std::vector< pgrouting::CH_edge > &shortcut_edges, std::ostringstream &log, std::ostringstream &err)
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
static void get_postgres_result(G &graph, const Identifiers< int64_t > remaining_vertices, const std::vector< pgrouting::CH_edge > shortcut_edges, contracted_rt **return_tuples)
long id
Definition: trsp.h:32
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
size_t size() const
Definition: identifiers.hpp:77
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
virtual const char * what() const
Definition: pgr_assert.cpp:53
static bool is_valid_contraction(int64_t number)
graphType
Definition: graph_enum.h:30
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: