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
ch_vertex.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: ch_vertex.cpp
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 Function's developer:
9 Copyright (c) 2016 Rohith Reddy
10 Mail:
11 
12 ------
13 
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 
28  ********************************************************************PGR-GNU*/
29 #include <algorithm>
30 #include <vector>
31 #include "./ch_vertex.h"
32 
33 namespace pgrouting {
34 namespace contraction {
35 
36 
38  return m_contracted_vertices;
39 }
40 
41 
43  if (m_contracted_vertices.size() == 0)
44  return false;
45  return true;
46 }
47 
48 void Vertex::add_contracted_vertex(Vertex& v, int64_t vid) {
49  // adding the id(boost graph) of the contracted vertex v
50  m_contracted_vertices += vid;
51  // adding the ids of the contracted vertices of the given vertex v
53  // empty the contracted vertices of the given vertex v
55 }
56 
57 std::ostream& operator <<(std::ostream& os, const Vertex& v) {
58  os << "{\n id: " << v.id << ",\n";
59  os << " contracted vertices: ";
60  os << v.contracted_vertices();
61  os << "\n}";
62  os << "\n";
63  return os;
64 }
65 
66 
67 size_t
69  std::vector < Vertex > vertices) {
70  auto count(vertices.size());
71  std::stable_sort(
72  vertices.begin(), vertices.end(),
73  [](const Vertex &lhs, const Vertex &rhs)
74  {return lhs.id < rhs.id;});
75  vertices.erase(
76  std::unique(
77  vertices.begin(), vertices.end(),
78  [](const Vertex &lhs, const Vertex &rhs)
79  {return lhs.id == rhs.id;}), vertices.end());
80  return count - vertices.size();
81 }
82 
83 std::vector < Vertex >
85  const std::vector <pgr_edge_t > &data_edges) {
86  std::vector< Vertex > vertices;
87  if (data_edges.empty()) return vertices;
88  vertices.reserve(data_edges.size() * 2);
89  for (const auto edge : data_edges) {
90  Vertex v_source(edge, true);
91  vertices.push_back(v_source);
92 
93  Vertex v_target(edge, false);
94  vertices.push_back(v_target);
95  }
96  /*
97  * sort and delete duplicates
98  */
99  std::stable_sort(
100  vertices.begin(), vertices.end(),
101  [](const Vertex &lhs, const Vertex &rhs)
102  {return lhs.id < rhs.id;});
103  vertices.erase(
104  std::unique(
105  vertices.begin(), vertices.end(),
106  [](const Vertex &lhs, const Vertex &rhs)
107  {return lhs.id == rhs.id;}), vertices.end());
108  return vertices;
109 }
110 
111 std::vector < Vertex >
113  const pgr_edge_t *data_edges,
114  int64_t count) {
115  return extract_vertices(
116  std::vector < pgr_edge_t >(data_edges, data_edges + count));
117 }
118 
119 } // namespace contraction
120 } // namespace pgrouting
void add_contracted_vertex(Vertex &v, int64_t vid)
Definition: ch_vertex.cpp:48
bool has_contracted_vertices() const
Definition: ch_vertex.cpp:42
std::ostream & operator<<(std::ostream &os, const Edge &e)
Definition: ch_edge.cpp:111
const Identifiers< int64_t > & contracted_vertices() const
Definition: ch_vertex.cpp:37
Identifiers< int64_t > m_contracted_vertices
Definition: ch_vertex.h:60
size_t size() const
Definition: identifiers.hpp:49
size_t check_vertices(std::vector< Vertex > vertices)
Definition: ch_vertex.cpp:68
std::vector< Vertex > extract_vertices(const std::vector< pgr_edge_t > &data_edges)
Definition: ch_vertex.cpp:84