PGROUTING  2.5
pgrouting::bidirectional::Pgr_bdDijkstra< G > Class Template Reference

#include "pgr_bdDijkstra.hpp"

Inheritance diagram for pgrouting::bidirectional::Pgr_bdDijkstra< G >:
Collaboration diagram for pgrouting::bidirectional::Pgr_bdDijkstra< G >:

Public Member Functions

 Pgr_bdDijkstra (G &pgraph)
 
 ~Pgr_bdDijkstra ()=default
 
void clean_log ()
 
void clear ()
 
std::string log () const
 
Path pgr_bdDijkstra (V start_vertex, V end_vertex, bool only_cost)
 

Protected Types

typedef std::priority_queue< Cost_Vertex_pair, std::vector< Cost_Vertex_pair >, std::greater< Cost_Vertex_pair > > Priority_queue
 

Protected Member Functions

Path bidirectional (bool only_cost)
 
bool found (const V &node)
 
void initialize ()
 

Protected Attributes

std::vector< double > backward_cost
 
std::vector< int64_t > backward_edge
 
std::vector< bool > backward_finished
 
std::vector< Vbackward_predecessor
 
Priority_queue backward_queue
 
double best_cost
 
bool cost_only
 
std::vector< double > forward_cost
 
std::vector< int64_t > forward_edge
 
std::vector< bool > forward_finished
 
std::vector< Vforward_predecessor
 
Priority_queue forward_queue
 
G & graph
 
double INF
 infinity More...
 
std::ostringstream m_log
 
V v_min_node
 target descriptor More...
 
V v_source
 source descriptor More...
 
V v_target
 target descriptor More...
 

Private Types

typedef Pgr_bidirectional< G >::Cost_Vertex_pair Cost_Vertex_pair
 
typedef Pgr_bidirectional< G >::E E
 
typedef Pgr_bidirectional< G >::V V
 

Private Member Functions

void explore_backward (const Cost_Vertex_pair &node)
 
void explore_forward (const Cost_Vertex_pair &node)
 

Detailed Description

template<typename G>
class pgrouting::bidirectional::Pgr_bdDijkstra< G >

Definition at line 49 of file pgr_bdDijkstra.hpp.

Member Typedef Documentation

Definition at line 52 of file pgr_bdDijkstra.hpp.

template<typename G>
typedef Pgr_bidirectional<G>::E pgrouting::bidirectional::Pgr_bdDijkstra< G >::E
private

Definition at line 51 of file pgr_bdDijkstra.hpp.

template<typename G>
typedef std::priority_queue< Cost_Vertex_pair, std::vector<Cost_Vertex_pair>, std::greater<Cost_Vertex_pair> > pgrouting::bidirectional::Pgr_bidirectional< G >::Priority_queue
protectedinherited

Definition at line 69 of file pgr_bidirectional.hpp.

template<typename G>
typedef Pgr_bidirectional<G>::V pgrouting::bidirectional::Pgr_bdDijkstra< G >::V
private

Definition at line 50 of file pgr_bdDijkstra.hpp.

Constructor & Destructor Documentation

template<typename G>
pgrouting::bidirectional::Pgr_bdDijkstra< G >::Pgr_bdDijkstra ( G &  pgraph)
inlineexplicit

Definition at line 75 of file pgr_bdDijkstra.hpp.

References pgrouting::bidirectional::Pgr_bidirectional< G >::m_log, and pgrouting::bidirectional::Pgr_bdDijkstra< G >::~Pgr_bdDijkstra().

75  :
76  Pgr_bidirectional<G>(pgraph) {
77  m_log << "pgr_bdDijkstra constructor\n";
78  }

Here is the call graph for this function:

template<typename G>
pgrouting::bidirectional::Pgr_bdDijkstra< G >::~Pgr_bdDijkstra ( )
default

Referenced by pgrouting::bidirectional::Pgr_bdDijkstra< G >::Pgr_bdDijkstra().

