PGROUTING  3.2
pgrouting::compPathsLess Class Reference

#include "compPaths.h"

Public Member Functions

bool operator() (const Path &p1, const Path &p2) const
 

Detailed Description

Compares 2 paths for <

Returns
true when p1 < p2

Testing takes place in the following order:

  • The aggregate cost is compared
  • The length is compared
  • The Node id is compared

Definition at line 47 of file compPaths.h.

Member Function Documentation

◆ operator()()

bool pgrouting::compPathsLess::operator() ( const Path p1,
const Path p2 
) const

Definition at line 40 of file compPaths.cpp.

40  {
41  /*
42  * less cost is best
43  */
44  if (!(std::fabs(p2.tot_cost() - p1.tot_cost())
45  <
46  std::numeric_limits<double>::epsilon())) {
47  if (p1.tot_cost() > p2.tot_cost())
48  return false;
49  if (p1.tot_cost() < p2.tot_cost())
50  return true;
51  }
52 
53  // paths costs are equal now check by length
54  if (p1.size() > p2.size())
55  return false;
56  if (p1.size() < p2.size())
57  return true;
58 
59 // pgassert(p1.tot_cost() == p2.tot_cost());
60  pgassert(p1.size() == p2.size());
61 
62  // paths weights & lengths are equal now check by node ID
63  unsigned int i;
64  for (i = 0; i < p1.size(); i++) {
65  if (p1[i].node > p2[i].node)
66  return false;
67  if (p1[i].node < p2[i].node)
68  return true;
69  }
70 
71 // pgassert(p1.tot_cost() == p2.tot_cost());
72  pgassert(p1.size() == p2.size());
73 #ifdef NDEBUG
74  for (i = 0; i < p1.size(); i++) {
75  pgassert(p1[i].node == p2[i].node);
76  }
77 #endif
78 
79  // we got here and everything is equal
80  return false;
81 }

References pgassert, Path::size(), and Path::tot_cost().


The documentation for this class was generated from the following files:
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
Path::size
size_t size() const
Definition: basePath_SSEC.hpp:71
Path::tot_cost
double tot_cost() const
Definition: basePath_SSEC.hpp:69