1 /*PGR-GNU*****************************************************************
2 File: pgr_boyerMyrvold.hpp
3 
4 Copyright (c) 2020 pgRouting developers
5 Mail: project@pgrouting.org
6 
7 Copyright (c) 2020 Himanshu Raj
8 Mail: raj.himanshu2@gmail.com
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_PLANAR_PGR_BOYERMYRVOLD_HPP_
25 #define INCLUDE_PLANAR_PGR_BOYERMYRVOLD_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/boyer_myrvold_planar_test.hpp>
33 #include <boost/graph/is_kuratowski_subgraph.hpp>
34 #include <boost/ref.hpp>
35 
36 #include <vector>
37 
38 #include "cpp_common/pgr_messages.h"
39 #include "cpp_common/pgr_base_graph.hpp"
40 #include "cpp_common/interruption.h"
41 #include "c_types/pgr_boyer_t.h"
42 //******************************************
43 namespace pgrouting {
44 namespace functions {
45 
46 template < class G >
47 class Pgr_boyerMyrvold : public pgrouting::Pgr_messages {
48  public:
49      typedef typename G::V V;
50      typedef typename G::E E;
51      typedef typename G::E_i E_i;
boyerMyrvold(G & graph)52      std::vector<pgr_boyer_t> boyerMyrvold(G &graph) {
53           return generateboyerMyrvold(graph);
54      }
55 
isPlanar(G & graph)56      bool isPlanar(G &graph) {
57           /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
58           CHECK_FOR_INTERRUPTS();
59           try {
60              return (boost::boyer_myrvold_planarity_test(graph.graph));
61           } catch (boost::exception const& ex) {
62              (void)ex;
63              throw;
64           } catch (std::exception &e) {
65              (void)e;
66              throw;
67           } catch (...) {
68              throw;
69           }
70           return false;
71      }
72 
73  private:
generateboyerMyrvold(const G & graph)74      std::vector< pgr_boyer_t >generateboyerMyrvold(const G &graph ) {
75      std::vector< pgr_boyer_t > results;
76      auto check = boost::boyer_myrvold_planarity_test(graph.graph);
77      if (check) {
78          E_i ei, ei_end;
79      for (boost::tie(ei, ei_end) = edges(graph.graph); ei != ei_end; ++ei) {
80          int64_t src = graph[graph.source(*ei)].id;
81          int64_t tgt = graph[graph.target(*ei)].id;
82          double cost = graph[*ei].cost;
83          pgr_boyer_t tmp;
84          tmp.source = src;
85          tmp.target = tgt;
86          tmp.cost = cost;
87          results.push_back(tmp);
88       }
89     }
90      return results;
91     }
92 };
93 }  // namespace functions
94 }  // namespace pgrouting
95 
96 #endif  // INCLUDE_PLANAR_PGR_BOYERMYRVOLD_HPP_
97