PGROUTING  3.2
pgr_makeConnected.hpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: pgr_makeConnected.hpp
3 
4 Copyright (c) 2020 pgRouting developers
6 
7 Copyright (c) 2020 Himanshu Raj
9 
10 ------
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
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 ********************************************************************PGR-GNU*/
23 
24 #ifndef INCLUDE_COMPONENTS_PGR_MAKECONNECTED_HPP_
25 #define INCLUDE_COMPONENTS_PGR_MAKECONNECTED_HPP_
26 #pragma once
27 
28 #include <boost/graph/adjacency_list.hpp>
29 #include <boost/graph/properties.hpp>
30 #include <boost/graph/graph_traits.hpp>
31 #include <boost/property_map/property_map.hpp>
32 #include <boost/graph/connected_components.hpp>
33 #include <boost/graph/make_connected.hpp>
34 #include <boost/ref.hpp>
35 
36 #include <vector>
37 #include <set>
38 #include <map>
39 
43 //******************************************
44 
45 namespace pgrouting {
46 namespace functions {
47 
48 template < class G >
50  public:
51  typedef typename G::V V;
52  typedef typename G::E E;
53  typedef typename G::E_i E_i;
54  std::vector<pgr_makeConnected_t> makeConnected(G &graph) {
55  return generatemakeConnected(graph);
56  }
57 
58  private:
59  std::vector< pgr_makeConnected_t > generatemakeConnected(G &graph ) {
60  std::vector<size_t> component(boost::num_vertices(graph.graph));
61  auto comp = boost::connected_components(graph.graph, &component[0]);
62  comp--;
63  auto edgeCount = boost::num_edges(graph.graph);
64  size_t newEdge = 0;
65  log << "Number of Components before: " << boost::connected_components(graph.graph, &component[0]) << "\n";
66  size_t i = 0;
67 
68  /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
69  CHECK_FOR_INTERRUPTS();
70  try {
71  boost::make_connected(graph.graph);
72  } catch (boost::exception const& ex) {
73  (void)ex;
74  throw;
75  } catch (std::exception &e) {
76  (void)e;
77  throw;
78  } catch (...) {
79  throw;
80  }
81 
82  log << "Number of Components after: " << boost::connected_components(graph.graph, &component[0]) << "\n";
83  E_i ei, ei_end;
84  std::vector< pgr_makeConnected_t > results(comp);
85  for (boost::tie(ei, ei_end) = edges(graph.graph); ei != ei_end; ++ei) {
86  int64_t src = graph[graph.source(*ei)].id;
87  int64_t tgt = graph[graph.target(*ei)].id;
88  log<< "src:" << src<< "tgt:" << tgt <<"\n";
89  if (newEdge >= edgeCount) {
90  results[i].start_vid = src;
91  results[i].end_vid = tgt;
92  i++;
93  }
94  newEdge++;
95  }
96  return results;
97  }
98 };
99 } // namespace functions
100 } // namespace pgrouting
101 
102 #endif // INCLUDE_COMPONENTS_PGR_MAKECONNECTED_HPP_
pgrouting::Pgr_messages
Definition: pgr_messages.h:39
interruption.h
pgr_base_graph.hpp
pgrouting::functions::Pgr_makeConnected::E
G::E E
Definition: pgr_makeConnected.hpp:52
pgr_messages.h
pgrouting::functions::Pgr_makeConnected
Definition: pgr_makeConnected.hpp:49
pgrouting::Pgr_messages::log
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:81
pgrouting::functions::Pgr_makeConnected::generatemakeConnected
std::vector< pgr_makeConnected_t > generatemakeConnected(G &graph)
Definition: pgr_makeConnected.hpp:59
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::functions::Pgr_makeConnected::makeConnected
std::vector< pgr_makeConnected_t > makeConnected(G &graph)
Definition: pgr_makeConnected.hpp:54
pgrouting::functions::Pgr_makeConnected::E_i
G::E_i E_i
Definition: pgr_makeConnected.hpp:53
pgrouting::functions::Pgr_makeConnected::V
G::V V
Definition: pgr_makeConnected.hpp:51
pgrouting::alphashape::V
boost::graph_traits< BG >::vertex_descriptor V
Definition: pgr_alphaShape.h:58
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56