PGROUTING  3.1
Path Class Reference

#include "basePath_SSEC.hpp"

Collaboration diagram for Path:

Public Member Functions

 Path ()
 
 Path (int64_t s_id, int64_t e_id)
 
 Path (const Path &)=default
 
template<typename G , typename V >
 Path (G &graph, int64_t source, double distance, const std::vector< V > &predecessors, const std::vector< double > &distances)
 
template<typename G >
 Path (const G &graph, const Path &original, bool only_cost)
 
template<typename G , typename V >
 Path (G &graph, V v_source, double distance, const std::vector< V > &predecessors, const std::vector< double > &distances)
 
template<typename G , typename V >
 Path (const G &graph, const V v_source, const V v_target, const std::vector< V > &predecessors, const std::vector< double > &distances, bool only_cost, bool normal=true)
 
void append (const Path &other)
 Path: 2 -> 9 seq node edge cost agg_cost 0 2 4 1 0 1 5 8 1 1 2 6 9 1 2 3 9 -1 0 3 Path: 9 -> 3 seq node edge cost agg_cost 0 9 16 1 0 1 4 3 1 1 2 3 -1 0 2 Path: 2 -> 3 seq node edge cost agg_cost 0 2 4 1 0 1 5 8 1 1 2 6 9 1 2 3 9 16 1 3 4 4 3 1 4 5 3 -1 0 5. More...
 
void appendPath (const Path &o_path)
 
const Path_tback () const
 
Path_tback ()
 
pthIt begin ()
 
ConstpthIt begin () const
 
void clear ()
 
template<typename G , typename V >
void complete_path (const G &graph, const V v_source, const V v_target, const std::vector< V > &predecessors, const std::vector< double > &distances, bool normal)
 constructs a path based on results More...
 
size_t countInfinityCost () const
 
bool empty () const
 
void empty_path (unsigned int d_vertex)
 
pthIt end ()
 
ConstpthIt end () const
 
int64_t end_id () const
 
void end_id (int64_t value)
 
void erase (pthIt pos)
 
ConstpthIt find_restriction (const pgrouting::trsp::Rule &rule) const
 get the iterator of the path where the (restriction) rule starts More...
 
const Path_tfront () const
 
Path_tfront ()
 
void generate_postgres_data (General_path_element_t **postgres_data, size_t &sequence) const
 
void get_pg_dd_path (General_path_element_t **ret_path, size_t &sequence) const
 
void get_pg_ksp_path (General_path_element_t **ret_path, size_t &sequence, int routeId) const
 
void get_pg_turn_restricted_path (General_path_element_t **ret_path, size_t &sequence, int routeId) const
 
Path getSubpath (unsigned int j) const
 
bool has_restriction (const pgrouting::trsp::Rule &rule) const
 
Path inf_cost_on_restriction (const pgrouting::trsp::Rule &rule)
 
bool isEqual (const Path &subpath) const
 
const Path_toperator[] (size_t i) const
 
Path_toperator[] (size_t i)
 
void push_back (Path_t data)
 
void push_front (Path_t data)
 
void push_front (int64_t d_vertex, int64_t d_edge, double d_cost, double d_tot_cost)
 
void recalculate_agg_cost ()
 
Pathrenumber_vertices (int64_t value)
 
void reverse ()
 
Path_t set_data (int64_t d_from, int64_t d_to, int64_t d_vertex, int64_t d_edge, double d_cost, double d_tot_cost)
 
size_t size () const
 
void sort_by_node_agg_cost ()
 Sorts a path by node, aggcost ascending. More...
 
int64_t start_id () const
 
void start_id (int64_t value)
 
double tot_cost () const
 

Private Types

typedef std::deque< Path_t >::const_iterator ConstpthIt
 
typedef std::deque< Path_t >::iterator pthIt
 

Private Attributes

int64_t m_end_id
 
int64_t m_start_id
 
double m_tot_cost
 
std::deque< Path_tpath
 

Friends

size_t collapse_paths (General_path_element_t **ret_path, const std::deque< Path > &paths)
 
size_t count_tuples (const std::deque< Path > &paths)
 counts the tuples to be returned More...
 
void equi_cost (std::deque< Path > &paths)
 discards common vertices with greater agg_cost More...
 
std::ostream & operator<< (std::ostream &log, const Path &p)
 

