PGROUTING  3.2
pgr_bipartite_driver.hpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: pgr_bipartite_driver.hpp
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
7 
8 Function's developer:
9 Copyright (c) 2020 Prakash Tiwari
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 
31 #ifndef INCLUDE_COLORING_PGR_BIPARTITE_DRIVER_HPP_
32 #define INCLUDE_COLORING_PGR_BIPARTITE_DRIVER_HPP_
33 #pragma once
34 
35 #include <boost/property_map/property_map.hpp>
36 #include <boost/property_map/vector_property_map.hpp>
37 #include <boost/type_traits.hpp>
38 #include <boost/graph/bipartite.hpp>
39 
40 #include <iostream>
41 #include <algorithm>
42 #include <vector>
43 
47 
48 
49 namespace pgrouting {
50 namespace functions {
51 
52 template<class G>
54  public:
55  typedef typename G::V_i V_i;
56  std::vector<pgr_bipartite_rt> print_Bipartite(
57  G &graph) {
58  std::vector<pgr_bipartite_rt> results;
59  std::vector <boost::default_color_type> partition(graph.num_vertices());
60  auto partition_map =
61  make_iterator_property_map(partition.begin(), boost::get(boost::vertex_index, graph.graph));
62 
63  /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
64  CHECK_FOR_INTERRUPTS();
65  try {
66  boost::is_bipartite(graph.graph, boost::get(boost::vertex_index, graph.graph), partition_map);
67  } catch (boost::exception const& ex) {
68  (void)ex;
69  throw;
70  } catch (std::exception &e) {
71  (void)e;
72  throw;
73  } catch (...) {
74  throw;
75  }
76  V_i v, vend;
77  for (boost::tie(v, vend) = vertices(graph.graph); v != vend; ++v) {
78  int64_t vid = graph[*v].id;
79  boost::get(partition_map, *v) ==
80  boost::color_traits <boost::default_color_type>::white() ?
81  results.push_back({vid, 0}) :results.push_back({vid, 1});
82  }
83  return results;
84  }
85  std::vector<pgr_bipartite_rt> pgr_bipartite(
86  G &graph ){
87  std::vector<pgr_bipartite_rt> results;
88  bool bipartite = boost::is_bipartite(graph.graph);
89  if (bipartite) results = print_Bipartite(graph);
90  return results;
91  }
92 };
93 } // namespace functions
94 } // namespace pgrouting
95 #endif // INCLUDE_COLORING_PGR_BIPARTITE_DRIVER_HPP_
pgrouting::Pgr_messages
Definition: pgr_messages.h:39
interruption.h
pgrouting::functions::Pgr_Bipartite
Definition: pgr_bipartite_driver.hpp:53
pgr_base_graph.hpp
pgrouting::functions::Pgr_Bipartite::pgr_bipartite
std::vector< pgr_bipartite_rt > pgr_bipartite(G &graph)
Definition: pgr_bipartite_driver.hpp:85
pgr_messages.h
pgrouting::functions::Pgr_Bipartite::V_i
G::V_i V_i
Definition: pgr_bipartite_driver.hpp:55
pgrouting::alphashape::G
graph::Pgr_base_graph< BG, XY_vertex, Basic_edge > G
Definition: pgr_alphaShape.h:56
pgrouting::functions::Pgr_Bipartite::print_Bipartite
std::vector< pgr_bipartite_rt > print_Bipartite(G &graph)
Definition: pgr_bipartite_driver.hpp:56
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56