]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/canonical_ordering.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / graph / example / canonical_ordering.cpp
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/planar_canonical_ordering.hpp>
17 #include <boost/graph/boyer_myrvold_planar_test.hpp>
18
19 using namespace boost;
20
21 int main(int argc, char** argv)
22 {
23
24 typedef adjacency_list< vecS, vecS, undirectedS,
25 property< vertex_index_t, int >, property< edge_index_t, int > >
26 graph;
27
28 // Create a maximal planar graph on 6 vertices
29 graph g(6);
30
31 add_edge(0, 1, g);
32 add_edge(1, 2, g);
33 add_edge(2, 3, g);
34 add_edge(3, 4, g);
35 add_edge(4, 5, g);
36 add_edge(5, 0, g);
37
38 add_edge(0, 2, g);
39 add_edge(0, 3, g);
40 add_edge(0, 4, g);
41
42 add_edge(1, 3, g);
43 add_edge(1, 4, g);
44 add_edge(1, 5, g);
45
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++);
52
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;
61 else
62 std::cout << "Input graph is not planar" << std::endl;
63
64 typedef std::vector< graph_traits< graph >::vertex_descriptor >
65 ordering_storage_t;
66
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));
71
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;
78
79 return 0;
80 }