PGROUTING  3.2
pgrouting::Pgr_dijkstra< G > Class Template Reference

#include "pgr_dijkstra.hpp"

Collaboration diagram for pgrouting::Pgr_dijkstra< G >:

Classes

class  dijkstra_distance_visitor
 class for stopping when a distance/cost has being surpassed More...
 
class  dijkstra_distance_visitor_no_init
 class for stopping when a distance/cost has being surpassed More...
 
class  dijkstra_many_goal_visitor
 class for stopping when all targets are found More...
 

Public Types

typedef G::E E
 
typedef G::V V
 

Public Member Functions

drivingDistance
Path drivingDistance (G &graph, int64_t start_vertex, double distance)
 1 to distance More...
 
std::deque< PathdrivingDistance (G &graph, const std::vector< int64_t > &start_vertex, double distance, bool equicost, std::ostringstream &the_log)
 

Private Attributes

members
std::vector< Vpredecessors
 
std::vector< double > distances
 
std::deque< VnodesInDistance
 
std::ostringstream log
 

Dijkstra

Path dijkstra (G &graph, int64_t start_vertex, int64_t end_vertex, bool only_cost=false)
 Dijkstra 1 to 1. More...
 
std::deque< Pathdijkstra (G &graph, int64_t start_vertex, const std::vector< int64_t > &end_vertex, bool only_cost, size_t n_goals)
 Dijkstra 1 to many. More...
 
std::deque< Pathdijkstra (G &graph, const std::vector< int64_t > &start_vertex, int64_t end_vertex, bool only_cost)
 
std::deque< Pathdijkstra (G &graph, const std::vector< int64_t > &start_vertex, const std::vector< int64_t > &end_vertex, bool only_cost, size_t n_goals=(std::numeric_limits< size_t >::max)())
 
std::deque< Pathdijkstra (G &graph, const std::vector< pgr_combination_t > &combinations, bool only_cost, size_t n_goals)
 
bool dijkstra_1_to_1 (G &graph, V source, V target)
 Call to Dijkstra 1 source to 1 target. More...
 
bool dijkstra_1_to_distance (G &graph, V source, double distance)
 Call to Dijkstra 1 to distance. More...
 
bool dijkstra_1_to_distance_no_init (G &graph, V source, double distance)
 Call to Dijkstra 1 to distance no init. More...
 
bool execute_drivingDistance (G &graph, int64_t start_vertex, double distance)
 to use with driving distance More...
 
bool execute_drivingDistance_no_init (G &graph, V start_vertex, double distance)
 to use with driving distance More...
 
std::deque< PathdrivingDistance_with_equicost (G &graph, const std::vector< int64_t > &start_vertex, double distance)
 
std::deque< Pathget_drivingDistance_with_equicost_paths (G &graph, const std::vector< int64_t > &start_vertex, std::deque< std::vector< V > > &pred, double distance)
 gets results in form of a container of paths More...
 
std::deque< PathdrivingDistance_no_equicost (G &graph, const std::vector< int64_t > &start_vertex, double distance)
 
bool dijkstra_1_to_many (G &graph, V source, const std::vector< V > &targets, size_t n_goals)
 Dijkstra 1 source to many targets. More...
 
void clear ()
 
std::deque< Pathget_paths (const G &graph, V source, std::vector< V > &targets, bool only_cost) const
 

Detailed Description

template<class G>
class pgrouting::Pgr_dijkstra< G >

Definition at line 62 of file pgr_dijkstra.hpp.

Member Typedef Documentation

◆ E

template<class G >
typedef G::E pgrouting::Pgr_dijkstra< G >::E

Definition at line 105 of file pgr_dijkstra.hpp.

◆ V

template<class G >
typedef G::V pgrouting::Pgr_dijkstra< G >::V

Definition at line 104 of file pgr_dijkstra.hpp.

Member Function Documentation

◆ clear()

◆ dijkstra() [1/5]

