PGROUTING  3.2
pgrouting::contraction::Pgr_linear< G > Class Template Reference

#include "pgr_linearContraction.hpp"

Collaboration diagram for pgrouting::contraction::Pgr_linear< G >:

Public Member Functions

 Pgr_linear ()
 
void calculateVertices (G &graph)
 
void doContraction (G &graph, Identifiers< V > forbidden_vertices)
 
bool is_contractible (G &graph, V v)
 
void one_cycle (G &graph, V v)
 
void operator() (G &graph, Identifiers< V > &forbidden_vertices)
 
void process_shortcut (G &graph, V u, V v, V w)
 u -—e1{v1}-—> v -—e2{v2}-—> w More...
 
void setForbiddenVertices (Identifiers< V > forbidden_vertices)
 

Private Types

typedef G::B_G B_G
 
typedef G::V V
 
typedef G::V_i V_i
 

Private Member Functions

int64_t get_next_id ()
 

Private Attributes

int64_t last_edge_id
 
Identifiers< Vm_forbiddenVertices
 
Identifiers< Vm_linearVertices
 

Detailed Description

template<class G>
class pgrouting::contraction::Pgr_linear< G >

Definition at line 49 of file pgr_linearContraction.hpp.

Member Typedef Documentation

◆ B_G

template<class G >
typedef G::B_G pgrouting::contraction::Pgr_linear< G >::B_G
private

Definition at line 53 of file pgr_linearContraction.hpp.

◆ V

template<class G >
typedef G::V pgrouting::contraction::Pgr_linear< G >::V
private

Definition at line 51 of file pgr_linearContraction.hpp.

◆ V_i

template<class G >
typedef G::V_i pgrouting::contraction::Pgr_linear< G >::V_i
private

Definition at line 52 of file pgr_linearContraction.hpp.

Constructor & Destructor Documentation

◆ Pgr_linear()

template<class G >
pgrouting::contraction::Pgr_linear< G >::Pgr_linear ( )
inline

Definition at line 61 of file pgr_linearContraction.hpp.

61 :last_edge_id(0) {}

Member Function Documentation

◆ calculateVertices()

template<class G >
void pgrouting::contraction::Pgr_linear< G >::calculateVertices ( G &  graph)
inline

Definition at line 79 of file pgr_linearContraction.hpp.

79  {
81  V_i vi;
82  BGL_FORALL_VERTICES_T(v, graph.graph, B_G) {
83  if (is_contractible(graph, v)) {
84  m_linearVertices += v;
85  }
86  }
87  }

References Identifiers< T >::clear(), pgrouting::contraction::Pgr_linear< G >::is_contractible(), and pgrouting::contraction::Pgr_linear< G >::m_linearVertices.

Referenced by pgrouting::contraction::Pgr_linear< G >::doContraction().

◆ doContraction()

◆ get_next_id()

template<class G >
int64_t pgrouting::contraction::Pgr_linear< G >::get_next_id ( )
inlineprivate

◆ is_contractible()

◆ one_cycle()

template<class G >
void pgrouting::contraction::Pgr_linear< G >::one_cycle ( G &  graph,
V  v 
)
inline

Definition at line 103 of file pgr_linearContraction.hpp.

103  {
104  pgassert(is_contractible(graph, v));
105 
106  Identifiers<V> adjacent_vertices =
107  graph.find_adjacent_vertices(v);
108  pgassert(adjacent_vertices.size() == 2);
109 
110  V u = adjacent_vertices.front();
111  adjacent_vertices.pop_front();
112  V w = adjacent_vertices.front();
113  adjacent_vertices.pop_front();
114 
115  pgassert(v != u);
116  pgassert(v != w);
117  pgassert(u != w);
118 
119  if (graph.is_directed()) {
120  /*
121  * u --> v --> w
122  */
123  process_shortcut(graph, u, v, w);
124  /*
125  * w --> v --> u
126  */
127  process_shortcut(graph, w, v, u);
128 
129  } else {
130  pgassert(graph.is_undirected());
131  /*
132  * u - v - w
133  */
134  process_shortcut(graph, u, v, w);
135  }
136 
137  graph[v].contracted_vertices().clear();
138  boost::clear_vertex(v, graph.graph);
139  m_linearVertices -= v;
140 
141  if (is_contractible(graph, u)) {
142  one_cycle(graph, u);
143  } else {
144  m_linearVertices -= u;
145  }
146  if (is_contractible(graph, w)) {
147  one_cycle(graph, w);
148  } else {
149  m_linearVertices -= w;
150  }
151  }

References Identifiers< T >::front(), pgrouting::contraction::Pgr_linear< G >::is_contractible(), pgrouting::contraction::Pgr_linear< G >::m_linearVertices, pgassert, Identifiers< T >::pop_front(), pgrouting::contraction::Pgr_linear< G >::process_shortcut(), and Identifiers< T >::size().

