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 
21 using namespace boost;
22 
main(int argc,char ** argv)23 int main(int argc, char** argv)
24 {
25 
26   typedef adjacency_list
27     < vecS,
28       vecS,
29       undirectedS,
30       property<vertex_index_t, int>,
31       property<edge_index_t, int>
32     >
33     graph;
34 
35   graph g(11);
36   add_edge(0,1,g);
37   add_edge(2,3,g);
38   add_edge(3,0,g);
39   add_edge(3,4,g);
40   add_edge(4,5,g);
41   add_edge(5,3,g);
42   add_edge(5,6,g);
43   add_edge(6,7,g);
44   add_edge(7,8,g);
45   add_edge(8,5,g);
46   add_edge(8,9,g);
47   add_edge(0,10,g);
48 
49 
50   //Initialize the interior edge index
51   property_map<graph, edge_index_t>::type e_index = get(edge_index, g);
52   graph_traits<graph>::edges_size_type edge_count = 0;
53   graph_traits<graph>::edge_iterator ei, ei_end;
54   for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
55     put(e_index, *ei, edge_count++);
56 
57 
58   //Test for planarity; compute the planar embedding as a side-effect
59   typedef std::vector< graph_traits<graph>::edge_descriptor > vec_t;
60   std::vector<vec_t> embedding(num_vertices(g));
61   if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
62                                    boyer_myrvold_params::embedding =
63                                      &embedding[0]
64                                    )
65       )
66     std::cout << "Input graph is planar" << std::endl;
67   else
68     std::cout << "Input graph is not planar" << std::endl;
69 
70   typedef std::vector< graph_traits<graph>::edges_size_type >
71     component_storage_t;
72   typedef iterator_property_map
73     < component_storage_t::iterator,
74       property_map<graph, edge_index_t>::type
75     >
76     component_map_t;
77 
78   component_storage_t component_storage(num_edges(g));
79   component_map_t component(component_storage.begin(), get(edge_index, g));
80 
81   std::cout << "Before calling make_biconnected_planar, the graph has "
82             << biconnected_components(g, component)
83             << " biconnected components" << std::endl;
84 
85   make_biconnected_planar(g, &embedding[0]);
86 
87   // Re-initialize the edge index, since we just added a few edges
88   edge_count = 0;
89   for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
90     put(e_index, *ei, edge_count++);
91 
92   // Re-size the storage for the biconnected components, since we
93   // just added a few edges
94 
95   component_storage.resize(num_edges(g));
96   component = component_map_t(component_storage.begin(), get(edge_index,g));
97 
98   std::cout << "After calling make_biconnected_planar, the graph has "
99             << biconnected_components(g, component)
100             << " biconnected components" << std::endl;
101 
102   if (boyer_myrvold_planarity_test(g))
103     std::cout << "Also, the graph is still planar." << std::endl;
104   else
105     std::cout << "But the graph is not still planar." << std::endl;
106 
107   return 0;
108 }
109