PGROUTING  3.2
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 62 of file pgr_bidirectional.hpp.

Member Typedef Documentation

◆ Cost_Vertex_pair

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

Definition at line 67 of file pgr_bidirectional.hpp.

◆ E

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

Definition at line 65 of file pgr_bidirectional.hpp.

◆ Priority_queue

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 71 of file pgr_bidirectional.hpp.

◆ V

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

Definition at line 64 of file pgr_bidirectional.hpp.

Constructor & Destructor Documentation

◆ Pgr_bidirectional()

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

Definition at line 75 of file pgr_bidirectional.hpp.

75  :
76  graph(pgraph),
77  INF((std::numeric_limits<double>::max)()),
78  best_cost(0) {
79  m_log << "constructor\n";
80  }

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

◆ ~Pgr_bidirectional()

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

Member Function Documentation

◆ bidirectional()

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

Definition at line 122 of file pgr_bidirectional.hpp.

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

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

◆ clean_log()

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

Definition at line 85 of file pgr_bidirectional.hpp.

85 {m_log.clear();}

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

◆ clear()

◆ explore_backward()

◆ explore_forward()

◆ found()

◆ initialize()

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

Definition at line 103 of file pgr_bidirectional.hpp.

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

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

◆ log()

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

Definition at line 84 of file pgr_bidirectional.hpp.

84 {return m_log.str();}

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

Referenced by pgr_bdAstar(), and pgr_bdDijkstra().

Member Data Documentation

◆ backward_cost

◆ backward_edge

◆ backward_finished

◆ backward_predecessor

◆ backward_queue

◆ best_cost

◆ cost_only

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

Definition at line 227 of file pgr_bidirectional.hpp.

◆ forward_cost

◆ forward_edge

◆ forward_finished

◆ forward_predecessor

◆ forward_queue

◆ graph

◆ INF

◆ m_log

◆ v_min_node

◆ v_source

◆ v_target


The documentation for this class was generated from the following file:
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::explore_backward
virtual void explore_backward(const Cost_Vertex_pair &node)=0
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_bidirectional::v_source
V v_source
source descriptor
Definition: pgr_bidirectional.hpp:220
pgrouting::bidirectional::Pgr_bidirectional::INF
double INF
infinity
Definition: pgr_bidirectional.hpp:224
pgrouting::bidirectional::Pgr_bidirectional::found
bool found(const V &node)
Definition: pgr_bidirectional.hpp:196
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_bidirectional::v_min_node
V v_min_node
target descriptor
Definition: pgr_bidirectional.hpp:222
pgrouting::bidirectional::Pgr_bidirectional::forward_finished
std::vector< bool > forward_finished
Definition: pgr_bidirectional.hpp:238
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::bidirectional::Pgr_bidirectional::best_cost
double best_cost
Definition: pgr_bidirectional.hpp:226
pgrouting::bidirectional::Pgr_bidirectional::clear
void clear()
Definition: pgr_bidirectional.hpp:86
pgrouting::bidirectional::Pgr_bidirectional::forward_predecessor
std::vector< V > forward_predecessor
Definition: pgr_bidirectional.hpp:240
pgrouting::bidirectional::Pgr_bidirectional::initialize
void initialize()
Definition: pgr_bidirectional.hpp:103
pgrouting::bidirectional::Pgr_bidirectional::backward_edge
std::vector< int64_t > backward_edge
Definition: pgr_bidirectional.hpp:234
pgrouting::bidirectional::Pgr_bidirectional::explore_forward
virtual void explore_forward(const Cost_Vertex_pair &node)=0