PGROUTING  3.2
pgr_kruskal.hpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: pgr_kruskal.hpp
3 
4 Copyright (c) 2015 pgRouting developers
6 
7 Copyright (c) 2018 Aditya Pratap Singh
9 
10 ------
11 
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16 
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21 
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 
26  ********************************************************************PGR-GNU*/
27 
28 #ifndef INCLUDE_SPANNINGTREE_PGR_KRUSKAL_HPP_
29 #define INCLUDE_SPANNINGTREE_PGR_KRUSKAL_HPP_
30 #pragma once
31 
32 #include <boost/graph/kruskal_min_spanning_tree.hpp>
33 #include <vector>
34 #include "spanningTree/pgr_mst.hpp"
36 
37 namespace pgrouting {
38 namespace functions {
39 
40 template <class G>
41 class Pgr_kruskal : public Pgr_mst<G> {
42  public:
43  std::vector<pgr_mst_rt> kruskal(G &graph);
44 
45  std::vector<pgr_mst_rt> kruskalBFS(
46  G &graph,
47  std::vector<int64_t> roots,
48  int64_t max_depth);
49 
50  std::vector<pgr_mst_rt> kruskalDFS(
51  G &graph,
52  std::vector<int64_t> roots,
53  int64_t max_depth);
54 
55  std::vector<pgr_mst_rt> kruskalDD(
56  G &graph,
57  std::vector<int64_t> roots,
58  double distance);
59 
60  private:
61  typedef typename G::B_G B_G;
62  typedef typename G::V V;
63  typedef typename G::E E;
64 
65  /* Does all the work */
66  void generate_mst(const G &graph);
67 };
68 
69 
70 template <class G>
71 void
73  this->clear();
74  /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
75  CHECK_FOR_INTERRUPTS();
76  boost::kruskal_minimum_spanning_tree(
77  graph.graph,
78  std::inserter(this->m_spanning_tree.edges, this->m_spanning_tree.edges.begin()),
79  boost::weight_map(get(&G::G_T_E::cost, graph.graph)));
80 }
81 
82 
83 template <class G>
84 std::vector<pgr_mst_rt>
86  G &graph) {
87  return this->mst(graph);
88 }
89 
90 
91 template <class G>
92 std::vector<pgr_mst_rt>
94  G &graph,
95  std::vector<int64_t> roots,
96  int64_t max_depth) {
97  return this->mstBFS(graph, roots, max_depth);
98 }
99 
100 template <class G>
101 std::vector<pgr_mst_rt>
103  G &graph,
104  std::vector<int64_t> roots,
105  int64_t max_depth) {
106  return this->mstDFS(graph, roots, max_depth);
107 }
108 
109 template <class G>
110 std::vector<pgr_mst_rt>
112  G &graph,
113  std::vector<int64_t> roots,
114  double distance) {
115  return this->mstDD(graph, roots, distance);
116 }
117 
118 
119 } // namespace functions
120 } // namespace pgrouting
121 
122 #endif // INCLUDE_SPANNINGTREE_PGR_KRUSKAL_HPP_
interruption.h
pgrouting::functions::Pgr_kruskal::kruskalDFS
std::vector< pgr_mst_rt > kruskalDFS(G &graph, std::vector< int64_t > roots, int64_t max_depth)
Definition: pgr_kruskal.hpp:102
pgrouting::functions::Pgr_kruskal::E
G::E E
Definition: pgr_kruskal.hpp:63
pgrouting::functions::Pgr_kruskal::V
G::V V
Definition: pgr_kruskal.hpp:62
pgrouting::functions::Pgr_kruskal::kruskalBFS
std::vector< pgr_mst_rt > kruskalBFS(G &graph, std::vector< int64_t > roots, int64_t max_depth)
Definition: pgr_kruskal.hpp:93
pgr_mst.hpp
pgrouting::functions::Pgr_kruskal::kruskal
std::vector< pgr_mst_rt > kruskal(G &graph)
Definition: pgr_kruskal.hpp:85
pgrouting::functions::Pgr_mst
Definition: pgr_mst.hpp:48
pgrouting::alphashape::E
boost::graph_traits< BG >::edge_descriptor E
Definition: pgr_alphaShape.h:57
pgrouting::alphashape::G
graph::Pgr_base_graph< BG, XY_vertex, Basic_edge > G
Definition: pgr_alphaShape.h:56
pgrouting::alphashape::V
boost::graph_traits< BG >::vertex_descriptor V
Definition: pgr_alphaShape.h:58
pgrouting::functions::Pgr_kruskal
Definition: pgr_kruskal.hpp:41
pgrouting::functions::Pgr_kruskal::generate_mst
void generate_mst(const G &graph)
Definition: pgr_kruskal.hpp:72
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56
pgrouting::functions::Pgr_kruskal::B_G
G::B_G B_G
Definition: pgr_kruskal.hpp:61
pgrouting::functions::Pgr_kruskal::kruskalDD
std::vector< pgr_mst_rt > kruskalDD(G &graph, std::vector< int64_t > roots, double distance)
Definition: pgr_kruskal.hpp:111