PGROUTING  3.2
anonymous_namespace{contractGraph_driver.cpp} Namespace Reference

Functions

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

Function Documentation

◆ get_modified_vertices()

template<typename G >
Identifiers<int64_t> anonymous_namespace{contractGraph_driver.cpp}::get_modified_vertices ( const G &  graph)

vertices with at least one contracted vertex

Returns
The vids Identifiers with at least one contracted vertex

Definition at line 51 of file contractGraph_driver.cpp.

51  {
53  for (auto v : boost::make_iterator_range(boost::vertices(graph.graph))) {
54  if (graph[v].has_contracted_vertices()) {
55  vids += graph[v].id;
56  }
57  }
58  return vids;
59 }

Referenced by get_postgres_result().

◆ get_postgres_result()

template<typename G >
void anonymous_namespace{contractGraph_driver.cpp}::get_postgres_result ( G &  graph,
contracted_rt **  return_tuples,
size_t *  count 
)

Definition at line 111 of file contractGraph_driver.cpp.

114  {
115  auto modified_vertices(get_modified_vertices(graph));
116  auto shortcut_edges(get_shortcuts(graph));
117 
118  (*count) = modified_vertices.size() + shortcut_edges.size();
119  (*return_tuples) = pgr_alloc((*count), (*return_tuples));
120  size_t sequence = 0;
121 
122  for (const auto id : modified_vertices) {
123  auto v = graph.get_V(id);
124  int64_t* contracted_vertices = NULL;
125  auto vids = graph[v].contracted_vertices();
126 
127  contracted_vertices = pgr_alloc(vids.size(), contracted_vertices);
128 
129  int count = 0;
130  for (const auto id : vids) {
131  contracted_vertices[count++] = id;
132  }
133  (*return_tuples)[sequence] = {
134  id,
135  const_cast<char*>("v"),
136  -1, -1, -1.00,
137  contracted_vertices,
138  count};
139 
140  ++sequence;
141  }
142 
143  int64_t eid = 0;
144  for (auto e : shortcut_edges) {
145  auto edge = graph[e];
146  int64_t* contracted_vertices = NULL;
147 
148  const auto vids(edge.contracted_vertices());
149  pgassert(!vids.empty());
150 
151  contracted_vertices = pgr_alloc(vids.size(), contracted_vertices);
152  int count = 0;
153  for (const auto vid : vids) {
154  contracted_vertices[count++] = vid;
155  }
156  (*return_tuples)[sequence] = {
157  --eid,
158  const_cast<char*>("e"),
160  contracted_vertices, count};
161  ++sequence;
162  }
163 }

References edge::cost, get_modified_vertices(), get_shortcuts(), pgassert, pgr_alloc(), edge::source, and edge::target.

◆ get_shortcuts()

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

Returns
The vids Identifiers with at least one contracted vertex

Definition at line 66 of file contractGraph_driver.cpp.

66  {
67  using E = typename G::E;
68  Identifiers<E> eids;
69  for (auto e : boost::make_iterator_range(boost::edges(graph.graph))) {
70  if (graph[e].id < 0) {
71  eids += e;
72  pgassert(!graph[e].contracted_vertices().empty());
73  } else {
74  pgassert(graph[e].contracted_vertices().empty());
75  }
76  }
77  std::vector<E> o_eids(eids.begin(), eids.end());
78  std::sort(o_eids.begin(), o_eids.end(),
79  [&](E lhs, E rhs) {return -graph[lhs].id < -graph[rhs].id;});
80  return o_eids;
81 }

References Identifiers< T >::begin(), Identifiers< T >::end(), and pgassert.

Referenced by get_postgres_result().

◆ process_contraction()

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 
)

Definition at line 85 of file contractGraph_driver.cpp.

90  {
91  graph.insert_edges(edges);
92  Identifiers<typename G::V> forbid_vertices;
93  for (const auto &vertex : forbidden_vertices) {
94  if (graph.has_vertex(vertex)) {
95  forbid_vertices += graph.get_V(vertex);
96  }
97  }
98 
99  /*
100  * Function call to get the contracted graph.
101  */
103  Contract result(
104  graph,
105  forbid_vertices,
106  contraction_order,
107  max_cycles);
108 }

Referenced by do_pgr_contractGraph().

pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
edge::cost
float8 cost
Definition: trsp.h:45
edge::target
int64 target
Definition: trsp.h:44
edge
Definition: trsp.h:41
anonymous_namespace{contractGraph_driver.cpp}::get_modified_vertices
Identifiers< int64_t > get_modified_vertices(const G &graph)
vertices with at least one contracted vertex
Definition: contractGraph_driver.cpp:51
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
Identifiers::begin
const_iterator begin() const
Definition: identifiers.hpp:81
pgrouting::alphashape::E
boost::graph_traits< BG >::edge_descriptor E
Definition: pgr_alphaShape.h:57
anonymous_namespace{contractGraph_driver.cpp}::get_shortcuts
std::vector< typename G::E > get_shortcuts(const G &graph)
vertices with at least one contracted vertex
Definition: contractGraph_driver.cpp:66
edge::source
int64 source
Definition: trsp.h:43
Identifiers::end
const_iterator end() const
Definition: identifiers.hpp:82
pgrouting::contraction::Pgr_contract
Definition: pgr_contract.hpp:49
Identifiers< int64_t >