Detailed Description

Definition at line 47 of file basePath_SSEC.hpp.

Member Typedef Documentation

◆ ConstpthIt

typedef std::deque< Path_t >::const_iterator Path::ConstpthIt
private

Definition at line 49 of file basePath_SSEC.hpp.

◆ pthIt

typedef std::deque< Path_t >::iterator Path::pthIt
private

Definition at line 48 of file basePath_SSEC.hpp.

Constructor & Destructor Documentation

◆ Path() [1/7]

Path::Path ( )
inline

Definition at line 58 of file basePath_SSEC.hpp.

Referenced by Path().

58  : m_start_id(0), m_end_id(0), m_tot_cost(0)
59  {}
int64_t m_end_id
int64_t m_start_id
double m_tot_cost

◆ Path() [2/7]

Path::Path ( int64_t  s_id,
int64_t  e_id 
)
inline

Definition at line 60 of file basePath_SSEC.hpp.

References Path().

61  : m_start_id(s_id), m_end_id(e_id), m_tot_cost(0)
62  {}
int64_t m_end_id
int64_t m_start_id
double m_tot_cost

◆ Path() [3/7]

Path::Path ( const Path )
default

◆ Path() [4/7]

template<typename G , typename V >
Path::Path ( G &  graph,
int64_t  source,
double  distance,
const std::vector< V > &  predecessors,
const std::vector< double > &  distances 
)
inline

Definition at line 162 of file basePath_SSEC.hpp.

References push_back().

167  :
168  m_start_id(source),
169  m_end_id(source) {
170  for (V i = 0; i < distances.size(); ++i) {
171  if (distances[i] <= distance) {
172  auto cost = distances[i] - distances[predecessors[i]];
173  auto edge_id = graph.get_edge_id(predecessors[i], i, cost);
174  push_back(
175  {graph[i].id,
176  edge_id, cost,
177  distances[i]});
178  }
179  }
180  }
int64_t m_end_id
int64_t m_start_id
boost::graph_traits< BG >::vertex_descriptor V
void push_back(Path_t data)

◆ Path() [5/7]

template<typename G >
Path::Path ( const G &  graph,
const Path original,
bool  only_cost 
)
inline

Definition at line 183 of file basePath_SSEC.hpp.

References m_end_id, m_tot_cost, path, push_back(), and recalculate_agg_cost().

186  :
187  m_start_id(original.m_start_id),
188  m_end_id(original.m_end_id),
189  m_tot_cost(0) {
190  if (original.path.empty()) return;
191 
192  typename G::EO_i ei, ei_end;
193 
194 // auto last_node = m_start_id;
195  for (const auto &p : original.path) {
196  boost::tie(ei, ei_end) = out_edges(
197  graph.get_V(p.node),
198  graph.graph);
199 
200  if (p.edge == -1) {
201  path.push_back({m_end_id, -1, 0, 0});
202  } else {
203  for ( ; ei != ei_end; ++ei) {
204  if (graph[*ei].id == p.edge) {
205  auto cost = graph[*ei].cost;
206  push_back({p.node, p.edge, cost, 0});
207  }
208  }
209  }
210 // last_node = p.node;
211  }
213 
214  if (only_cost) {
215  path.clear();
216  path.push_back(
217  {m_end_id,
218  -1,
219  m_tot_cost,
220  m_tot_cost});
221  }
222  }
int64_t m_end_id
int64_t m_start_id
void recalculate_agg_cost()
void push_back(Path_t data)
std::deque< Path_t > path
double m_tot_cost

◆ Path() [6/7]

template<typename G , typename V >
Path::Path ( G &  graph,
v_source,
double  distance,
const std::vector< V > &  predecessors,
const std::vector< double > &  distances 
)
inline

Definition at line 224 of file basePath_SSEC.hpp.

References push_back().

229  :
230  m_start_id(graph.graph[v_source].id),
231  m_end_id(graph.graph[v_source].id) {
232  for (V i = 0; i < distances.size(); ++i) {
233  if (distances[i] <= distance) {
234  auto cost = distances[i] - distances[predecessors[i]];
235  auto edge_id = graph.get_edge_id(predecessors[i], i, cost);
236  push_back(
237  {graph[i].id,
238  edge_id, cost,
239  distances[i]});
240  }
241  }
242  }
int64_t m_end_id
int64_t m_start_id
boost::graph_traits< BG >::vertex_descriptor V
void push_back(Path_t data)

