PGROUTING  3.2
contractGraph_driver.cpp File Reference
#include "drivers/contraction/contractGraph_driver.h"
#include <string.h>
#include <sstream>
#include <deque>
#include <vector>
#include <algorithm>
#include "contraction/ch_graphs.hpp"
#include "contraction/pgr_contract.hpp"
#include "cpp_common/identifiers.hpp"
#include "cpp_common/pgr_alloc.hpp"
Include dependency graph for contractGraph_driver.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{contractGraph_driver.cpp}
 

Functions

void do_pgr_contractGraph (pgr_edge_t *data_edges, size_t total_edges, 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)
 
template<typename G >
Identifiers< int64_t > anonymous_namespace{contractGraph_driver.cpp}::get_modified_vertices (const G &graph)
 vertices with at least one contracted vertex More...
 
template<typename G >
void anonymous_namespace{contractGraph_driver.cpp}::get_postgres_result (G &graph, contracted_rt **return_tuples, size_t *count)
 
template<typename G >
std::vector< typename G::E > anonymous_namespace{contractGraph_driver.cpp}::get_shortcuts (const G &graph)
 vertices with at least one contracted vertex More...
 
template<typename G >
void anonymous_namespace{contractGraph_driver.cpp}::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)
 

Function Documentation

◆ do_pgr_contractGraph()

void do_pgr_contractGraph ( pgr_edge_t data_edges,
size_t  total_edges,
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 177 of file contractGraph_driver.cpp.

190  {
191  std::ostringstream log;
192  std::ostringstream notice;
193  std::ostringstream err;
194  try {
195  pgassert(total_edges != 0);
196  pgassert(size_contraction_order != 0);
197  pgassert(max_cycles != 0);
198  pgassert(!(*log_msg));
199  pgassert(!(*notice_msg));
200  pgassert(!(*err_msg));
201  pgassert(!(*return_tuples));
202  pgassert(*return_count == 0);
203 
204  /*
205  * Converting to C++ structures
206  */
207  std::vector<pgr_edge_t> edges(data_edges, data_edges + total_edges);
208  std::vector<int64_t> forbid(
209  forbidden_vertices,
210  forbidden_vertices + size_forbidden_vertices);
211  std::vector<int64_t> ordering(
212  contraction_order,
213  contraction_order + size_contraction_order);
214 
215  for (const auto kind : ordering) {
216  if (!pgrouting::contraction::is_valid_contraction(static_cast<int>(kind))) {
217  *err_msg = pgr_msg("Invalid contraction type found");
218  log << "Contraction type " << kind << " not valid";
219  *log_msg = pgr_msg(log.str().c_str());
220  return;
221  }
222  }
223 
224 
225  graphType gType = directed? DIRECTED: UNDIRECTED;
226  if (directed) {
228  DirectedGraph digraph(gType);
229 
230  process_contraction(digraph, edges, forbid, ordering,
231  max_cycles);
232 
234  digraph,
235  return_tuples,
236  return_count);
237  } else {
239  UndirectedGraph undigraph(gType);
240  process_contraction(undigraph, edges, forbid, ordering,
241  max_cycles);
242 
244  undigraph,
245  return_tuples,
246  return_count);
247  }
248 
249  pgassert(err.str().empty());
250  *log_msg = log.str().empty()?
251  *log_msg :
252  pgr_msg(log.str().c_str());
253  *notice_msg = notice.str().empty()?
254  *notice_msg :
255  pgr_msg(notice.str().c_str());
256  } catch (AssertFailedException &except) {
257  (*return_tuples) = pgr_free(*return_tuples);
258  (*return_count) = 0;
259  err << except.what();
260  *err_msg = pgr_msg(err.str().c_str());
261  *log_msg = pgr_msg(log.str().c_str());
262  } catch (std::exception &except) {
263  (*return_tuples) = pgr_free(*return_tuples);
264  (*return_count) = 0;
265  err << except.what();
266  *err_msg = pgr_msg(err.str().c_str());
267  *log_msg = pgr_msg(log.str().c_str());
268  } catch(...) {
269  (*return_tuples) = pgr_free(*return_tuples);
270  (*return_count) = 0;
271  err << "Caught unknown exception!";
272  *err_msg = pgr_msg(err.str().c_str());
273  *log_msg = pgr_msg(log.str().c_str());
274  }
275 }

References DIRECTED, get_postgres_result(), pgrouting::contraction::is_valid_contraction(), pgassert, pgr_free(), pgr_msg(), anonymous_namespace{contractGraph_driver.cpp}::process_contraction(), UNDIRECTED, and AssertFailedException::what().

Referenced by process().

pgrouting::UndirectedGraph
graph::Pgr_base_graph< boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, Basic_vertex, Basic_edge >, Basic_vertex, Basic_edge > UndirectedGraph
Definition: pgr_base_graph.hpp:186
pgr_msg
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
AssertFailedException::what
virtual const char * what() const
Definition: pgr_assert.cpp:67
pgrouting::graph::CHDirectedGraph
Pgr_contractionGraph< boost::adjacency_list< boost::listS, boost::vecS, boost::bidirectionalS, CH_vertex, CH_edge > > CHDirectedGraph
Definition: ch_graphs.hpp:56
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgrouting::graph::CHUndirectedGraph
Pgr_contractionGraph< boost::adjacency_list< boost::listS, boost::vecS, boost::undirectedS, CH_vertex, CH_edge > > CHUndirectedGraph
Definition: ch_graphs.hpp:51
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
anonymous_namespace{contractGraph_driver.cpp}::process_contraction
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)
Definition: contractGraph_driver.cpp:85
graphType
graphType
Definition: graph_enum.h:30
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
pgrouting::DirectedGraph
graph::Pgr_base_graph< boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, Basic_vertex, Basic_edge >, Basic_vertex, Basic_edge > DirectedGraph
Definition: pgr_base_graph.hpp:192
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
get_postgres_result
void get_postgres_result(std::vector< Line_graph_rt > edge_result, Line_graph_rt **return_tuples, size_t &sequence)
Definition: lineGraph_driver.cpp:46
pgrouting::contraction::is_valid_contraction
bool is_valid_contraction(int number)
Definition: pgr_contract.cpp:35
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139