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/boyer_myrvold_planar_test.hpp>
11
main(int argc,char ** argv)12 int main(int argc, char** argv)
13 {
14
15 // This program illustrates a simple use of boyer_myrvold_planar_embedding
16 // as a simple yes/no test for planarity.
17
18 using namespace boost;
19
20 typedef adjacency_list< vecS, vecS, undirectedS,
21 property< vertex_index_t, int > >
22 graph;
23
24 graph K_4(4);
25 add_edge(0, 1, K_4);
26 add_edge(0, 2, K_4);
27 add_edge(0, 3, K_4);
28 add_edge(1, 2, K_4);
29 add_edge(1, 3, K_4);
30 add_edge(2, 3, K_4);
31
32 if (boyer_myrvold_planarity_test(K_4))
33 std::cout << "K_4 is planar." << std::endl;
34 else
35 std::cout << "ERROR! K_4 should have been recognized as planar!"
36 << std::endl;
37
38 graph K_5(5);
39 add_edge(0, 1, K_5);
40 add_edge(0, 2, K_5);
41 add_edge(0, 3, K_5);
42 add_edge(0, 4, K_5);
43 add_edge(1, 2, K_5);
44 add_edge(1, 3, K_5);
45 add_edge(1, 4, K_5);
46 add_edge(2, 3, K_5);
47 add_edge(2, 4, K_5);
48
49 // We've almost created a K_5 - it's missing one edge - so it should still
50 // be planar at this point.
51
52 if (boyer_myrvold_planarity_test(K_5))
53 std::cout << "K_5 (minus an edge) is planar." << std::endl;
54 else
55 std::cout << "ERROR! K_5 with one edge missing should"
56 << " have been recognized as planar!" << std::endl;
57
58 // Now add the final edge...
59 add_edge(3, 4, K_5);
60
61 if (boyer_myrvold_planarity_test(K_5))
62 std::cout << "ERROR! K_5 was recognized as planar!" << std::endl;
63 else
64 std::cout << "K_5 is not planar." << std::endl;
65
66 return 0;
67 }
68