◆ Path() [7/7]

template<typename G , typename V >
Path::Path ( const G &  graph,
const V  v_source,
const V  v_target,
const std::vector< V > &  predecessors,
const std::vector< double > &  distances,
bool  only_cost,
bool  normal = true 
)
inline

Definition at line 246 of file basePath_SSEC.hpp.

References complete_path(), and push_front().

253  :
254  m_start_id(graph.graph[v_source].id),
255  m_end_id(graph.graph[v_target].id) {
256  if (!only_cost) {
257  complete_path(graph,
258  v_source,
259  v_target,
260  predecessors,
261  distances,
262  normal);
263  return;
264  }
265  /*
266  * only_cost
267  */
268  if (v_target != predecessors[v_target]) {
269  push_front(
270  {graph.graph[v_target].id,
271  -1,
272  distances[v_target],
273  distances[v_target]});
274  }
275  return;
276  }
int64_t m_end_id
void push_front(Path_t data)
int64_t m_start_id
void complete_path(const G &graph, const V v_source, const V v_target, const std::vector< V > &predecessors, const std::vector< double > &distances, bool normal)
constructs a path based on results

Member Function Documentation

◆ append()

void Path::append ( const Path other)

Path: 2 -> 9 seq node edge cost agg_cost 0 2 4 1 0 1 5 8 1 1 2 6 9 1 2 3 9 -1 0 3 Path: 9 -> 3 seq node edge cost agg_cost 0 9 16 1 0 1 4 3 1 1 2 3 -1 0 2 Path: 2 -> 3 seq node edge cost agg_cost 0 2 4 1 0 1 5 8 1 1 2 6 9 1 2 3 9 16 1 3 4 4 3 1 4 5 3 -1 0 5.

Definition at line 192 of file basePath_SSEC.cpp.

References m_end_id, m_start_id, path, pgassert, and push_back().

Referenced by pgrouting::bidirectional::Pgr_bidirectional< G >::bidirectional(), and front().

192  {
193  pgassert(m_end_id == other.m_start_id);
194  if (other.m_start_id == other.m_end_id) {
195  pgassert(other.path.empty());
196  return;
197  }
198  if (m_start_id == m_end_id) {
199  pgassert(path.empty());
200  *this = other;
201  return;
202  }
203 #if 0
204  pgassert(path.back().cost == 0);
205 #endif
206  pgassert(path.back().edge == -1);
207  m_end_id = other.m_end_id;
208 
209  auto last = path.back();
210  auto agg_cost = last.agg_cost;
211 
212  path.pop_back();
213 
214  for (auto item : other.path) {
215  item.agg_cost += agg_cost;
216  push_back(item);
217  }
218 }
int64_t m_end_id
int64_t m_start_id
void push_back(Path_t data)
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
std::deque< Path_t > path

◆ appendPath()

void Path::appendPath ( const Path o_path)

Definition at line 164 of file basePath_SSEC.cpp.

References path, and recalculate_agg_cost().

Referenced by pgrouting::yen::Pgr_ksp< G >::doNextCycle(), and front().

164  {
165  path.insert(path.end(), o_path.path.begin(), o_path.path.end());
167 }
void recalculate_agg_cost()
std::deque< Path_t > path

◆ back() [1/2]

const Path_t& Path::back ( ) const
inline

Definition at line 88 of file basePath_SSEC.hpp.

88 {return path.back();}
std::deque< Path_t > path

◆ back() [2/2]

Path_t& Path::back ( )
inline

Definition at line 89 of file basePath_SSEC.hpp.

89 {return path.back();}
std::deque< Path_t > path

◆ begin() [1/2]

pthIt Path::begin ( )
inline

◆ begin() [2/2]

ConstpthIt Path::begin ( ) const
inline

Definition at line 83 of file basePath_SSEC.hpp.

83 {return path.begin();}
std::deque< Path_t > path

◆ clear()

void Path::clear ( )

Definition at line 87 of file basePath_SSEC.cpp.

References m_end_id, m_start_id, m_tot_cost, and path.

Referenced by pgrouting::trsp::Pgr_trspHandler::clear(), and front().

