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
basic_vertex.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2  *
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 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 
23 ********************************************************************PGR-GNU*/
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 <vector>
34 #include <algorithm>
35 
36 #include <sstream>
37 #include "./basic_vertex.h"
38 #include "./pgr_types.h"
39 #include "./pgr_assert.h"
40 
41 
42 namespace pgrouting {
43 
44  std::ostream& operator<<(std::ostream& log, const Basic_vertex &v) {
45  log << v.id;
46  return log;
47  }
48 
50  std::vector < Basic_vertex > vertices) {
51  auto count(vertices.size());
52  std::stable_sort(
53  vertices.begin(), vertices.end(),
54  [](const Basic_vertex &lhs, const Basic_vertex &rhs)
55  {return lhs.id < rhs.id;});
56  vertices.erase(
57  std::unique(
58  vertices.begin(), vertices.end(),
59  [](const Basic_vertex &lhs, const Basic_vertex &rhs)
60  {return lhs.id == rhs.id;}), vertices.end());
61 
62  return vertices.size() - count;
63  }
64 
65 
66  std::vector < Basic_vertex > extract_vertices(
67  std::vector < Basic_vertex > vertices,
68  const std::vector <pgr_edge_t > data_edges) {
69  if (data_edges.empty()) return vertices;
70 
71  vertices.reserve(vertices.size() + data_edges.size() * 2);
72 
73  for (const auto edge : data_edges) {
75 
76  vertex.id = edge.source;
77  vertices.push_back(vertex);
78 
79  vertex.id = edge.target;
80  vertices.push_back(vertex);
81  }
82 
83  /*
84  * sort and delete duplicates
85  */
86  std::stable_sort(vertices.begin(), vertices.end(),
87  [](const Basic_vertex &lhs, const Basic_vertex &rhs)
88  {return lhs.id < rhs.id;});
89 
90  vertices.erase(
91  std::unique(vertices.begin(), vertices.end(),
92  [](const Basic_vertex &lhs, const Basic_vertex &rhs)
93  {return lhs.id == rhs.id;}), vertices.end());
94 
95  return vertices;
96  }
97 
98 
99  std::vector < Basic_vertex > extract_vertices(
100  const std::vector <pgr_edge_t > data_edges) {
101  std::vector< Basic_vertex > vertices;
102  if (data_edges.empty()) return vertices;
103 
104  vertices.reserve(data_edges.size() * 2);
105 
106  for (const auto edge : data_edges) {
108 
109  vertex.id = edge.source;
110  vertices.push_back(vertex);
111 
112  vertex.id = edge.target;
113  vertices.push_back(vertex);
114  }
115 
116  /*
117  * sort and delete duplicates
118  */
119  std::stable_sort(vertices.begin(), vertices.end(),
120  [](const Basic_vertex &lhs, const Basic_vertex &rhs)
121  {return lhs.id < rhs.id;});
122 
123  vertices.erase(
124  std::unique(vertices.begin(), vertices.end(),
125  [](const Basic_vertex &lhs, const Basic_vertex &rhs)
126  {return lhs.id == rhs.id;}), vertices.end());
127 
128  return vertices;
129  }
130 
131  std::vector < Basic_vertex > extract_vertices(
132  const pgr_edge_t *data_edges, int64_t count) {
133  return extract_vertices(
134  std::vector < pgr_edge_t >(
135  data_edges, data_edges + count));
136  }
137 
138  std::vector < Basic_vertex > extract_vertices(
139  std::vector < Basic_vertex > vertices,
140  const pgr_edge_t *data_edges, int64_t count) {
141  return extract_vertices(
142  vertices, std::vector < pgr_edge_t >(
143  data_edges, data_edges + count));
144  }
145 
146 } // namespace pgrouting
std::ostream & operator<<(std::ostream &log, const Basic_vertex &v)
std::vector< Basic_vertex > extract_vertices(std::vector< Basic_vertex > vertices, const std::vector< pgr_edge_t > data_edges)
Assertions Handling.
size_t check_vertices(std::vector< Basic_vertex > vertices)