simple_planarity_test.cpp 1.9 KB

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