Here is the caller graph for this function:

Member Function Documentation

template<typename G>
Path pgrouting::bidirectional::Pgr_bidirectional< G >::bidirectional ( bool  only_cost)
inlineprotectedinherited

Definition at line 119 of file pgr_bidirectional.hpp.

References Path::append(), pgrouting::bidirectional::Pgr_bidirectional< G >::backward_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_finished, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_predecessor, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_queue, pgrouting::bidirectional::Pgr_bidirectional< G >::best_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::explore_backward(), pgrouting::bidirectional::Pgr_bidirectional< G >::explore_forward(), pgrouting::bidirectional::Pgr_bidirectional< G >::forward_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_finished, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_predecessor, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_queue, pgrouting::bidirectional::Pgr_bidirectional< G >::found(), pgrouting::bidirectional::Pgr_bidirectional< G >::graph, pgrouting::bidirectional::Pgr_bidirectional< G >::INF, pgrouting::bidirectional::Pgr_bidirectional< G >::initialize(), pgrouting::bidirectional::Pgr_bidirectional< G >::m_log, Path::reverse(), pgrouting::bidirectional::Pgr_bidirectional< G >::v_min_node, pgrouting::bidirectional::Pgr_bidirectional< G >::v_source, and pgrouting::bidirectional::Pgr_bidirectional< G >::v_target.

Referenced by pgrouting::bidirectional::Pgr_bdAstar< G >::pgr_bdAstar(), and pgrouting::bidirectional::Pgr_bdDijkstra< G >::pgr_bdDijkstra().

119  {
120  m_log << "bidir_astar\n";
121 
123 
124  forward_cost[v_source] = 0;
125  forward_queue.push(std::make_pair(0.0, v_source));
126 
127 
128  backward_cost[v_target] = 0;
129  backward_queue.push(std::make_pair(0.0, v_target));
130 
131  while (!forward_queue.empty() && !backward_queue.empty()) {
132  auto forward_node = forward_queue.top();
133  auto backward_node = backward_queue.top();
134  /*
135  * done: there is no path with lower cost
136  */
137  if (forward_node.first == INF || backward_node.first == INF) {
138  break;
139  }
140 
141  /*
142  * Explore from the cheapest side
143  */
144  if (backward_node.first < forward_node.first) {
145  backward_queue.pop();
146  if (!backward_finished[backward_node.second]) {
147  explore_backward(backward_node);
148  }
149  if (found(backward_node.second)) {
150  break;
151  }
152  } else {
153  forward_queue.pop();
154  if (!forward_finished[forward_node.second]) {
155  explore_forward(forward_node);
156  }
157  if (found(forward_node.second)) {
158  break;
159  }
160  }
161  }
162 
163  if (best_cost == INF) return Path();
164 
165  Path forward_path(
166  graph,
167  v_source,
168  v_min_node,
170  forward_cost,
171  only_cost,
172  true);
173  Path backward_path(
174  graph,
175  v_target,
176  v_min_node,
179  only_cost,
180  false);
181  m_log << forward_path;
182  backward_path.reverse();
183  m_log << backward_path;
184  forward_path.append(backward_path);
185  m_log << forward_path;
186  return forward_path;
187  }
virtual void explore_forward(const Cost_Vertex_pair &node)=0
virtual void explore_backward(const Cost_Vertex_pair &node)=0

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename G>
void pgrouting::bidirectional::Pgr_bidirectional< G >::clean_log ( )
inlineinherited
template<typename G>
void pgrouting::bidirectional::Pgr_bidirectional< G >::clear ( )
inlineinherited

Definition at line 83 of file pgr_bidirectional.hpp.

References pgrouting::bidirectional::Pgr_bidirectional< G >::backward_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_edge, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_finished, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_predecessor, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_queue, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_edge, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_finished, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_predecessor, and pgrouting::bidirectional::Pgr_bidirectional< G >::forward_queue.