template<class G >
std::deque<Path> pgrouting::Pgr_dijkstra< G >::dijkstra ( G &  graph,
const std::vector< int64_t > &  start_vertex,
const std::vector< int64_t > &  end_vertex,
bool  only_cost,
size_t  n_goals = (std::numeric_limits<size_t>::max)() 
)
inline

Definition at line 270 of file pgr_dijkstra.hpp.

275  {
276  // a call to 1 to many is faster for each of the sources
277  std::deque<Path> paths;
278 
279  for (const auto &start : start_vertex) {
280  auto r_paths = dijkstra(
281  graph,
282  start, end_vertex,
283  only_cost, n_goals);
284  paths.insert(paths.begin(), r_paths.begin(), r_paths.end());
285  }
286 
287  return paths;
288  }

References pgrouting::Pgr_dijkstra< G >::dijkstra().

◆ dijkstra() [2/5]

template<class G >
std::deque<Path> pgrouting::Pgr_dijkstra< G >::dijkstra ( G &  graph,
const std::vector< int64_t > &  start_vertex,
int64_t  end_vertex,
bool  only_cost 
)
inline

Definition at line 249 of file pgr_dijkstra.hpp.

253  {
254  std::deque<Path> paths;
255 
256  for (const auto &start : start_vertex) {
257  paths.push_back(
258  dijkstra(graph, start, end_vertex, only_cost));
259  }
260 
261  std::stable_sort(paths.begin(), paths.end(),
262  [](const Path &e1, const Path &e2)->bool {
263  return e1.start_id() < e2.start_id();
264  });
265  return paths;
266  }

References pgrouting::Pgr_dijkstra< G >::dijkstra().

◆ dijkstra() [3/5]

template<class G >
std::deque<Path> pgrouting::Pgr_dijkstra< G >::dijkstra ( G &  graph,
const std::vector< pgr_combination_t > &  combinations,
bool  only_cost,
size_t  n_goals 
)
inline

Definition at line 291 of file pgr_dijkstra.hpp.

295  {
296  // a call to 1 to many is faster for each of the sources
297  std::deque<Path> paths;
298 
299  // group targets per distinct source
300  std::map<int64_t , std::vector<int64_t> > vertex_map;
301  for (const pgr_combination_t &comb : combinations) {
302  std::map< int64_t , std::vector<int64_t> >::iterator it = vertex_map.find(comb.source);
303  if (it != vertex_map.end()) {
304  it->second.push_back(comb.target);
305  } else {
306  std::vector<int64_t > targets{comb.target};
307  vertex_map[comb.source] = targets;
308  }
309  }
310 
311  for (const auto &start_ends : vertex_map) {
312  auto r_paths = dijkstra(
313  graph,
314  start_ends.first, start_ends.second,
315  only_cost, n_goals);
316  paths.insert(paths.begin(), r_paths.begin(), r_paths.end());
317  }
318 
319  return paths;
320  }

References pgrouting::Pgr_dijkstra< G >::dijkstra().

◆ dijkstra() [4/5]

template<class G >
std::deque<Path> pgrouting::Pgr_dijkstra< G >::dijkstra ( G &  graph,
int64_t  start_vertex,
const std::vector< int64_t > &  end_vertex,
bool  only_cost,
size_t  n_goals 
)
inline

Dijkstra 1 to many.

Definition at line 212 of file pgr_dijkstra.hpp.

217  {
218  // adjust predecessors and distances vectors
219  clear();
220 
221  predecessors.resize(graph.num_vertices());
222  distances.resize(
223  graph.num_vertices(),
224  std::numeric_limits<double>::infinity());
225 
226 
227  // get the graphs source and target
228  if (!graph.has_vertex(start_vertex)) return std::deque<Path>();
229 
230  auto v_source(graph.get_V(start_vertex));
231 
232  std::set< V > s_v_targets;
233  for (const auto &vertex : end_vertex) {
234  if (graph.has_vertex(vertex)) s_v_targets.insert(graph.get_V(vertex));
235  }
236 
237  std::vector< V > v_targets(s_v_targets.begin(), s_v_targets.end());
238  // perform the algorithm
239  dijkstra_1_to_many(graph, v_source, v_targets, n_goals);
240 
241  std::deque< Path > paths;
242  // get the results // route id are the targets
243  paths = get_paths(graph, v_source, v_targets, only_cost);
244 
245  return paths;
246  }