87  {
88  path.clear();
89  m_tot_cost = 0;
90  m_start_id = 0;
91  m_end_id = 0;
92 }
int64_t m_end_id
int64_t m_start_id
std::deque< Path_t > path
double m_tot_cost

◆ complete_path()

template<typename G , typename V >
void Path::complete_path ( const G &  graph,
const V  v_source,
const V  v_target,
const std::vector< V > &  predecessors,
const std::vector< double > &  distances,
bool  normal 
)
inline

constructs a path based on results

Normal = false for reversed search path like in pgr_bdDijkstra

Definition at line 282 of file basePath_SSEC.hpp.

References push_front().

Referenced by Path().

288  {
289  // no path was found
290  if (v_target == predecessors[v_target]) {
291  return;
292  }
293 
294  /*
295  * set the target
296  */
297  auto target = v_target;
298 
299  /*
300  * the last stop is the target
301  */
302  push_front(
303  {graph.graph[target].id, -1,
304  0, distances[target]});
305 
306  /*
307  * get the path
308  */
309  while (target != v_source) {
310  /*
311  * done when the predecesor of the target is the target
312  */
313  if (target == predecessors[target]) break;
314 
315  /*
316  * Inserting values in the path
317  */
318  auto cost = distances[target] - distances[predecessors[target]];
319  auto vertex_id = graph.graph[predecessors[target]].id;
320  auto edge_id = normal?
321  graph.get_edge_id(predecessors[target], target, cost)
322  : graph.get_edge_id(target, predecessors[target], cost);
323 
324  push_front({
325  vertex_id,
326  edge_id,
327  cost,
328  distances[target] - cost});
329  target = predecessors[target];
330  }
331 
332  return;
333  }
void push_front(Path_t data)

◆ countInfinityCost()

size_t Path::countInfinityCost ( ) const

Definition at line 133 of file basePath_SSEC.cpp.

References path.

Referenced by empty(), and pgrouting::yen::Pgr_turnRestrictedPath< G >::get_results().

133  {
134  return static_cast<size_t>(std::count_if(path.begin(), path.end(),
135  [](Path_t const&p) -> size_t {
136  return std::isinf(p.agg_cost);
137  }));
138 }
Definition: path_t.h:36
std::deque< Path_t > path

◆ empty()

◆ empty_path()

void Path::empty_path ( unsigned int  d_vertex)

Referenced by front().

◆ end() [1/2]

pthIt Path::end ( )
inline

◆ end() [2/2]

ConstpthIt Path::end ( ) const
inline

Definition at line 84 of file basePath_SSEC.hpp.

84 {return path.end();}
std::deque< Path_t > path

◆ end_id() [1/2]

◆ end_id() [2/2]

void Path::end_id ( int64_t  value)
inline

Definition at line 68 of file basePath_SSEC.hpp.

68 {m_end_id = value;}
int64_t m_end_id

◆ erase()

void Path::erase ( pthIt  pos)
inline

Definition at line 87 of file basePath_SSEC.hpp.

87 {path.erase(pos);}
std::deque< Path_t > path

◆ find_restriction()

Path::ConstpthIt Path::find_restriction ( const pgrouting::trsp::Rule rule) const

get the iterator of the path where the (restriction) rule starts

Parameters
[in]ruleA subpath of edges for turn restrictions
Returns
the iterator of the path

Definition at line 94 of file basePath_SSEC.cpp.

References pgrouting::trsp::Rule::begin(), Path_t::edge, pgrouting::trsp::Rule::end(), and path.

Referenced by front(), and has_restriction().

95  {
96  return std::search(path.begin(), path.end(), rule.begin(), rule.end(),
97  [](Path_t p, int64_t e) {return p.edge == e;});
98 }
int64_t edge
Definition: path_t.h:38
Definition: path_t.h:36
constiterator begin() const
Definition: rule.h:52
std::deque< Path_t > path
constiterator end() const
Definition: rule.h:53

◆ front() [1/2]

const Path_t& Path::front ( ) const
inline

Definition at line 90 of file basePath_SSEC.hpp.

90 {return path.front();}
std::deque< Path_t > path

◆ front() [2/2]

◆ generate_postgres_data()

void Path::generate_postgres_data ( General_path_element_t **  postgres_data,
size_t &  sequence 
) const