Referenced by pgrouting::contraction::Pgr_linear< G >::doContraction().

◆ operator()()

template<class G >
void pgrouting::contraction::Pgr_linear< G >::operator() ( G &  graph,
Identifiers< V > &  forbidden_vertices 
)
inline

Definition at line 57 of file pgr_linearContraction.hpp.

57  {
58  doContraction(graph, forbidden_vertices);
59  }

References pgrouting::contraction::Pgr_linear< G >::doContraction().

◆ process_shortcut()

template<class G >
void pgrouting::contraction::Pgr_linear< G >::process_shortcut ( G &  graph,
V  u,
V  v,
V  w 
)
inline

u -—e1{v1}-—> v -—e2{v2}-—> w

e1: min cost edge from u to v e2: min cost edge from v to w

result: u —{v+v1+v2}—> w

Definition at line 166 of file pgr_linearContraction.hpp.

166  {
167  auto e1 = graph.get_min_cost_edge(u, v);
168  auto e2 = graph.get_min_cost_edge(v, w);
169 
170  if (std::get<2>(e1) && std::get<2>(e2)) {
171  auto contracted_vertices = std::get<1>(e1) + std::get<1>(e2);
172  double cost = std::get<0>(e1) + std::get<0>(e2);
173  contracted_vertices += graph[v].id;
174  contracted_vertices += graph[v].contracted_vertices();
175 
176  // Create shortcut
177  CH_edge shortcut(
178  get_next_id(),
179  graph[u].id,
180  graph[w].id,
181  cost);
182  shortcut.contracted_vertices() = contracted_vertices;
183 
184  graph.add_shortcut(shortcut, u, w);
185  }
186  }

References pgrouting::CH_edge::contracted_vertices(), and pgrouting::contraction::Pgr_linear< G >::get_next_id().

Referenced by pgrouting::contraction::Pgr_linear< G >::one_cycle().

◆ setForbiddenVertices()

template<class G >
void pgrouting::contraction::Pgr_linear< G >::setForbiddenVertices ( Identifiers< V forbidden_vertices)
inline

Definition at line 70 of file pgr_linearContraction.hpp.

71  {
72  m_forbiddenVertices = forbidden_vertices;
73  }

References pgrouting::contraction::Pgr_linear< G >::m_forbiddenVertices.

Member Data Documentation

◆ last_edge_id

template<class G >
int64_t pgrouting::contraction::Pgr_linear< G >::last_edge_id
private

◆ m_forbiddenVertices

◆ m_linearVertices


The documentation for this class was generated from the following file:
pgrouting::contraction::Pgr_linear::m_linearVertices
Identifiers< V > m_linearVertices
Definition: pgr_linearContraction.hpp:190
pgrouting::contraction::Pgr_linear::is_contractible
bool is_contractible(G &graph, V v)
Definition: pgr_linearContraction.hpp:75
Identifiers::pop_front
void pop_front()
Definition: identifiers.hpp:83
pgrouting::contraction::Pgr_linear::V_i
G::V_i V_i
Definition: pgr_linearContraction.hpp:52
pgrouting::contraction::Pgr_linear::B_G
G::B_G B_G
Definition: pgr_linearContraction.hpp:53
pgrouting::contraction::Pgr_linear::calculateVertices
void calculateVertices(G &graph)
Definition: pgr_linearContraction.hpp:79
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
Identifiers::size
size_t size() const
Definition: identifiers.hpp:78
Identifiers::clear
void clear()
Definition: identifiers.hpp:84
pgrouting::contraction::Pgr_linear::last_edge_id
int64_t last_edge_id
Definition: pgr_linearContraction.hpp:193
pgrouting::contraction::Pgr_linear::doContraction
void doContraction(G &graph, Identifiers< V > forbidden_vertices)
Definition: pgr_linearContraction.hpp:91
pgrouting::contraction::Pgr_linear::V
G::V V
Definition: pgr_linearContraction.hpp:51
pgrouting::contraction::Pgr_linear::get_next_id
int64_t get_next_id()
Definition: pgr_linearContraction.hpp:64
Identifiers::empty
bool empty() const
Definition: identifiers.hpp:79
pgrouting::contraction::Pgr_linear::process_shortcut
void process_shortcut(G &graph, V u, V v, V w)
u -—e1{v1}-—> v -—e2{v2}-—> w
Definition: pgr_linearContraction.hpp:166
pgrouting::contraction::Pgr_linear::m_forbiddenVertices
Identifiers< V > m_forbiddenVertices
Definition: pgr_linearContraction.hpp:191
Identifiers::front
T front() const
Definition: identifiers.hpp:80
Identifiers::has
bool has(const T other) const
true ids() has element
Definition: identifiers.hpp:98
Identifiers< V >
pgrouting::contraction::Pgr_linear::one_cycle
void one_cycle(G &graph, V v)
Definition: pgr_linearContraction.hpp:103