PGROUTING  2.5
pgr_componentsGraph.hpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: pgr_componentsGraph.hpp
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) 2017 Maoguang Wang
10 Mail: xjtumg1007@gmail.com
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 
30 #ifndef INCLUDE_COMPONENTS_PGR_COMPONENTSGRAPH_HPP_
31 #define INCLUDE_COMPONENTS_PGR_COMPONENTSGRAPH_HPP_
32 #pragma once
33 
34 
35 #include <vector>
36 
38 
39 
40 namespace pgrouting {
41 
42 namespace graph {
43 
44 template <class G, typename T_V, typename T_E>
46 
47 } // namespace graph
48 
50 boost::adjacency_list < boost::vecS, boost::vecS,
51  boost::undirectedS,
53  Basic_vertex, Basic_edge > ComponentsUndiGraph;
54 
55 namespace graph {
56 
57 template <class G, typename T_V, typename T_E>
58 class Pgr_componentsGraph : public Pgr_base_graph<G, T_V, T_E> {
59  public:
60  G graph;
61 
64  }
65 
66  template < typename T >
67  void insert_edges(const T *edges, int64_t count) {
68  insert_edges(std::vector < T >(edges, edges + count));
69  }
70 
71  template <typename T >
72  void insert_edges(const std::vector < T > &edges) {
73  for (const auto edge : edges) {
74  graph_add_edge(edge);
75  }
76  }
77 
78  private:
79  template < typename T >
80  void
81  graph_add_edge(const T &edge) {
82  bool inserted;
84  if ((edge.cost < 0) && (edge.reverse_cost < 0))
85  return;
86 
87  /*
88  * true: for source
89  * false: for target
90  */
91  auto vm_s = Pgr_base_graph< G, T_V, T_E >::get_V(T_V(edge, true));
92  auto vm_t = Pgr_base_graph< G, T_V, T_E >::get_V(T_V(edge, false));
93 
95  !=
98  !=
100  if (edge.cost >= 0) {
101  boost::tie(e, inserted) =
102  boost::add_edge(vm_s, vm_t, graph);
103  graph[e].cost = edge.cost;
104  graph[e].id = edge.id;
105  } else if (edge.reverse_cost >= 0) {
106  boost::tie(e, inserted) =
107  boost::add_edge(vm_t, vm_s, graph);
108  graph[e].cost = edge.reverse_cost;
109  graph[e].id = edge.id;
110  }
111  }
112 };
113 
114 } // namespace graph
115 } // namespace pgrouting
116 
117 #endif // INCLUDE_COMPONENTS_PGR_COMPONENTSGRAPH_HPP_
static edge_t edges[22573]
graph::Pgr_componentsGraph< boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, Basic_vertex, Basic_edge >, Basic_vertex, Basic_edge > ComponentsUndiGraph
Definition: trsp.h:31
V get_V(const T_V &vertex)
get the vertex descriptor of the vertex
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
void insert_edges(const std::vector< T > &edges)
Book keeping class for swapping orders between vehicles.
Definition: basic_edge.cpp:28
graphType
Definition: graph_enum.h:30
void insert_edges(const T *edges, int64_t count)
boost::graph_traits< G >::edge_descriptor E