References pgrouting::Pgr_dijkstra< G >::clear(), pgrouting::Pgr_dijkstra< G >::dijkstra_1_to_many(), pgrouting::Pgr_dijkstra< G >::distances, pgrouting::Pgr_dijkstra< G >::get_paths(), and pgrouting::Pgr_dijkstra< G >::predecessors.

◆ dijkstra() [5/5]

template<class G >
Path pgrouting::Pgr_dijkstra< G >::dijkstra ( G &  graph,
int64_t  start_vertex,
int64_t  end_vertex,
bool  only_cost = false 
)
inline

Dijkstra 1 to 1.

Definition at line 172 of file pgr_dijkstra.hpp.

176  {
177  clear();
178 
179  // adjust predecessors and distances vectors
180  predecessors.resize(graph.num_vertices());
181  distances.resize(
182  graph.num_vertices(),
183  std::numeric_limits<double>::infinity());
184 
185 
186  if (!graph.has_vertex(start_vertex)
187  || !graph.has_vertex(end_vertex)) {
188  return Path(start_vertex, end_vertex);
189  }
190 
191  // get the graphs source and target
192  auto v_source(graph.get_V(start_vertex));
193  auto v_target(graph.get_V(end_vertex));
194 
195  // perform the algorithm
196  dijkstra_1_to_1(graph, v_source, v_target);
197 
198  // get the results
199  return Path(
200  graph,
201  v_source, v_target,
203  only_cost, true);
204  }

References pgrouting::Pgr_dijkstra< G >::clear(), pgrouting::Pgr_dijkstra< G >::dijkstra_1_to_1(), pgrouting::Pgr_dijkstra< G >::distances, and pgrouting::Pgr_dijkstra< G >::predecessors.

Referenced by pgrouting::Pgr_dijkstra< G >::dijkstra(), pgrouting::yen::Pgr_ksp< G >::doNextCycle(), pgrouting::yen::Pgr_ksp< G >::getFirstSolution(), pgr_dijkstra(), pgrouting::pgr_dijkstra(), and detail::pgr_dijkstra().

◆ dijkstra_1_to_1()

template<class G >
bool pgrouting::Pgr_dijkstra< G >::dijkstra_1_to_1 ( G &  graph,
V  source,
V  target 
)
inlineprivate

Call to Dijkstra 1 source to 1 target.

Definition at line 326 of file pgr_dijkstra.hpp.

329  {
330  /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
331  CHECK_FOR_INTERRUPTS();
332  try {
333  boost::dijkstra_shortest_paths(graph.graph, source,
334  boost::predecessor_map(&predecessors[0])
335  .weight_map(get(&G::G_T_E::cost, graph.graph))
336  .distance_map(&distances[0])
337  .visitor(visitors::dijkstra_one_goal_visitor<V>(target)));
338  } catch(found_goals &) {
339  return true;
340  } catch (boost::exception const& ex) {
341  (void)ex;
342  throw;
343  } catch (std::exception &e) {
344  (void)e;
345  throw;
346  } catch (...) {
347  throw;
348  }
349  return true;
350  }

References pgrouting::Pgr_dijkstra< G >::distances, and pgrouting::Pgr_dijkstra< G >::predecessors.

Referenced by pgrouting::Pgr_dijkstra< G >::dijkstra().

◆ dijkstra_1_to_distance()

