pgRouting
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
basePath_SSEC.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: basePath_SSEC.cpp
3 
4 Copyright (c) 2015 Celia Virginia Vergara Castillo
5 vicky_vergara@hotmail.com
6 
7 ------
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 
22 ********************************************************************PGR-GNU*/
23 
24 #if defined(__MINGW32__) || defined(_MSC_VER)
25 #include <winsock2.h>
26 #include <windows.h>
27 #ifdef open
28 #undef open
29 #endif
30 #endif
31 
32 
33 #include "basePath_SSEC.hpp"
34 #include <deque>
35 #include <iostream>
36 #include <algorithm>
37 #include "./pgr_types.h"
38 
39 
41  path.push_front(data);
42  m_tot_cost += data.cost;
43 }
44 
45 void Path::push_back(Path_t data) {
46  path.push_back(data);
47  m_tot_cost += data.cost;
48 }
49 
50 void Path::reverse() {
51  // std::swap(m_start_id, m_end_id);
52  std::deque< Path_t > newpath;
53  for (size_t i = 0; i < path.size(); ++i) {
54  newpath.push_front({
55  path[i].node,
56  (i == 0? -1 : path[i - 1].edge),
57  (i == 0? 0 : path[i - 1].cost),
58  0
59  });
60  }
61  for (size_t i = 0; i < newpath.size(); ++i) {
62  newpath[i].agg_cost = (i == 0)?
63  0 :
64  newpath[i - 1].agg_cost + newpath[i - 1].cost;
65  }
66  path = newpath;
67 }
68 
69 
70 
71 void Path::clear() {
72  path.clear();
73  m_tot_cost = 0;
74  m_start_id = 0;
75  m_end_id = 0;
76 }
77 
78 std::ostream& operator<<(std::ostream &log, const Path &path) {
79  log << "Path: " << path.start_id() << " -> " << path.end_id() << "\n"
80  << "seq\tnode\tedge\tcost\tagg_cost\n";
81  int64_t i = 0;
82  for (const auto &e : path) {
83  log << i << "\t"
84  << e.node << "\t"
85  << e.edge << "\t"
86  << e.cost << "\t"
87  << e.agg_cost << "\n";
88  ++i;
89  }
90  return log;
91 }
92 
93 
94 
95 Path Path::getSubpath(unsigned int j) const {
96  Path result(start_id(), end_id());
97  if (j == 0) return result;
98  for (auto i = path.begin(); i != path.begin() + j; ++i) {
99  result.push_back((*i));
100  }
101  return result;
102 }
103 
104 
105 bool Path::isEqual(const Path &subpath) const {
106  if (subpath.empty()) return true;
107  if (subpath.size() >= path.size()) return false;
108  std::deque< Path_t >::const_iterator i, j;
109  for (i = path.begin(), j = subpath.begin();
110  j != subpath.end();
111  ++i, ++j)
112  if ((*i).node != (*j).node) return false;
113  return true;
114 }
115 
116 void Path::appendPath(const Path &o_path) {
117  path.insert(path.end(), o_path.path.begin(), o_path.path.end());
118  m_tot_cost += o_path.m_tot_cost;
119 }
120 
121 
123  General_path_element_t **postgres_data,
124  size_t &sequence) const {
125  int i = 1;
126  for (const auto e : path) {
127  (*postgres_data)[sequence] =
128  {i, start_id(), end_id(), e.node, e.edge, e.cost, e.agg_cost};
129  ++i;
130  ++sequence;
131  }
132 }
133 
134 /* used by driving distance */
136  General_path_element_t **ret_path,
137  size_t &sequence) const {
138  for (unsigned int i = 0; i < path.size(); i++) {
139  (*ret_path)[sequence].seq = i;
140  (*ret_path)[sequence].start_id = start_id();
141  (*ret_path)[sequence].end_id = start_id();
142  (*ret_path)[sequence].node = path[i].node;
143  (*ret_path)[sequence].edge = path[i].edge;
144  (*ret_path)[sequence].cost = path[i].cost;
145  (*ret_path)[sequence].agg_cost = path[i].agg_cost;
146  sequence++;
147  }
148 }
149 
150 /* used by ksp */
152  General_path_element_t **ret_path,
153  size_t &sequence, int routeId) const {
154  for (unsigned int i = 0; i < path.size(); i++) {
155  (*ret_path)[sequence].seq = i + 1;
156  (*ret_path)[sequence].start_id = routeId;
157  (*ret_path)[sequence].end_id = end_id();
158  (*ret_path)[sequence].node = path[i].node;
159  (*ret_path)[sequence].edge = path[i].edge;
160  (*ret_path)[sequence].cost = path[i].cost;
161  (*ret_path)[sequence].agg_cost = (i == 0)?
162  0 :
163  (*ret_path)[sequence-1].agg_cost + path[i-1].cost;
164  sequence++;
165  }
166 }
int64_t m_end_id
void push_front(Path_t data)
int64_t m_start_id
void get_pg_ksp_path(General_path_element_t **ret_path, size_t &sequence, int routeId) const
void get_pg_dd_path(General_path_element_t **ret_path, size_t &sequence) const
double cost
Definition: pgr_types.h:85
void push_back(Path_t data)
void generate_postgres_data(General_path_element_t **postgres_data, size_t &sequence) const
int64_t end_id() const
std::ostream & operator<<(std::ostream &log, const Path &path)
pthIt end()
void reverse()
int64_t start_id() const
pthIt begin()
bool empty() const
path_element_t * path
Definition: BDATester.cpp:49
Path getSubpath(unsigned int j) const
size_t size() const
void clear()
std::deque< Path_t > path
double m_tot_cost
void appendPath(const Path &o_path)
bool isEqual(const Path &subpath) const