make_biconnected_planar.cpp 3.3 KB

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