template<class G >
bool pgrouting::Pgr_dijkstra< G >::dijkstra_1_to_distance ( G &  graph,
V  source,
double  distance 
)
inlineprivate

Call to Dijkstra 1 to distance.

Used on: 1 to distance many to distance On the first call of many to distance with equi_cost

Definition at line 359 of file pgr_dijkstra.hpp.

362  {
363  /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
364  CHECK_FOR_INTERRUPTS();
365  try {
366  boost::dijkstra_shortest_paths(graph.graph, source,
367  boost::predecessor_map(&predecessors[0])
368  .weight_map(get(&G::G_T_E::cost, graph.graph))
369  .distance_map(&distances[0])
370  .visitor(dijkstra_distance_visitor(
371  distance,
373  distances)));
374  } catch(found_goals &) {
375  /*No op*/
376  } catch (boost::exception const&) {
377  throw;
378  } catch (std::exception&) {
379  throw;
380  } catch (...) {
381  throw;
382  }
383  return true;
384  }

References pgrouting::Pgr_dijkstra< G >::distances, pgrouting::Pgr_dijkstra< G >::nodesInDistance, and pgrouting::Pgr_dijkstra< G >::predecessors.

Referenced by pgrouting::Pgr_dijkstra< G >::execute_drivingDistance().

◆ dijkstra_1_to_distance_no_init()

template<class G >
bool pgrouting::Pgr_dijkstra< G >::dijkstra_1_to_distance_no_init ( G &  graph,
V  source,
double  distance 
)
inlineprivate

Call to Dijkstra 1 to distance no init.

Used on: On the subsequent calls of many to distance with equi_cost

Definition at line 391 of file pgr_dijkstra.hpp.

394  {
395  pgassert(predecessors.size() == graph.num_vertices());
396  pgassert(distances.size() == graph.num_vertices());
397  distances[source] = 0;
398  std::vector<boost::default_color_type> color_map(graph.num_vertices());
399  /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
400  CHECK_FOR_INTERRUPTS();
401  try {
402  boost::dijkstra_shortest_paths_no_init(graph.graph, source,
403  make_iterator_property_map(
404  predecessors.begin(),
405  graph.vertIndex),
406  make_iterator_property_map(
407  distances.begin(),
408  graph.vertIndex),
409  get(&G::G_T_E::cost, graph.graph),
410  graph.vertIndex,
411  std::less<double>(),
412  boost::closed_plus<double>(),
413  static_cast<double>(0),
414  dijkstra_distance_visitor_no_init(
415  log,
416  source,
417  distance,
418  predecessors,
419  distances,
420  color_map),
421  boost::make_iterator_property_map(
422  color_map.begin(),
423  graph.vertIndex,
424  color_map[0]));
425  } catch(found_goals &) {
426  return true;
427  } catch (boost::exception const& ex) {
428  (void)ex;
429  throw;
430  } catch (std::exception &e) {
431  (void)e;
432  throw;
433  } catch (...) {
434  throw;
435  }
436 
437  return true;
438  }

References pgrouting::Pgr_dijkstra< G >::distances, pgrouting::Pgr_dijkstra< G >::log, pgassert, and pgrouting::Pgr_dijkstra< G >::predecessors.

Referenced by pgrouting::Pgr_dijkstra< G >::execute_drivingDistance_no_init().

◆ dijkstra_1_to_many()

template<class G >
bool pgrouting::Pgr_dijkstra< G >::dijkstra_1_to_many ( G &  graph,
V  source,
const std::vector< V > &  targets,
size_t  n_goals 
)
inlineprivate

Dijkstra 1 source to many targets.

Definition at line 673 of file pgr_dijkstra.hpp.