Definition at line 221 of file basePath_SSEC.cpp.

References end_id(), path, and start_id().

Referenced by front().

223  {
224  int i = 1;
225  for (const auto e : path) {
226  auto agg_cost = std::fabs(
227  e.agg_cost - (std::numeric_limits<double>::max)()) < 1?
228  std::numeric_limits<double>::infinity() : e.agg_cost;
229  auto cost = std::fabs(e.cost - (std::numeric_limits<double>::max)()) < 1?
230  std::numeric_limits<double>::infinity() : e.cost;
231 
232  (*postgres_data)[sequence] = {i, start_id(), end_id(), e.node, e.edge, cost, agg_cost};
233  ++i;
234  ++sequence;
235  }
236 }
int64_t end_id() const
int64_t start_id() const
std::deque< Path_t > path

◆ get_pg_dd_path()

void Path::get_pg_dd_path ( General_path_element_t **  ret_path,
size_t &  sequence 
) const

Definition at line 239 of file basePath_SSEC.cpp.

References path, and start_id().

Referenced by front().

241  {
242  for (unsigned int i = 0; i < path.size(); i++) {
243  (*ret_path)[sequence].seq = static_cast<int>(i);
244  (*ret_path)[sequence].start_id = start_id();
245  (*ret_path)[sequence].end_id = start_id();
246  (*ret_path)[sequence].node = path[i].node;
247  (*ret_path)[sequence].edge = path[i].edge;
248  (*ret_path)[sequence].cost = path[i].cost;
249  (*ret_path)[sequence].agg_cost = path[i].agg_cost;
250  sequence++;
251  }
252 }
int64_t start_id() const
std::deque< Path_t > path

◆ get_pg_ksp_path()

void Path::get_pg_ksp_path ( General_path_element_t **  ret_path,
size_t &  sequence,
int  routeId 
) const

Definition at line 255 of file basePath_SSEC.cpp.

References end_id(), and path.

Referenced by front().

257  {
258  for (unsigned int i = 0; i < path.size(); i++) {
259  (*ret_path)[sequence].seq = static_cast<int>(i + 1);
260  (*ret_path)[sequence].start_id = routeId;
261  (*ret_path)[sequence].end_id = end_id();
262  (*ret_path)[sequence].node = path[i].node;
263  (*ret_path)[sequence].edge = path[i].edge;
264  (*ret_path)[sequence].cost = path[i].cost;
265  (*ret_path)[sequence].agg_cost = (i == 0)?
266  0 :
267  (*ret_path)[sequence-1].agg_cost + path[i-1].cost;
268  sequence++;
269  }
270 }
int64_t end_id() const
std::deque< Path_t > path

◆ get_pg_turn_restricted_path()

void Path::get_pg_turn_restricted_path ( General_path_element_t **  ret_path,
size_t &  sequence,
int  routeId 
) const

Definition at line 273 of file basePath_SSEC.cpp.

References end_id(), and path.

Referenced by front().

275  {
276  for (unsigned int i = 0; i < path.size(); i++) {
277  (*ret_path)[sequence].seq = static_cast<int>(i + 1);
278  (*ret_path)[sequence].start_id = routeId;
279  (*ret_path)[sequence].end_id = end_id();
280  (*ret_path)[sequence].node = path[i].node;
281  (*ret_path)[sequence].edge = path[i].edge;
282  (*ret_path)[sequence].cost = path[i].cost;
283  (*ret_path)[sequence].agg_cost = path[i].agg_cost;
284  sequence++;
285  }
286 }
int64_t end_id() const
std::deque< Path_t > path

◆ getSubpath()

Path Path::getSubpath ( unsigned int  j) const

Definition at line 141 of file basePath_SSEC.cpp.

References end_id(), path, pgassert, push_back(), start_id(), and tot_cost().

Referenced by pgrouting::yen::Pgr_ksp< G >::doNextCycle(), and front().

141  {
142  Path result(start_id(), end_id());
143  if (j == 0) return result;
144  for (auto i = path.begin(); i != path.begin() + j; ++i) {
145  result.push_back((*i));
146  }
147  pgassert(result.tot_cost() != 0);
148  pgassert(this->tot_cost() != 0);
149  return result;
150 }
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
int64_t end_id() const
double tot_cost() const
int64_t start_id() const
std::deque< Path_t > path