Referenced by pgrouting::bidirectional::Pgr_bidirectional< G >::initialize(), pgr_bdAstar(), and pgr_bdDijkstra().

83  {
84  while (!forward_queue.empty()) forward_queue.pop();
85  while (!backward_queue.empty()) backward_queue.pop();
86 
87  backward_finished.clear();
88  backward_edge.clear();
89  backward_predecessor.clear();
90  backward_cost.clear();
91 
92  forward_finished.clear();
93  forward_edge.clear();
94  forward_predecessor.clear();
95  forward_cost.clear();
96  }

Here is the caller graph for this function:

template<typename G>
void pgrouting::bidirectional::Pgr_bdDijkstra< G >::explore_backward ( const Cost_Vertex_pair node)
inlineprivatevirtual

Implements pgrouting::bidirectional::Pgr_bidirectional< G >.

Definition at line 122 of file pgr_bdDijkstra.hpp.

References pgrouting::bidirectional::Pgr_bidirectional< G >::backward_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_edge, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_finished, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_predecessor, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_queue, and pgrouting::bidirectional::Pgr_bidirectional< G >::graph.

122  {
123  typename G::EI_i in, in_end;
124 
125  auto current_cost = node.first;
126  auto current_node = node.second;
127 
128  for (boost::tie(in, in_end) = in_edges(current_node, graph.graph);
129  in != in_end; ++in) {
130  auto edge_cost = graph[*in].cost;
131  auto next_node = graph.adjacent(current_node, *in);
132 
133  if (backward_finished[next_node]) continue;
134 
135  if (edge_cost + current_cost < backward_cost[next_node]) {
136  backward_cost[next_node] = edge_cost + current_cost;
137  backward_predecessor[next_node] = current_node;
138  backward_edge[next_node] = graph[*in].id;
139  backward_queue.push({backward_cost[next_node], next_node});
140  }
141  }
142  backward_finished[current_node] = true;
143  }
template<typename G>
void pgrouting::bidirectional::Pgr_bdDijkstra< G >::explore_forward ( const Cost_Vertex_pair node)
inlineprivatevirtual

Implements pgrouting::bidirectional::Pgr_bidirectional< G >.

Definition at line 99 of file pgr_bdDijkstra.hpp.

References pgrouting::bidirectional::Pgr_bidirectional< G >::forward_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_edge, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_finished, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_predecessor, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_queue, and pgrouting::bidirectional::Pgr_bidirectional< G >::graph.

99  {
100  typename G::EO_i out, out_end;
101 
102  auto current_cost = node.first;
103  auto current_node = node.second;
104 
105  for (boost::tie(out, out_end) = out_edges(current_node, graph.graph);
106  out != out_end; ++out) {
107  auto edge_cost = graph[*out].cost;
108  auto next_node = graph.adjacent(current_node, *out);
109 
110  if (forward_finished[next_node]) continue;
111 
112  if (edge_cost + current_cost < forward_cost[next_node]) {
113  forward_cost[next_node] = edge_cost + current_cost;
114  forward_predecessor[next_node] = current_node;
115  forward_edge[next_node] = graph[*out].id;
116  forward_queue.push({forward_cost[next_node], next_node});
117  }
118  }
119  forward_finished[current_node] = true;
120  }
template<typename G>
bool pgrouting::bidirectional::Pgr_bidirectional< G >::found ( const V node)
inlineprotectedinherited

Definition at line 191 of file pgr_bidirectional.hpp.

References pgrouting::bidirectional::Pgr_bidirectional< G >::backward_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_finished, pgrouting::bidirectional::Pgr_bidirectional< G >::best_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::explore_backward(), pgrouting::bidirectional::Pgr_bidirectional< G >::explore_forward(), pgrouting::bidirectional::Pgr_bidirectional< G >::forward_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_finished, and pgrouting::bidirectional::Pgr_bidirectional< G >::v_min_node.