677  {
678  /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
679  CHECK_FOR_INTERRUPTS();
680  std::set<V> goals_found;
681  std::set<V> goals(targets.begin(), targets.end());
682  try {
683  boost::dijkstra_shortest_paths(graph.graph, source,
684  boost::predecessor_map(&predecessors[0])
685  .weight_map(get(&G::G_T_E::cost, graph.graph))
686  .distance_map(&distances[0])
687  .distance_inf(std::numeric_limits<double>::infinity())
688  .visitor(dijkstra_many_goal_visitor(goals, n_goals, goals_found)));
689  } catch(found_goals &) {
690  for (const auto &g : goals) {
691  if (goals_found.find(g) == goals_found.end()) {
692  /* goal was not found */
693  predecessors[g] = g;
694  }
695  }
696  return true;
697  } catch (boost::exception const& ex) {
698  (void)ex;
699  throw;
700  } catch (std::exception &e) {
701  (void)e;
702  throw;
703  } catch (...) {
704  throw;
705  }
706  return true;
707  }

References pgrouting::Pgr_dijkstra< G >::distances, and pgrouting::Pgr_dijkstra< G >::predecessors.

Referenced by pgrouting::Pgr_dijkstra< G >::dijkstra().

◆ drivingDistance() [1/2]

template<class G >
std::deque< Path > pgrouting::Pgr_dijkstra< G >::drivingDistance ( G &  graph,
const std::vector< int64_t > &  start_vertex,
double  distance,
bool  equicost,
std::ostringstream &  the_log 
)
inline

Definition at line 140 of file pgr_dijkstra.hpp.

145  {
146  if (equicost) {
147  auto paths = drivingDistance_with_equicost(
148  graph,
149  start_vertex,
150  distance);
151  the_log << log.str();
152  return paths;
153  } else {
155  graph,
156  start_vertex,
157  distance);
158  }
159  }

References pgrouting::Pgr_dijkstra< G >::drivingDistance_no_equicost(), pgrouting::Pgr_dijkstra< G >::drivingDistance_with_equicost(), and pgrouting::Pgr_dijkstra< G >::log.

◆ drivingDistance() [2/2]

template<class G >
Path pgrouting::Pgr_dijkstra< G >::drivingDistance ( G &  graph,
int64_t  start_vertex,
double  distance 
)
inline

1 to distance

Definition at line 110 of file pgr_dijkstra.hpp.

113  {
115  graph,
116  start_vertex,
117  distance)) {
118  auto path = Path(graph,
119  start_vertex,
120  distance,
121  predecessors,
122  distances);
123 
124  std::sort(path.begin(), path.end(),
125  [](const Path_t &l, const Path_t &r)
126  {return l.node < r.node;});
127  std::stable_sort(path.begin(), path.end(),
128  [](const Path_t &l, const Path_t &r)
129  {return l.agg_cost < r.agg_cost;});
130  return path;
131  }
132 
133  /* The result is empty */
134  Path p(start_vertex, start_vertex);
135  p.push_back({start_vertex, -1, 0, 0});
136  return p;
137  }

Referenced by pgrouting::pgr_drivingDistance().

◆ drivingDistance_no_equicost()

template<class G >
std::deque< Path > pgrouting::Pgr_dijkstra< G >::drivingDistance_no_equicost ( G &  graph,
const std::vector< int64_t > &  start_vertex,
double  distance 
)
inlineprivate

Definition at line 646 of file pgr_dijkstra.hpp.

649  {
650  // perform the algorithm
651  std::deque<Path> paths;
652  for (const auto &vertex : start_vertex) {
653  if (execute_drivingDistance(graph, vertex, distance)) {
654  auto path = Path(
655  graph,
656  vertex,
657  distance,
658  predecessors,
659  distances);
660  path.sort_by_node_agg_cost();
661  paths.push_back(path);
662  } else {
663  Path p(vertex, vertex);
664  p.push_back({vertex, -1, 0, 0});
665  paths.push_back(p);
666  }
667  }
668  return paths;
669  }

References pgrouting::Pgr_dijkstra< G >::distances, pgrouting::Pgr_dijkstra< G >::execute_drivingDistance(), pgrouting::Pgr_dijkstra< G >::predecessors, and Path::push_back().

