PGROUTING  3.2
pgr_bdDijkstra.hpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 File: pgr_bdDijkstra.hpp
4 
5 Copyright (c) 2016 Celia Virginia Vergara Castillo
7 
8 ------
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 
24  ********************************************************************PGR-GNU*/
25 
26 #ifndef INCLUDE_BDDIJKSTRA_PGR_BDDIJKSTRA_HPP_
27 #define INCLUDE_BDDIJKSTRA_PGR_BDDIJKSTRA_HPP_
28 #pragma once
29 
30 
32 
33 #include <string>
34 #include <queue>
35 #include <utility>
36 #include <vector>
37 #include <limits>
38 #include <functional>
39 
40 
42 
43 
44 namespace pgrouting {
45 namespace bidirectional {
46 
47 
48 template < typename G >
49 class Pgr_bdDijkstra : public Pgr_bidirectional<G> {
50  typedef typename Pgr_bidirectional<G>::V V;
51  typedef typename Pgr_bidirectional<G>::E E;
53 
58 
64 
70 
71 
73 
74  public:
75  explicit Pgr_bdDijkstra(G &pgraph):
76  Pgr_bidirectional<G>(pgraph) {
77  m_log << "pgr_bdDijkstra constructor\n";
78  }
79 
80  ~Pgr_bdDijkstra() = default;
81 
82  Path pgr_bdDijkstra(V start_vertex, V end_vertex, bool only_cost) {
83  m_log << "pgr_bdDijkstra\n";
84  v_source = start_vertex;
85  v_target = end_vertex;
86 
87  return bidirectional(only_cost);
88  }
89 
90 
93 
94 
95  private:
96  void explore_forward(const Cost_Vertex_pair &node) {
97  typename G::EO_i out, out_end;
98 
99  auto current_cost = node.first;
100  auto current_node = node.second;
101 
102  for (boost::tie(out, out_end) = out_edges(current_node, graph.graph);
103  out != out_end; ++out) {
104  auto edge_cost = graph[*out].cost;
105  auto next_node = graph.adjacent(current_node, *out);
106 
107  if (forward_finished[next_node]) continue;
108 
109  if (edge_cost + current_cost < forward_cost[next_node]) {
110  forward_cost[next_node] = edge_cost + current_cost;
111  forward_predecessor[next_node] = current_node;
112  forward_edge[next_node] = graph[*out].id;
113  forward_queue.push({forward_cost[next_node], next_node});
114  }
115  }
116  forward_finished[current_node] = true;
117  }
118 
119  void explore_backward(const Cost_Vertex_pair &node) {
120  typename G::EI_i in, in_end;
121 
122  auto current_cost = node.first;
123  auto current_node = node.second;
124 
125  for (boost::tie(in, in_end) = in_edges(current_node, graph.graph);
126  in != in_end; ++in) {
127  auto edge_cost = graph[*in].cost;
128  auto next_node = graph.adjacent(current_node, *in);
129 
130  if (backward_finished[next_node]) continue;
131 
132  if (edge_cost + current_cost < backward_cost[next_node]) {
133  backward_cost[next_node] = edge_cost + current_cost;
134  backward_predecessor[next_node] = current_node;
135  backward_edge[next_node] = graph[*in].id;
136  backward_queue.push({backward_cost[next_node], next_node});
137  }
138  }
139  backward_finished[current_node] = true;
140  }
141 };
142 
143 } // namespace bidirectional
144 } // namespace pgrouting
145 
146 #endif // INCLUDE_BDDIJKSTRA_PGR_BDDIJKSTRA_HPP_
Path
Definition: basePath_SSEC.hpp:47
pgrouting::bidirectional::Pgr_bidirectional::forward_edge
std::vector< int64_t > forward_edge
Definition: pgr_bidirectional.hpp:239
pgrouting::bidirectional::Pgr_bidirectional::backward_predecessor
std::vector< V > backward_predecessor
Definition: pgr_bidirectional.hpp:235
pgrouting::bidirectional::Pgr_bidirectional::forward_queue
Priority_queue forward_queue
Definition: pgr_bidirectional.hpp:230
pgrouting::bidirectional::Pgr_bidirectional::m_log
std::ostringstream m_log
Definition: pgr_bidirectional.hpp:229
pgrouting::bidirectional::Pgr_bidirectional::v_target
V v_target
target descriptor
Definition: pgr_bidirectional.hpp:221
pgrouting::bidirectional::Pgr_bidirectional::backward_finished
std::vector< bool > backward_finished
Definition: pgr_bidirectional.hpp:233
pgrouting::bidirectional::Pgr_bdDijkstra::~Pgr_bdDijkstra
~Pgr_bdDijkstra()=default
pgrouting::bidirectional::Pgr_bdDijkstra::V
Pgr_bidirectional< G >::V V
Definition: pgr_bdDijkstra.hpp:50
pgrouting::bidirectional::Pgr_bidirectional::Cost_Vertex_pair
std::pair< double, V > Cost_Vertex_pair
Definition: pgr_bidirectional.hpp:67
pgrouting::bidirectional::Pgr_bidirectional::v_source
V v_source
source descriptor
Definition: pgr_bidirectional.hpp:220
pgrouting::bidirectional::Pgr_bidirectional
Definition: pgr_bidirectional.hpp:62
pgrouting::bidirectional::Pgr_bidirectional::graph
G & graph
Definition: pgr_bidirectional.hpp:219
pgrouting::bidirectional::Pgr_bidirectional::forward_cost
std::vector< double > forward_cost
Definition: pgr_bidirectional.hpp:241
pgrouting::bidirectional::Pgr_bdDijkstra::explore_backward
void explore_backward(const Cost_Vertex_pair &node)
Definition: pgr_bdDijkstra.hpp:119
pgrouting::bidirectional::Pgr_bidirectional::forward_finished
std::vector< bool > forward_finished
Definition: pgr_bidirectional.hpp:238
pgrouting::bidirectional::Pgr_bdDijkstra::Pgr_bdDijkstra
Pgr_bdDijkstra(G &pgraph)
Definition: pgr_bdDijkstra.hpp:75
pgrouting::bidirectional::Pgr_bidirectional::V
G::V V
Definition: pgr_bidirectional.hpp:64
pgrouting::bidirectional::Pgr_bdDijkstra::E
Pgr_bidirectional< G >::E E
Definition: pgr_bdDijkstra.hpp:51
pgrouting::bidirectional::Pgr_bidirectional::bidirectional
Path bidirectional(bool only_cost)
Definition: pgr_bidirectional.hpp:122
pgrouting::bidirectional::Pgr_bdDijkstra
Definition: pgr_bdDijkstra.hpp:49
pgrouting::bidirectional::Pgr_bidirectional::backward_cost
std::vector< double > backward_cost
Definition: pgr_bidirectional.hpp:236
pgrouting::bidirectional::Pgr_bidirectional::backward_queue
Priority_queue backward_queue
Definition: pgr_bidirectional.hpp:231
pgrouting::alphashape::G
graph::Pgr_base_graph< BG, XY_vertex, Basic_edge > G
Definition: pgr_alphaShape.h:56
pgrouting::bidirectional::Pgr_bdDijkstra::explore_forward
void explore_forward(const Cost_Vertex_pair &node)
Definition: pgr_bdDijkstra.hpp:96
pgrouting::bidirectional::Pgr_bidirectional::E
G::E E
Definition: pgr_bidirectional.hpp:65
pgr_bidirectional.hpp
pgrouting::bidirectional::Pgr_bdDijkstra::pgr_bdDijkstra
Path pgr_bdDijkstra(V start_vertex, V end_vertex, bool only_cost)
Definition: pgr_bdDijkstra.hpp:82
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56
pgrouting::bidirectional::Pgr_bidirectional::forward_predecessor
std::vector< V > forward_predecessor
Definition: pgr_bidirectional.hpp:240
pgrouting::bidirectional::Pgr_bidirectional::backward_edge
std::vector< int64_t > backward_edge
Definition: pgr_bidirectional.hpp:234
pgrouting::bidirectional::Pgr_bdDijkstra::Cost_Vertex_pair
Pgr_bidirectional< G >::Cost_Vertex_pair Cost_Vertex_pair
Definition: pgr_bdDijkstra.hpp:52
basePath_SSEC.hpp