• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //=======================================================================
2 // Copyright 2007 Aaron Windsor
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
8 #include <iostream>
9 #include <boost/graph/adjacency_list.hpp>
10 #include <boost/graph/properties.hpp>
11 #include <boost/graph/graph_traits.hpp>
12 #include <boost/property_map/property_map.hpp>
13 #include <boost/ref.hpp>
14 #include <vector>
15 
16 #include <boost/graph/biconnected_components.hpp>
17 #include <boost/graph/make_biconnected_planar.hpp>
18 #include <boost/graph/boyer_myrvold_planar_test.hpp>
19 
20 using namespace boost;
21 
main(int argc,char ** argv)22 int main(int argc, char** argv)
23 {
24 
25     typedef adjacency_list< vecS, vecS, undirectedS,
26         property< vertex_index_t, int >, property< edge_index_t, int > >
27         graph;
28 
29     graph g(11);
30     add_edge(0, 1, g);
31     add_edge(2, 3, g);
32     add_edge(3, 0, g);
33     add_edge(3, 4, g);
34     add_edge(4, 5, g);
35     add_edge(5, 3, g);
36     add_edge(5, 6, g);
37     add_edge(6, 7, g);
38     add_edge(7, 8, g);
39     add_edge(8, 5, g);
40     add_edge(8, 9, g);
41     add_edge(0, 10, g);
42 
43     // Initialize the interior edge index
44     property_map< graph, edge_index_t >::type e_index = get(edge_index, g);
45     graph_traits< graph >::edges_size_type edge_count = 0;
46     graph_traits< graph >::edge_iterator ei, ei_end;
47     for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
48         put(e_index, *ei, edge_count++);
49 
50     // Test for planarity; compute the planar embedding as a side-effect
51     typedef std::vector< graph_traits< graph >::edge_descriptor > vec_t;
52     std::vector< vec_t > embedding(num_vertices(g));
53     if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
54             boyer_myrvold_params::embedding = &embedding[0]))
55         std::cout << "Input graph is planar" << std::endl;
56     else
57         std::cout << "Input graph is not planar" << std::endl;
58 
59     typedef std::vector< graph_traits< graph >::edges_size_type >
60         component_storage_t;
61     typedef iterator_property_map< component_storage_t::iterator,
62         property_map< graph, edge_index_t >::type >
63         component_map_t;
64 
65     component_storage_t component_storage(num_edges(g));
66     component_map_t component(component_storage.begin(), get(edge_index, g));
67 
68     std::cout << "Before calling make_biconnected_planar, the graph has "
69               << biconnected_components(g, component)
70               << " biconnected components" << std::endl;
71 
72     make_biconnected_planar(g, &embedding[0]);
73 
74     // Re-initialize the edge index, since we just added a few edges
75     edge_count = 0;
76     for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
77         put(e_index, *ei, edge_count++);
78 
79     // Re-size the storage for the biconnected components, since we
80     // just added a few edges
81 
82     component_storage.resize(num_edges(g));
83     component = component_map_t(component_storage.begin(), get(edge_index, g));
84 
85     std::cout << "After calling make_biconnected_planar, the graph has "
86               << biconnected_components(g, component)
87               << " biconnected components" << std::endl;
88 
89     if (boyer_myrvold_planarity_test(g))
90         std::cout << "Also, the graph is still planar." << std::endl;
91     else
92         std::cout << "But the graph is not still planar." << std::endl;
93 
94     return 0;
95 }
96