Referenced by pgrouting::Pgr_dijkstra< G >::drivingDistance().

◆ drivingDistance_with_equicost()

template<class G >
std::deque< Path > pgrouting::Pgr_dijkstra< G >::drivingDistance_with_equicost ( G &  graph,
const std::vector< int64_t > &  start_vertex,
double  distance 
)
inlineprivate

Definition at line 518 of file pgr_dijkstra.hpp.

521  {
522  clear();
523  log << "Number of edges:" << boost::num_edges(graph.graph) << "\n";
524 
525  predecessors.resize(graph.num_vertices());
526  distances.resize(
527  graph.num_vertices(),
528  std::numeric_limits<double>::infinity());
529 
530  /*
531  * Vector to store the different predessesors
532  * each is of size = graph.num_vertices()
533  *
534  * TODO(vicky)
535  * - figure out less storage if possible
536  */
537  std::deque< std::vector< V > > pred(start_vertex.size());
538 
539  // perform the algorithm
540  size_t i = 0;
541  for (const auto &vertex : start_vertex) {
542  nodesInDistance.clear();
543  /*
544  * The vertex does not exist
545  * Nothing to do
546  */
547  if (graph.has_vertex(vertex)) {
549  graph,
550  graph.get_V(vertex),
551  distance)) {
552  pred[i] = predecessors;
553  }
554  }
555  ++i;
556  }
557 
558 
559  /*
560  * predecessors of vertices in the set are themselves
561  */
562  for (const auto &vertex : start_vertex) {
563  for (auto &p : pred) {
564  if (!p.empty() && graph.has_vertex(vertex))
565  p[graph.get_V(vertex)] = graph.get_V(vertex);
566  }
567  }
568 
569 
571  graph,
572  start_vertex,
573  pred,
574  distance);
575  }

References pgrouting::Pgr_dijkstra< G >::clear(), pgrouting::Pgr_dijkstra< G >::distances, pgrouting::Pgr_dijkstra< G >::execute_drivingDistance_no_init(), pgrouting::Pgr_dijkstra< G >::get_drivingDistance_with_equicost_paths(), pgrouting::Pgr_dijkstra< G >::log, pgrouting::Pgr_dijkstra< G >::nodesInDistance, pred(), and pgrouting::Pgr_dijkstra< G >::predecessors.

Referenced by pgrouting::Pgr_dijkstra< G >::drivingDistance().

◆ execute_drivingDistance()

template<class G >
bool pgrouting::Pgr_dijkstra< G >::execute_drivingDistance ( G &  graph,
int64_t  start_vertex,
double  distance 
)
inlineprivate

to use with driving distance

Prepares the execution for a driving distance:

Parameters
graph
start_vertex
distanceResults are kept on predecessor & distances
Returns
bool True when results are found

Definition at line 453 of file pgr_dijkstra.hpp.

456  {
457  clear();
458 
459  predecessors.resize(graph.num_vertices());
460  distances.resize(
461  graph.num_vertices(),
462  std::numeric_limits<double>::infinity());
463 
464  // get source;
465  if (!graph.has_vertex(start_vertex)) {
466  return false;
467  }
468 
469  return dijkstra_1_to_distance(
470  graph,
471  graph.get_V(start_vertex),
472  distance);
473  }

References pgrouting::Pgr_dijkstra< G >::clear(), pgrouting::Pgr_dijkstra< G >::dijkstra_1_to_distance(), pgrouting::Pgr_dijkstra< G >::distances, and pgrouting::Pgr_dijkstra< G >::predecessors.

Referenced by pgrouting::Pgr_dijkstra< G >::drivingDistance_no_equicost().

◆ execute_drivingDistance_no_init()

template<class G >
bool pgrouting::Pgr_dijkstra< G >::execute_drivingDistance_no_init ( G &  graph,
V  start_vertex,
double  distance 
)
inlineprivate

