boyer_myrvold_planar_test.hpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. #ifndef __BOYER_MYRVOLD_PLANAR_TEST_HPP__
  9. #define __BOYER_MYRVOLD_PLANAR_TEST_HPP__
  10. #include <boost/graph/planar_detail/boyer_myrvold_impl.hpp>
  11. #include <boost/parameter.hpp>
  12. #include <boost/type_traits.hpp>
  13. #include <boost/mpl/bool.hpp>
  14. namespace boost
  15. {
  16. struct no_kuratowski_subgraph_isolation
  17. {
  18. };
  19. struct no_planar_embedding
  20. {
  21. };
  22. namespace boyer_myrvold_params
  23. {
  24. BOOST_PARAMETER_KEYWORD(tag, graph)
  25. BOOST_PARAMETER_KEYWORD(tag, embedding)
  26. BOOST_PARAMETER_KEYWORD(tag, kuratowski_subgraph)
  27. BOOST_PARAMETER_KEYWORD(tag, vertex_index_map)
  28. BOOST_PARAMETER_KEYWORD(tag, edge_index_map)
  29. typedef parameter::parameters< parameter::required< tag::graph >,
  30. tag::embedding, tag::kuratowski_subgraph, tag::vertex_index_map,
  31. tag::edge_index_map >
  32. boyer_myrvold_params_t;
  33. namespace core
  34. {
  35. template < typename ArgumentPack >
  36. bool dispatched_boyer_myrvold(
  37. ArgumentPack const& args, mpl::true_, mpl::true_)
  38. {
  39. // Dispatch for no planar embedding, no kuratowski subgraph
  40. // isolation
  41. typedef typename remove_const< typename parameter::value_type<
  42. ArgumentPack, tag::graph >::type >::type graph_t;
  43. typedef typename property_map< graph_t, vertex_index_t >::const_type
  44. vertex_default_index_map_t;
  45. typedef typename parameter::value_type< ArgumentPack,
  46. tag::vertex_index_map, vertex_default_index_map_t >::type
  47. vertex_index_map_t;
  48. graph_t const& g = args[graph];
  49. vertex_default_index_map_t v_d_map = get(vertex_index, g);
  50. vertex_index_map_t v_i_map = args[vertex_index_map | v_d_map];
  51. boyer_myrvold_impl< graph_t, vertex_index_map_t,
  52. graph::detail::no_old_handles, graph::detail::no_embedding >
  53. planarity_tester(g, v_i_map);
  54. return planarity_tester.is_planar() ? true : false;
  55. }
  56. template < typename ArgumentPack >
  57. bool dispatched_boyer_myrvold(
  58. ArgumentPack const& args, mpl::true_, mpl::false_)
  59. {
  60. // Dispatch for no planar embedding, kuratowski subgraph isolation
  61. typedef typename remove_const< typename parameter::value_type<
  62. ArgumentPack, tag::graph >::type >::type graph_t;
  63. typedef typename property_map< graph_t, vertex_index_t >::const_type
  64. vertex_default_index_map_t;
  65. typedef typename parameter::value_type< ArgumentPack,
  66. tag::vertex_index_map, vertex_default_index_map_t >::type
  67. vertex_index_map_t;
  68. typedef typename property_map< graph_t, edge_index_t >::const_type
  69. edge_default_index_map_t;
  70. typedef typename parameter::value_type< ArgumentPack,
  71. tag::edge_index_map, edge_default_index_map_t >::type
  72. edge_index_map_t;
  73. graph_t const& g = args[graph];
  74. vertex_default_index_map_t v_d_map = get(vertex_index, g);
  75. vertex_index_map_t v_i_map = args[vertex_index_map | v_d_map];
  76. edge_default_index_map_t e_d_map = get(edge_index, g);
  77. edge_index_map_t e_i_map = args[edge_index_map | e_d_map];
  78. boyer_myrvold_impl< graph_t, vertex_index_map_t,
  79. graph::detail::store_old_handles, graph::detail::no_embedding >
  80. planarity_tester(g, v_i_map);
  81. if (planarity_tester.is_planar())
  82. return true;
  83. else
  84. {
  85. planarity_tester.extract_kuratowski_subgraph(
  86. args[kuratowski_subgraph], e_i_map);
  87. return false;
  88. }
  89. }
  90. template < typename ArgumentPack >
  91. bool dispatched_boyer_myrvold(
  92. ArgumentPack const& args, mpl::false_, mpl::true_)
  93. {
  94. // Dispatch for planar embedding, no kuratowski subgraph isolation
  95. typedef typename remove_const< typename parameter::value_type<
  96. ArgumentPack, tag::graph >::type >::type graph_t;
  97. typedef typename property_map< graph_t, vertex_index_t >::const_type
  98. vertex_default_index_map_t;
  99. typedef typename parameter::value_type< ArgumentPack,
  100. tag::vertex_index_map, vertex_default_index_map_t >::type
  101. vertex_index_map_t;
  102. graph_t const& g = args[graph];
  103. vertex_default_index_map_t v_d_map = get(vertex_index, g);
  104. vertex_index_map_t v_i_map = args[vertex_index_map | v_d_map];
  105. boyer_myrvold_impl< graph_t, vertex_index_map_t,
  106. graph::detail::no_old_handles,
  107. #ifdef BOOST_GRAPH_PREFER_STD_LIB
  108. graph::detail::std_list
  109. #else
  110. graph::detail::recursive_lazy_list
  111. #endif
  112. >
  113. planarity_tester(g, v_i_map);
  114. if (planarity_tester.is_planar())
  115. {
  116. planarity_tester.make_edge_permutation(args[embedding]);
  117. return true;
  118. }
  119. else
  120. return false;
  121. }
  122. template < typename ArgumentPack >
  123. bool dispatched_boyer_myrvold(
  124. ArgumentPack const& args, mpl::false_, mpl::false_)
  125. {
  126. // Dispatch for planar embedding, kuratowski subgraph isolation
  127. typedef typename remove_const< typename parameter::value_type<
  128. ArgumentPack, tag::graph >::type >::type graph_t;
  129. typedef typename property_map< graph_t, vertex_index_t >::const_type
  130. vertex_default_index_map_t;
  131. typedef typename parameter::value_type< ArgumentPack,
  132. tag::vertex_index_map, vertex_default_index_map_t >::type
  133. vertex_index_map_t;
  134. typedef typename property_map< graph_t, edge_index_t >::const_type
  135. edge_default_index_map_t;
  136. typedef typename parameter::value_type< ArgumentPack,
  137. tag::edge_index_map, edge_default_index_map_t >::type
  138. edge_index_map_t;
  139. graph_t const& g = args[graph];
  140. vertex_default_index_map_t v_d_map = get(vertex_index, g);
  141. vertex_index_map_t v_i_map = args[vertex_index_map | v_d_map];
  142. edge_default_index_map_t e_d_map = get(edge_index, g);
  143. edge_index_map_t e_i_map = args[edge_index_map | e_d_map];
  144. boyer_myrvold_impl< graph_t, vertex_index_map_t,
  145. graph::detail::store_old_handles,
  146. #ifdef BOOST_BGL_PREFER_STD_LIB
  147. graph::detail::std_list
  148. #else
  149. graph::detail::recursive_lazy_list
  150. #endif
  151. >
  152. planarity_tester(g, v_i_map);
  153. if (planarity_tester.is_planar())
  154. {
  155. planarity_tester.make_edge_permutation(args[embedding]);
  156. return true;
  157. }
  158. else
  159. {
  160. planarity_tester.extract_kuratowski_subgraph(
  161. args[kuratowski_subgraph], e_i_map);
  162. return false;
  163. }
  164. }
  165. template < typename ArgumentPack >
  166. bool boyer_myrvold_planarity_test(ArgumentPack const& args)
  167. {
  168. typedef typename parameter::binding< ArgumentPack,
  169. tag::kuratowski_subgraph,
  170. const no_kuratowski_subgraph_isolation& >::type
  171. kuratowski_arg_t;
  172. typedef typename parameter::binding< ArgumentPack, tag::embedding,
  173. const no_planar_embedding& >::type embedding_arg_t;
  174. return dispatched_boyer_myrvold(args,
  175. boost::is_same< embedding_arg_t, const no_planar_embedding& >(),
  176. boost::is_same< kuratowski_arg_t,
  177. const no_kuratowski_subgraph_isolation& >());
  178. }
  179. } // namespace core
  180. } // namespace boyer_myrvold_params
  181. template < typename A0 > bool boyer_myrvold_planarity_test(A0 const& arg0)
  182. {
  183. return boyer_myrvold_params::core::boyer_myrvold_planarity_test(
  184. boyer_myrvold_params::boyer_myrvold_params_t()(arg0));
  185. }
  186. template < typename A0, typename A1 >
  187. // bool boyer_myrvold_planarity_test(A0 const& arg0, A1 const& arg1)
  188. bool boyer_myrvold_planarity_test(A0 const& arg0, A1 const& arg1)
  189. {
  190. return boyer_myrvold_params::core::boyer_myrvold_planarity_test(
  191. boyer_myrvold_params::boyer_myrvold_params_t()(arg0, arg1));
  192. }
  193. template < typename A0, typename A1, typename A2 >
  194. bool boyer_myrvold_planarity_test(
  195. A0 const& arg0, A1 const& arg1, A2 const& arg2)
  196. {
  197. return boyer_myrvold_params::core::boyer_myrvold_planarity_test(
  198. boyer_myrvold_params::boyer_myrvold_params_t()(arg0, arg1, arg2));
  199. }
  200. template < typename A0, typename A1, typename A2, typename A3 >
  201. bool boyer_myrvold_planarity_test(
  202. A0 const& arg0, A1 const& arg1, A2 const& arg2, A3 const& arg3)
  203. {
  204. return boyer_myrvold_params::core::boyer_myrvold_planarity_test(
  205. boyer_myrvold_params::boyer_myrvold_params_t()(arg0, arg1, arg2, arg3));
  206. }
  207. template < typename A0, typename A1, typename A2, typename A3, typename A4 >
  208. bool boyer_myrvold_planarity_test(A0 const& arg0, A1 const& arg1,
  209. A2 const& arg2, A3 const& arg3, A4 const& arg4)
  210. {
  211. return boyer_myrvold_params::core::boyer_myrvold_planarity_test(
  212. boyer_myrvold_params::boyer_myrvold_params_t()(
  213. arg0, arg1, arg2, arg3, arg4));
  214. }
  215. }
  216. #endif //__BOYER_MYRVOLD_PLANAR_TEST_HPP__