make_bicon_planar_test.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 <boost/graph/adjacency_list.hpp>
  9. #include <boost/graph/properties.hpp>
  10. #include <boost/graph/make_biconnected_planar.hpp>
  11. #include <boost/graph/biconnected_components.hpp>
  12. #include <boost/graph/boyer_myrvold_planar_test.hpp>
  13. #include <boost/property_map/property_map.hpp>
  14. #include <boost/property_map/vector_property_map.hpp>
  15. #include <boost/test/minimal.hpp>
  16. using namespace boost;
  17. template <typename Graph>
  18. void reset_edge_index(Graph& g)
  19. {
  20. typename property_map<Graph, edge_index_t>::type index = get(edge_index, g);
  21. typename graph_traits<Graph>::edge_iterator ei, ei_end;
  22. typename graph_traits<Graph>::edges_size_type cnt = 0;
  23. for(boost::tie(ei,ei_end) = edges(g); ei != ei_end; ++ei)
  24. put(index, *ei, cnt++);
  25. }
  26. template <typename Graph>
  27. void make_line_graph(Graph& g, int size)
  28. {
  29. typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
  30. vertex_t prev_vertex = add_vertex(g);
  31. for(int i = 1; i < size; ++i)
  32. {
  33. vertex_t curr_vertex = add_vertex(g);
  34. add_edge(curr_vertex, prev_vertex, g);
  35. prev_vertex = curr_vertex;
  36. }
  37. }
  38. struct UpdateVertexIndex
  39. {
  40. template <typename Graph>
  41. void update(Graph& g)
  42. {
  43. typename property_map<Graph, vertex_index_t>::type index = get(vertex_index, g);
  44. typename graph_traits<Graph>::vertex_iterator vi, vi_end;
  45. typename graph_traits<Graph>::vertices_size_type cnt = 0;
  46. for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
  47. put(index, *vi, cnt++);
  48. }
  49. };
  50. struct NoVertexIndexUpdater
  51. {
  52. template <typename Graph> void update(Graph&) {}
  53. };
  54. template <typename Graph, typename VertexIndexUpdater>
  55. void test_line_graph(VertexIndexUpdater vertex_index_updater, int size)
  56. {
  57. Graph g;
  58. make_line_graph(g, size);
  59. vertex_index_updater.update(g);
  60. reset_edge_index(g);
  61. typedef std::vector< typename graph_traits<Graph>::edge_descriptor > edge_vector_t;
  62. typedef std::vector< edge_vector_t > embedding_storage_t;
  63. typedef iterator_property_map
  64. < typename embedding_storage_t::iterator,
  65. typename property_map<Graph, vertex_index_t>::type
  66. > embedding_t;
  67. embedding_storage_t embedding_storage(num_vertices(g));
  68. embedding_t embedding(embedding_storage.begin(), get(vertex_index, g));
  69. typename graph_traits<Graph>::vertex_iterator vi, vi_end;
  70. for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
  71. std::copy(out_edges(*vi,g).first, out_edges(*vi,g).second, std::back_inserter(embedding[*vi]));
  72. BOOST_CHECK(biconnected_components(g, make_vector_property_map<int>(get(edge_index,g))) > 1);
  73. BOOST_CHECK(boyer_myrvold_planarity_test(g));
  74. make_biconnected_planar(g, embedding);
  75. reset_edge_index(g);
  76. BOOST_CHECK(biconnected_components(g, make_vector_property_map<int>(get(edge_index,g))) == 1);
  77. BOOST_CHECK(boyer_myrvold_planarity_test(g));
  78. }
  79. int test_main(int, char* [])
  80. {
  81. typedef adjacency_list
  82. <vecS,
  83. vecS,
  84. undirectedS,
  85. property<vertex_index_t, int>,
  86. property<edge_index_t, int>
  87. >
  88. VVgraph_t;
  89. typedef adjacency_list
  90. <vecS,
  91. listS,
  92. undirectedS,
  93. property<vertex_index_t, int>,
  94. property<edge_index_t, int>
  95. >
  96. VLgraph_t;
  97. typedef adjacency_list
  98. <listS,
  99. vecS,
  100. undirectedS,
  101. property<vertex_index_t, int>,
  102. property<edge_index_t, int>
  103. >
  104. LVgraph_t;
  105. typedef adjacency_list
  106. <listS,
  107. listS,
  108. undirectedS,
  109. property<vertex_index_t, int>,
  110. property<edge_index_t, int>
  111. >
  112. LLgraph_t;
  113. typedef adjacency_list
  114. <setS,
  115. setS,
  116. undirectedS,
  117. property<vertex_index_t, int>,
  118. property<edge_index_t, int>
  119. >
  120. SSgraph_t;
  121. test_line_graph<VVgraph_t>(NoVertexIndexUpdater(), 10);
  122. test_line_graph<VVgraph_t>(NoVertexIndexUpdater(), 50);
  123. test_line_graph<VLgraph_t>(UpdateVertexIndex(), 3);
  124. test_line_graph<VLgraph_t>(UpdateVertexIndex(), 30);
  125. test_line_graph<LVgraph_t>(NoVertexIndexUpdater(), 15);
  126. test_line_graph<LVgraph_t>(NoVertexIndexUpdater(), 45);
  127. test_line_graph<LLgraph_t>(UpdateVertexIndex(), 8);
  128. test_line_graph<LLgraph_t>(UpdateVertexIndex(), 19);
  129. test_line_graph<SSgraph_t>(UpdateVertexIndex(), 13);
  130. test_line_graph<SSgraph_t>(UpdateVertexIndex(), 20);
  131. return 0;
  132. }