to use with driving distance

Prepares the execution for a driving distance:

Parameters
graph
start_vertex
distanceResults are kept on predecessor & distances
Returns
bool True when results are found

Definition at line 488 of file pgr_dijkstra.hpp.

491  {
492  pgassert(predecessors.size() == graph.num_vertices());
493  pgassert(distances.size() == graph.num_vertices());
494 
495  std::iota(predecessors.begin(), predecessors.end(), 0);
496 
498  graph,
499  start_vertex,
500  distance);
501  }

References pgrouting::Pgr_dijkstra< G >::dijkstra_1_to_distance_no_init(), pgrouting::Pgr_dijkstra< G >::distances, pgassert, and pgrouting::Pgr_dijkstra< G >::predecessors.

Referenced by pgrouting::Pgr_dijkstra< G >::drivingDistance_with_equicost().

◆ get_drivingDistance_with_equicost_paths()

template<class G >
std::deque< Path > pgrouting::Pgr_dijkstra< G >::get_drivingDistance_with_equicost_paths ( G &  graph,
const std::vector< int64_t > &  start_vertex,
std::deque< std::vector< V > > &  pred,
double  distance 
)
inlineprivate

gets results in form of a container of paths

Parameters
[in]graphThe graph that is being worked
[in]start_vertexAn array of vertices id
[in]predan array of predecessors
[in]distancethe max distance

Definition at line 584 of file pgr_dijkstra.hpp.

588  {
589  /*
590  * precondition
591  */
592  pgassert(start_vertex.size() == pred.size());
593 
594 
595  /*
596  * Creating all the result "paths"
597  */
598  std::deque<Path> paths;
599  for (const auto vertex : start_vertex) {
600  paths.push_back(Path(vertex, vertex));
601  paths.back().push_back({vertex, -1, 0, 0});
602  }
603 
604  /*
605  * Ciclying the distances:
606  * To which vertex do they belong to?
607  */
608  for (V d = 0; d < distances.size(); ++d) {
609  /*
610  * Sikiping distances greater than the one asked for
611  */
612  if (!(distances[d] <= distance)) continue;
613 
614  for (auto i = start_vertex.size(); i > 0; --i) {
615  /*
616  * The vertex does not exist on the graph
617  */
618  if (pred[i - 1].empty()) break;
619 
620 
621  /*
622  * The predecessor = current then
623  * its unreachable to this vertex
624  */
625  if (pred[i - 1][d] == d) continue;
626 
627  auto cost = distances[d] - distances[pred[i - 1][d]];
628  auto edge_id = graph.get_edge_id(pred[i - 1][d], d, cost);
629  pgassert(edge_id != -1);
630  paths[i - 1].push_back(
631  {graph[d].id,
632  edge_id, cost,
633  distances[d]});
634  break;
635  }
636  }
637 
638  for (auto &path : paths) {
639  path.sort_by_node_agg_cost();
640  }
641  return paths;
642  }

References pgrouting::Pgr_dijkstra< G >::distances, pgassert, and pred().

Referenced by pgrouting::Pgr_dijkstra< G >::drivingDistance_with_equicost().

◆ get_paths()

template<class G >
std::deque<Path> pgrouting::Pgr_dijkstra< G >::get_paths ( const G &  graph,
V  source,
std::vector< V > &  targets,
bool  only_cost 
) const
inlineprivate

Definition at line 720 of file pgr_dijkstra.hpp.

724  {
725  std::deque<Path> paths;
726  for (const auto target : targets) {
727  paths.push_back(Path(
728  graph,
729  source, target,
731  only_cost, true));
732  }
733  return paths;
734  }

References pgrouting::Pgr_dijkstra< G >::distances, and pgrouting::Pgr_dijkstra< G >::predecessors.

Referenced by pgrouting::Pgr_dijkstra< G >::dijkstra().

Member Data Documentation

◆ distances

