PGROUTING  2.6-dev
basePath_SSEC.cpp File Reference
#include "cpp_common/basePath_SSEC.hpp"
#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

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

Definition at line 259 of file basePath_SSEC.cpp.

References Path::path.

Referenced by do_pgr_astarManyToMany(), do_pgr_bdAstar(), do_pgr_bdDijkstra(), do_pgr_driving_many_to_dist(), do_pgr_many_to_many_dijkstra(), do_pgr_many_withPointsDD(), do_pgr_withPoints(), and do_trsp().

261  {
262  size_t sequence = 0;
263  for (const Path &path : paths) {
264  if (path.path.size() > 0)
265  path.generate_postgres_data(ret_path, sequence);
266  }
267  return sequence;
268 }

Here is the caller graph for this function:

size_t count_tuples ( const std::deque< Path > &  paths)

Definition at line 336 of file basePath_SSEC.cpp.

Referenced by do_pgr_astarManyToMany(), do_pgr_bdAstar(), do_pgr_bdDijkstra(), do_pgr_dijkstraVia(), do_pgr_driving_many_to_dist(), do_pgr_ksp(), do_pgr_many_to_many_dijkstra(), do_pgr_many_withPointsDD(), do_pgr_withPoints(), do_pgr_withPointsKsp(), and do_trsp().

336  {
337  size_t count(0);
338  for (const Path &e : paths) {
339  count += e.path.size();
340  }
341  return count;
342 }

Here is the caller graph for this function:

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

Definition at line 285 of file basePath_SSEC.cpp.

References Path_t::node, Path::path, Path::size(), and Path::start_id().

285  {
286  /* sort paths by size: largest first */
287  std::sort(paths.begin(), paths.end(),
288  [](const Path &e1, const Path &e2)->bool {
289  return e2.size() < e1.size();
290  });
291 
292  /* sort each path by node: smaller id first */
293  for (auto &p : paths) {
294  if (p.size() < 2) continue;
295  std::sort(p.begin(), p.end(),
296  [](const Path_t &e1, const Path_t &e2)->bool {
297  return e1.node < e2.node;
298  });
299  }
300 
301  for (auto &p1 : paths) {
302  for (const auto &p2 : paths) {
303  if (p1.start_id() == p2.start_id()) continue;
304  for (const auto &stop : p2.path) {
305  /* find the node of p2 in p1 */
306  auto pos = lower_bound(p1.begin(), p1.end(), stop,
307  [](const Path_t &l, const Path_t &r)->bool {
308  return l.node < r.node;
309  });
310 
311  if (pos != p1.end()
312  && (stop.node == pos->node)
313  && (stop.agg_cost < pos->agg_cost)) {
314  /* both share the same node &
315  * the second path has the smallest
316  * So erasing from the first path */
317  p1.erase(pos);
318  }
319  }
320  }
321  }
322  /* sort paths by start_id */
323  std::sort(paths.begin(), paths.end(),
324  [](const Path &e1, const Path &e2)->bool {
325  return e1.start_id() < e2.start_id();
326  });
327 
328  /* sort each path by agg_cost, node */
329  for (auto &path : paths) {
330  path.sort_by_node_agg_cost();
331  }
332 }
int64_t node
Definition: path_t.h:37
Definition: path_t.h:36
int64_t start_id() const
size_t size() const

Here is the call graph for this function:

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

Definition at line 91 of file basePath_SSEC.cpp.

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

91  {
92  log << "Path: " << path.start_id() << " -> " << path.end_id() << "\n"
93  << "seq\tnode\tedge\tcost\tagg_cost\n";
94  int64_t i = 0;
95  for (const auto &e : path) {
96  log << i << "\t"
97  << e.node << "\t"
98  << e.edge << "\t"
99  << e.cost << "\t"
100  << e.agg_cost << "\n";
101  ++i;
102  }
103  return log;
104 }
int64_t end_id() const
int64_t start_id() const

Here is the call graph for this function: