PGROUTING  3.2
basePath_SSEC.cpp File Reference
#include "cpp_common/basePath_SSEC.hpp"
#include <cmath>
#include <limits>
#include <deque>
#include <iostream>
#include <algorithm>
#include <utility>
#include "c_types/general_path_element_t.h"
#include "cpp_common/pgr_assert.h"
Include dependency graph for basePath_SSEC.cpp:

Go to the source code of this file.

Functions

size_t collapse_paths (General_path_element_t **ret_path, const std::deque< Path > &paths)
 
size_t count_tuples (const std::deque< Path > &paths)
 
void equi_cost (std::deque< Path > &paths)
 
std::ostream & operator<< (std::ostream &log, const Path &path)
 

Function Documentation

◆ collapse_paths()

size_t collapse_paths ( General_path_element_t **  ret_path,
const std::deque< Path > &  paths 
)

Definition at line 310 of file basePath_SSEC.cpp.

312  {
313  size_t sequence = 0;
314  for (const Path &path : paths) {
315  if (path.path.size() > 0)
316  path.generate_postgres_data(ret_path, sequence);
317  }
318  return sequence;
319 }

Referenced by do_pgr_astarManyToMany(), do_pgr_bdAstar(), do_pgr_bdDijkstra(), do_pgr_bellman_ford(), do_pgr_bellman_ford_neg(), do_pgr_binaryBreadthFirstSearch(), do_pgr_combinations_dijkstra(), do_pgr_dagShortestPath(), do_pgr_driving_many_to_dist(), do_pgr_edwardMoore(), do_pgr_many_to_many_dijkstra(), do_pgr_many_withPointsDD(), do_pgr_withPoints(), and do_trsp().

◆ count_tuples()

◆ equi_cost()

void equi_cost ( std::deque< Path > &  paths)

Definition at line 336 of file basePath_SSEC.cpp.

336  {
337  /* sort paths by size: largest first */
338  std::sort(paths.begin(), paths.end(),
339  [](const Path &e1, const Path &e2)->bool {
340  return e2.size() < e1.size();
341  });
342 
343  /* sort each path by node: smaller id first */
344  for (auto &p : paths) {
345  if (p.size() < 2) continue;
346  std::sort(p.begin(), p.end(),
347  [](const Path_t &e1, const Path_t &e2)->bool {
348  return e1.node < e2.node;
349  });
350  }
351 
352  for (auto &p1 : paths) {
353  for (const auto &p2 : paths) {
354  if (p1.start_id() == p2.start_id()) continue;
355  for (const auto &stop : p2.path) {
356  /* find the node of p2 in p1 */
357  auto pos = lower_bound(p1.begin(), p1.end(), stop,
358  [](const Path_t &l, const Path_t &r)->bool {
359  return l.node < r.node;
360  });
361 
362  if (pos != p1.end()
363  && (stop.node == pos->node)
364  && (stop.agg_cost < pos->agg_cost)) {
365  /* both share the same node &
366  * the second path has the smallest
367  * So erasing from the first path */
368  p1.erase(pos);
369  }
370  }
371  }
372  }
373  /* sort paths by start_id */
374  std::sort(paths.begin(), paths.end(),
375  [](const Path &e1, const Path &e2)->bool {
376  return e1.start_id() < e2.start_id();
377  });
378 
379  /* sort each path by agg_cost, node */
380  for (auto &path : paths) {
381  path.sort_by_node_agg_cost();
382  }
383 }

◆ operator<<()

std::ostream& operator<< ( std::ostream &  log,
const Path path 
)

Definition at line 118 of file basePath_SSEC.cpp.

118  {
119  log << "Path: " << path.start_id() << " -> " << path.end_id() << "\n"
120  << "seq\tnode\tedge\tcost\tagg_cost\n";
121  int64_t i = 0;
122  for (const auto &e : path) {
123  log << i << "\t"
124  << e.node << "\t"
125  << e.edge << "\t"
126  << e.cost << "\t"
127  << e.agg_cost << "\n";
128  ++i;
129  }
130  return log;
131 }

References Path::end_id(), and Path::start_id().

Path::end_id
int64_t end_id() const
Definition: basePath_SSEC.hpp:67
Path
Definition: basePath_SSEC.hpp:47
Path::start_id
int64_t start_id() const
Definition: basePath_SSEC.hpp:65
Path_t
Definition: path_t.h:36