◆ log

◆ nodesInDistance

◆ predecessors


The documentation for this class was generated from the following file:
pgrouting::Pgr_dijkstra::nodesInDistance
std::deque< V > nodesInDistance
Definition: pgr_dijkstra.hpp:742
pgrouting::Pgr_dijkstra::clear
void clear()
Definition: pgr_dijkstra.hpp:710
Path
Definition: basePath_SSEC.hpp:47
pgrouting::Pgr_dijkstra::execute_drivingDistance
bool execute_drivingDistance(G &graph, int64_t start_vertex, double distance)
to use with driving distance
Definition: pgr_dijkstra.hpp:453
pgrouting::Pgr_dijkstra::dijkstra_1_to_1
bool dijkstra_1_to_1(G &graph, V source, V target)
Call to Dijkstra 1 source to 1 target.
Definition: pgr_dijkstra.hpp:326
Path_t
Definition: path_t.h:36
pgrouting::Pgr_dijkstra::predecessors
std::vector< V > predecessors
Definition: pgr_dijkstra.hpp:740
pgrouting::Pgr_dijkstra::drivingDistance_with_equicost
std::deque< Path > drivingDistance_with_equicost(G &graph, const std::vector< int64_t > &start_vertex, double distance)
Definition: pgr_dijkstra.hpp:518
pgrouting::Pgr_dijkstra::get_drivingDistance_with_equicost_paths
std::deque< Path > get_drivingDistance_with_equicost_paths(G &graph, const std::vector< int64_t > &start_vertex, std::deque< std::vector< V > > &pred, double distance)
gets results in form of a container of paths
Definition: pgr_dijkstra.hpp:584
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pred
static size_t pred(size_t i, size_t n)
Definition: pgr_tsp.cpp:64
pgr_combination_t
Definition: pgr_combination_t.h:43
pgrouting::Pgr_dijkstra::dijkstra_1_to_many
bool dijkstra_1_to_many(G &graph, V source, const std::vector< V > &targets, size_t n_goals)
Dijkstra 1 source to many targets.
Definition: pgr_dijkstra.hpp:673
pgrouting::Pgr_dijkstra::dijkstra_1_to_distance_no_init
bool dijkstra_1_to_distance_no_init(G &graph, V source, double distance)
Call to Dijkstra 1 to distance no init.
Definition: pgr_dijkstra.hpp:391
pgrouting::Pgr_dijkstra::execute_drivingDistance_no_init
bool execute_drivingDistance_no_init(G &graph, V start_vertex, double distance)
to use with driving distance
Definition: pgr_dijkstra.hpp:488
pgrouting::Pgr_dijkstra::log
std::ostringstream log
Definition: pgr_dijkstra.hpp:743
pgrouting::Pgr_dijkstra::drivingDistance_no_equicost
std::deque< Path > drivingDistance_no_equicost(G &graph, const std::vector< int64_t > &start_vertex, double distance)
Definition: pgr_dijkstra.hpp:646
pgrouting::Pgr_dijkstra::dijkstra_1_to_distance
bool dijkstra_1_to_distance(G &graph, V source, double distance)
Call to Dijkstra 1 to distance.
Definition: pgr_dijkstra.hpp:359
pgrouting::Pgr_dijkstra::distances
std::vector< double > distances
Definition: pgr_dijkstra.hpp:741
pgrouting::Pgr_dijkstra::V
G::V V
Definition: pgr_dijkstra.hpp:104
pgrouting::Pgr_dijkstra::get_paths
std::deque< Path > get_paths(const G &graph, V source, std::vector< V > &targets, bool only_cost) const
Definition: pgr_dijkstra.hpp:720
pgrouting::Pgr_dijkstra::dijkstra
Path dijkstra(G &graph, int64_t start_vertex, int64_t end_vertex, bool only_cost=false)
Dijkstra 1 to 1.
Definition: pgr_dijkstra.hpp:172