1 //=======================================================================
2 // Copyright 2007 Aaron Windsor
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 //=======================================================================
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>
16 #include <boost/graph/planar_canonical_ordering.hpp>
17 #include <boost/graph/boyer_myrvold_planar_test.hpp>
19 using namespace boost
;
21 int main(int argc
, char** argv
)
24 typedef adjacency_list
< vecS
, vecS
, undirectedS
,
25 property
< vertex_index_t
, int >, property
< edge_index_t
, int > >
28 // Create a maximal planar graph on 6 vertices
46 // Initialize the interior edge index
47 property_map
< graph
, edge_index_t
>::type e_index
= get(edge_index
, g
);
48 graph_traits
< graph
>::edges_size_type edge_count
= 0;
49 graph_traits
< graph
>::edge_iterator ei
, ei_end
;
50 for (boost::tie(ei
, ei_end
) = edges(g
); ei
!= ei_end
; ++ei
)
51 put(e_index
, *ei
, edge_count
++);
53 // Test for planarity - we know it is planar, we just want to
54 // compute the planar embedding as a side-effect
55 typedef std::vector
< graph_traits
< graph
>::edge_descriptor
> vec_t
;
56 std::vector
< vec_t
> embedding(num_vertices(g
));
57 if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph
= g
,
58 boyer_myrvold_params::embedding
= make_iterator_property_map(
59 embedding
.begin(), get(vertex_index
, g
))))
60 std::cout
<< "Input graph is planar" << std::endl
;
62 std::cout
<< "Input graph is not planar" << std::endl
;
64 typedef std::vector
< graph_traits
< graph
>::vertex_descriptor
>
67 ordering_storage_t ordering
;
68 planar_canonical_ordering(g
,
69 make_iterator_property_map(embedding
.begin(), get(vertex_index
, g
)),
70 std::back_inserter(ordering
));
72 ordering_storage_t::iterator oi
, oi_end
;
73 oi_end
= ordering
.end();
74 std::cout
<< "The planar canonical ordering is: ";
75 for (oi
= ordering
.begin(); oi
!= oi_end
; ++oi
)
76 std::cout
<< *oi
<< " ";
77 std::cout
<< std::endl
;