Referenced by pgrouting::bidirectional::Pgr_bidirectional< G >::bidirectional().

191  {
192  /*
193  * Update common node
194  */
195  if (forward_finished[node] && backward_finished[node]) {
196  if (best_cost >= forward_cost[node] + backward_cost[node]) {
197  v_min_node = node;
198  best_cost = forward_cost[node] + backward_cost[node];
199  return false;
200  } else {
201  return true;
202  }
203  }
204  return false;
205  }

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename G>
void pgrouting::bidirectional::Pgr_bidirectional< G >::initialize ( )
inlineprotectedinherited

Definition at line 100 of file pgr_bidirectional.hpp.

References pgrouting::bidirectional::Pgr_bidirectional< G >::backward_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_edge, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_finished, pgrouting::bidirectional::Pgr_bidirectional< G >::backward_predecessor, pgrouting::bidirectional::Pgr_bidirectional< G >::best_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::clear(), pgrouting::bidirectional::Pgr_bidirectional< G >::forward_cost, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_edge, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_finished, pgrouting::bidirectional::Pgr_bidirectional< G >::forward_predecessor, pgrouting::bidirectional::Pgr_bidirectional< G >::graph, pgrouting::bidirectional::Pgr_bidirectional< G >::INF, pgrouting::bidirectional::Pgr_bidirectional< G >::m_log, and pgrouting::bidirectional::Pgr_bidirectional< G >::v_min_node.

Referenced by pgrouting::bidirectional::Pgr_bidirectional< G >::bidirectional().

100  {
101  m_log << "initializing\n";
102  clear();
103  forward_predecessor.resize(graph.num_vertices());
104  forward_finished.resize(graph.num_vertices(), false);
105  forward_edge.resize(graph.num_vertices(), -1);
106  forward_cost.resize(graph.num_vertices(), INF);
107  std::iota(forward_predecessor.begin(), forward_predecessor.end(), 0);
108 
109  backward_predecessor.resize(graph.num_vertices());
110  backward_finished.resize(graph.num_vertices(), false);
111  backward_edge.resize(graph.num_vertices(), -1);
112  backward_cost.resize(graph.num_vertices(), INF);
113  std::iota(backward_predecessor.begin(), backward_predecessor.end(), 0);
114 
115  v_min_node = -1;
116  best_cost = INF;
117  }

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename G>
std::string pgrouting::bidirectional::Pgr_bidirectional< G >::log ( ) const
inlineinherited

Definition at line 81 of file pgr_bidirectional.hpp.

References pgrouting::bidirectional::Pgr_bidirectional< G >::m_log.

Referenced by pgr_bdAstar(), and pgr_bdDijkstra().

81 {return m_log.str();}

Here is the caller graph for this function:

template<typename G>
Path pgrouting::bidirectional::Pgr_bdDijkstra< G >::pgr_bdDijkstra ( V  start_vertex,
V  end_vertex,
bool  only_cost 
)
inline

Definition at line 82 of file pgr_bdDijkstra.hpp.

References pgrouting::bidirectional::Pgr_bidirectional< G >::bidirectional(), pgrouting::bidirectional::Pgr_bidirectional< G >::m_log, pgrouting::bidirectional::Pgr_bidirectional< G >::v_source, and pgrouting::bidirectional::Pgr_bidirectional< G >::v_target.

Referenced by pgr_bdDijkstra().

82  {
83  m_log << "pgr_bdDijkstra\n";
84  v_source = start_vertex;
85  v_target = end_vertex;
86 
87  if (v_source == v_target) {
88  return Path(v_source, v_target);
89  }
90  return bidirectional(only_cost);
91  }

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

template<typename G>
bool pgrouting::bidirectional::Pgr_bidirectional< G >::cost_only
protectedinherited

Definition at line 226 of file pgr_bidirectional.hpp.


The documentation for this class was generated from the following file: