PGROUTING  3.2
pgr_contract.hpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: pgr_contract.hpp
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
7 
8 Function's developer:
9 Copyright (c) 2016 Rohith Reddy
10 Mail:
11 
12 ------
13 
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 
28  ********************************************************************PGR-GNU*/
29 
30 #ifndef INCLUDE_CONTRACTION_PGR_CONTRACT_HPP_
31 #define INCLUDE_CONTRACTION_PGR_CONTRACT_HPP_
32 #pragma once
33 
34 #include <deque>
35 #include <vector>
36 #include "cpp_common/pgr_assert.h"
37 
42 
43 namespace pgrouting {
44 namespace contraction {
45 
46 bool is_valid_contraction(int number);
47 
48 template < class G >
49 class Pgr_contract {
50  typedef typename G::V V;
51 
52  public:
54  G &graph,
55  Identifiers<V> forbidden_vertices,
56  std::vector<int64_t> contraction_order,
57  int64_t max_cycles
58  ) {
59  std::deque<int64_t> contract_order;
60  // push -1 to indicate the start of the queue
61  contract_order.push_back(-1);
62  contract_order.insert(
63  contract_order.end(),
64  contraction_order.begin(), contraction_order.end());
65  for (int64_t i = 0; i < max_cycles; ++i) {
66  int64_t front = contract_order.front();
67  contract_order.pop_front();
68  contract_order.push_back(front);
69  auto kind = contract_order.front();
70  while (kind != -1) {
71  one_cycle(graph, kind, forbidden_vertices);
72  contract_order.pop_front();
73  contract_order.push_back(front);
74  kind = contract_order.front();
75  }
76  }
77  }
78 
79 
80  private:
81  void one_cycle(
82  G &graph,
83  int64_t kind,
84  Identifiers<V> &forbidden_vertices) {
85  switch (kind) {
86  case -1:
87  pgassert(false);
88  break;
89 
90  case 1:
91  perform_deadEnd(graph, forbidden_vertices);
92  break;
93 
94 
95  case 2:
96  perform_linear(graph, forbidden_vertices);
97  break;
98  default:
99  pgassert(false);
100  break;
101  }
102  }
103 
104  void perform_deadEnd(G &graph,
105  Identifiers<V> forbidden_vertices) {
106  Pgr_deadend<G> deadendContractor;
107  deadendContractor.setForbiddenVertices(forbidden_vertices);
108 
109  deadendContractor.calculateVertices(graph);
110  try {
111  deadendContractor.doContraction(graph);
112  }
113  catch ( ... ) {
114  throw;
115  }
116  }
117 
118 
119  void perform_linear(G &graph,
120  Identifiers<V>& forbidden_vertices) {
121  Pgr_linear<G> linearContractor;
122  try {
123  linearContractor(graph, forbidden_vertices);
124  }
125  catch ( ... ) {
126  throw;
127  }
128  }
129 };
130 
131 } // namespace contraction
132 } // namespace pgrouting
133 
134 #endif // INCLUDE_CONTRACTION_PGR_CONTRACT_HPP_
pgrouting::contraction::Pgr_deadend::calculateVertices
void calculateVertices(G &graph)
Definition: pgr_deadEndContraction.hpp:59
pgrouting::contraction::Pgr_linear
Definition: pgr_linearContraction.hpp:49
pgrouting::contraction::Pgr_deadend::doContraction
void doContraction(G &graph)
Definition: pgr_deadEndContraction.hpp:78
pgrouting::contraction::Pgr_contract::perform_deadEnd
void perform_deadEnd(G &graph, Identifiers< V > forbidden_vertices)
Definition: pgr_contract.hpp:104
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgr_linearContraction.hpp
ch_graphs.hpp
pgrouting::contraction::Pgr_deadend
Definition: pgr_deadEndContraction.hpp:45
pgr_assert.h
An assert functionality that uses C++ throw().
pgr_deadEndContraction.hpp
pgrouting::contraction::Pgr_deadend::setForbiddenVertices
void setForbiddenVertices(Identifiers< V > forbidden_vertices)
Definition: pgr_deadEndContraction.hpp:53
pgrouting::contraction::Pgr_contract::perform_linear
void perform_linear(G &graph, Identifiers< V > &forbidden_vertices)
Definition: pgr_contract.hpp:119
pgrouting::contraction::Pgr_contract::Pgr_contract
Pgr_contract(G &graph, Identifiers< V > forbidden_vertices, std::vector< int64_t > contraction_order, int64_t max_cycles)
Definition: pgr_contract.hpp:53
pgrouting::contraction::Pgr_contract::one_cycle
void one_cycle(G &graph, int64_t kind, Identifiers< V > &forbidden_vertices)
Definition: pgr_contract.hpp:81
pgrouting::alphashape::G
graph::Pgr_base_graph< BG, XY_vertex, Basic_edge > G
Definition: pgr_alphaShape.h:56
pgrouting::contraction::Pgr_contract
Definition: pgr_contract.hpp:49
pgrouting::contraction::is_valid_contraction
bool is_valid_contraction(int number)
Definition: pgr_contract.cpp:35
pgrouting::alphashape::V
boost::graph_traits< BG >::vertex_descriptor V
Definition: pgr_alphaShape.h:58
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56
pgr_contractionGraph.hpp
Identifiers< V >
pgrouting::contraction::Pgr_contract::V
G::V V
Definition: pgr_contract.hpp:50