PGROUTING  2.5
pgrouting::bidirectional::Pgr_bidirectional< G > Class Template Referenceabstract

#include "pgr_bidirectional.hpp"

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

Public Member Functions

 Pgr_bidirectional (G &pgraph)
 
 ~Pgr_bidirectional ()=default
 
void clean_log ()
 
void clear ()
 
std::string log () const
 

Protected Types

typedef std::pair< double, VCost_Vertex_pair
 
typedef G::E E
 
typedef std::priority_queue< Cost_Vertex_pair, std::vector< Cost_Vertex_pair >, std::greater< Cost_Vertex_pair > > Priority_queue
 
typedef G::V V
 

Protected Member Functions

Path bidirectional (bool only_cost)
 
virtual void explore_backward (const Cost_Vertex_pair &node)=0
 
virtual void explore_forward (const Cost_Vertex_pair &node)=0
 
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...
 

Detailed Description

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

Definition at line 60 of file pgr_bidirectional.hpp.

Member Typedef Documentation

template<typename G>
typedef std::pair<double, V> pgrouting::bidirectional::Pgr_bidirectional< G >::Cost_Vertex_pair
protected

Definition at line 65 of file pgr_bidirectional.hpp.

template<typename G>
typedef G::E pgrouting::bidirectional::Pgr_bidirectional< G >::E
protected

Definition at line 63 of file pgr_bidirectional.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
protected

Definition at line 69 of file pgr_bidirectional.hpp.

template<typename G>
typedef G::V pgrouting::bidirectional::Pgr_bidirectional< G >::V
protected

Definition at line 62 of file pgr_bidirectional.hpp.

Constructor & Destructor Documentation

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

Definition at line 73 of file pgr_bidirectional.hpp.

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

73  :
74  graph(pgraph),
75  INF((std::numeric_limits<double>::max)()) {
76  m_log << "constructor\n";
77  };

Here is the call graph for this function:

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

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

Here is the caller graph for this function:

Member Function Documentation

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

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 ( )
inline
template<typename G>
void pgrouting::bidirectional::Pgr_bidirectional< G >::clear ( )
inline

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>
virtual void pgrouting::bidirectional::Pgr_bidirectional< G >::explore_backward ( const Cost_Vertex_pair node)
protectedpure virtual
template<typename G>
virtual void pgrouting::bidirectional::Pgr_bidirectional< G >::explore_forward ( const Cost_Vertex_pair node)
protectedpure virtual
template<typename G>
bool pgrouting::bidirectional::Pgr_bidirectional< G >::found ( const V node)
inlineprotected

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 ( )
inlineprotected

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
inline

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:

Member Data Documentation

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

Definition at line 226 of file pgr_bidirectional.hpp.


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