◆ has_restriction()

bool Path::has_restriction ( const pgrouting::trsp::Rule rule) const

Definition at line 100 of file basePath_SSEC.cpp.

References find_restriction(), and path.

Referenced by front(), and pgrouting::yen::Pgr_turnRestrictedPath< G >::Myvisitor::has_restriction().

101  {
102  return find_restriction(rule) != path.end();
103 }
ConstpthIt find_restriction(const pgrouting::trsp::Rule &rule) const
get the iterator of the path where the (restriction) rule starts
std::deque< Path_t > path

◆ inf_cost_on_restriction()

Path Path::inf_cost_on_restriction ( const pgrouting::trsp::Rule rule)

Definition at line 105 of file basePath_SSEC.cpp.

References pgrouting::trsp::Rule::begin(), Path_t::edge, pgrouting::trsp::Rule::end(), and path.

Referenced by front().

106  {
107  auto position = std::search(
108  path.begin(), path.end(), rule.begin(), rule.end(),
109  [](Path_t p, int64_t e) { return p.edge == e;});
110  if (position != path.end()) {
111  position->agg_cost = std::numeric_limits<double>::infinity();
112  }
113  return *this;
114 }
int64_t edge
Definition: path_t.h:38
Definition: path_t.h:36
constiterator begin() const
Definition: rule.h:52
std::deque< Path_t > path
constiterator end() const
Definition: rule.h:53

◆ isEqual()

bool Path::isEqual ( const Path subpath) const

Definition at line 153 of file basePath_SSEC.cpp.

References begin(), empty(), end(), path, and size().

Referenced by front().

153  {
154  if (subpath.empty()) return true;
155  if (subpath.size() >= path.size()) return false;
156  std::deque< Path_t >::const_iterator i, j;
157  for (i = path.begin(), j = subpath.begin();
158  j != subpath.end();
159  ++i, ++j)
160  if ((*i).node != (*j).node) return false;
161  return true;
162 }
size_t size() const
pthIt end()
bool empty() const
pthIt begin()
std::deque< Path_t > path

◆ operator[]() [1/2]

const Path_t& Path::operator[] ( size_t  i) const
inline

Definition at line 77 of file basePath_SSEC.hpp.

77 {return path[i];}
std::deque< Path_t > path

◆ operator[]() [2/2]

Path_t& Path::operator[] ( size_t  i)
inline

Definition at line 78 of file basePath_SSEC.hpp.

References renumber_vertices().

78 {return path[i];}
std::deque< Path_t > path

◆ push_back()

◆ push_front() [1/2]

void Path::push_front ( Path_t  data)

Definition at line 47 of file basePath_SSEC.cpp.

References Path_t::cost, m_tot_cost, and path.

Referenced by complete_path(), empty(), front(), and Path().

47  {
48  path.push_front(data);
49  m_tot_cost += data.cost;
50 }
double cost
Definition: path_t.h:39
std::deque< Path_t > path
double m_tot_cost

◆ push_front() [2/2]

void Path::push_front ( int64_t  d_vertex,
int64_t  d_edge,
double  d_cost,
double  d_tot_cost 
)

◆ recalculate_agg_cost()

void Path::recalculate_agg_cost ( )

Definition at line 77 of file basePath_SSEC.cpp.

References m_tot_cost, and path.

Referenced by appendPath(), pgrouting::yen::Pgr_ksp< G >::executeYen(), front(), pgrouting::yen::Pgr_ksp< G >::getFirstSolution(), and Path().

77  {
78  m_tot_cost = 0;
79  for (auto &p : path) {
80  p.agg_cost = m_tot_cost;
81  m_tot_cost += p.cost;
82  }
83 }
std::deque< Path_t > path
double m_tot_cost

◆ renumber_vertices()

Path & Path::renumber_vertices ( int64_t  value)

Definition at line 38 of file basePath_SSEC.cpp.

References m_end_id, m_start_id, and path.

Referenced by operator[](), and pgrouting::trsp::Pgr_trspHandler::process_trsp().

38  {
39  for (auto &r : path) {
40  r.node += value;
41  }
42  m_start_id += value;
43  m_end_id += value;
44  return *this;
45 }
int64_t m_end_id
int64_t m_start_id
std::deque< Path_t > path

◆ reverse()

void Path::reverse ( )

Definition at line 57 of file basePath_SSEC.cpp.

References m_end_id, m_start_id, and path.

Referenced by pgrouting::bidirectional::Pgr_bidirectional< G >::bidirectional(), front(), pgr_astar(), and pgr_dijkstra().

57  {
58  std::swap(m_start_id, m_end_id);
59  if (path.size() <= 1) return;
60  std::deque< Path_t > newpath;
61  for (size_t i = 0; i < path.size(); ++i) {
62  newpath.push_front({
63  path[i].node,
64  (i == 0? -1 : path[i - 1].edge),
65  (i == 0? 0 : path[i - 1].cost),
66  0
67  });
68  }
69  for (size_t i = 0; i < newpath.size(); ++i) {
70  newpath[i].agg_cost = (i == 0)?
71  0 :
72  newpath[i - 1].agg_cost + newpath[i - 1].cost;
73  }
74  path = newpath;
75 }
int64_t m_end_id
int64_t m_start_id
std::deque< Path_t > path

◆ set_data()

Path_t Path::set_data ( int64_t  d_from,
int64_t  d_to,
int64_t  d_vertex,
int64_t  d_edge,
double  d_cost,
double  d_tot_cost 
)

Referenced by front().

◆ size()

size_t Path::size ( ) const
inline

◆ sort_by_node_agg_cost()

void Path::sort_by_node_agg_cost ( )

Sorts a path by node, aggcost ascending.

nodes ASC agg_cost ASC

Definition at line 295 of file basePath_SSEC.cpp.

References Path_t::agg_cost, Path_t::node, and path.

Referenced by front().

295  {
296  std::sort(path.begin(), path.end(),
297  [](const Path_t &l, const Path_t &r)
298  {return l.node < r.node;});
299  std::stable_sort(path.begin(), path.end(),
300  [](const Path_t &l, const Path_t &r)
301  {return l.agg_cost < r.agg_cost;});
302 }
int64_t node
Definition: path_t.h:37
Definition: path_t.h:36
std::deque< Path_t > path
double agg_cost
Definition: path_t.h:40

◆ start_id() [1/2]

◆ start_id() [2/2]

void Path::start_id ( int64_t  value)
inline

Definition at line 66 of file basePath_SSEC.hpp.

66 {m_start_id = value;}
int64_t m_start_id

◆ tot_cost()

double Path::tot_cost ( ) const
inline

Definition at line 69 of file basePath_SSEC.hpp.

References m_tot_cost.

Referenced by getSubpath(), pgrouting::compPathsLess::operator()(), and detail::post_process().

69 {return m_tot_cost;}
double m_tot_cost

Friends And Related Function Documentation

◆ collapse_paths

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

Definition at line 310 of file basePath_SSEC.cpp.

Referenced by front().

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 }
std::deque< Path_t > path

◆ count_tuples

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

counts the tuples to be returned

Definition at line 387 of file basePath_SSEC.cpp.

Referenced by front().

387  {
388  size_t count(0);
389  for (const Path &e : paths) {
390  count += e.path.size();
391  }
392  return count;
393 }

◆ equi_cost

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

discards common vertices with greater agg_cost

Definition at line 336 of file basePath_SSEC.cpp.

Referenced by front().

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 }
size_t size() const
int64_t node
Definition: path_t.h:37
Definition: path_t.h:36
int64_t start_id() const
std::deque< Path_t > path

◆ operator<<

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

Definition at line 118 of file basePath_SSEC.cpp.

Referenced by front().

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 }
std::deque< Path_t > path

Member Data Documentation

◆ m_end_id

int64_t Path::m_end_id
private

Definition at line 54 of file basePath_SSEC.hpp.

Referenced by append(), clear(), end_id(), Path(), renumber_vertices(), and reverse().

◆ m_start_id

int64_t Path::m_start_id
private

Definition at line 53 of file basePath_SSEC.hpp.

Referenced by append(), clear(), renumber_vertices(), reverse(), and start_id().

◆ m_tot_cost

double Path::m_tot_cost
private

Definition at line 55 of file basePath_SSEC.hpp.

Referenced by clear(), Path(), push_back(), push_front(), recalculate_agg_cost(), and tot_cost().

◆ path


The documentation for this class was generated from the following files: