boyer_myrvold.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <HTML>
  2. <!-- Copyright 2007 Aaron Windsor
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. -->
  7. <Head>
  8. <Title>Boost Graph Library: Boyer-Myrvold Planarity Testing/Embedding</Title>
  9. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  10. ALINK="#ff0000">
  11. <IMG SRC="../../../boost.png"
  12. ALT="C++ Boost" width="277" height="86">
  13. <BR Clear>
  14. <H1>Boyer-Myrvold Planarity Testing/Embedding</H1>
  15. <p>
  16. A graph is <a href="./planar_graphs.html#planar"><i>planar</i></a> if it can
  17. be drawn in two-dimensional space without any of its edges crossing. Such a
  18. drawing of a planar graph is called a
  19. <a href="./planar_graphs.html#plane_drawing"><i>plane drawing</i></a>. Each
  20. plane drawing belongs to an equivalence class called a <i>planar embedding</i>
  21. <a href="#1">[1]</a> that is defined by the clockwise ordering of adjacent
  22. edges around each vertex in the graph. A planar embedding is a convenient
  23. intermediate representation of an actual drawing of a planar graph, and many
  24. planar graph drawing algorithms are formulated as functions mapping a planar
  25. embedding to a plane drawing.
  26. <br>
  27. <br>
  28. <table align="center" class="image">
  29. <caption align="bottom"><h5>A planar graph (top left), along with a planar
  30. embedding of that graph (bottom left) can be used to create a plane drawing
  31. (right) by embedding edges around each vertex in the order in which they
  32. appear in the planar embedding.
  33. </h5></caption>
  34. <tr><td>
  35. <img src="./figs/embedding_illustration.png">
  36. </td></tr>
  37. <tr></tr>
  38. <tr></tr>
  39. </table>
  40. <br>
  41. <p>
  42. The function <tt>boyer_myrvold_planarity_test</tt> implements the planarity
  43. testing/embedding algorithm of Boyer and Myrvold
  44. [<a href="./bibliography.html#boyermyrvold04">70</a>].
  45. <tt>boyer_myrvold_planarity_test</tt> returns <tt>true</tt> if the input graph
  46. is planar and <tt>false</tt> otherwise. As a side-effect of this test, a planar
  47. embedding can be constructed if the graph is planar or a minimal set of edges
  48. that form a <a href = "./planar_graphs.html#kuratowskisubgraphs">Kuratowski
  49. subgraph</a> can be found if the graph is not planar.
  50. <tt>boyer_myrvold_planarity_test</tt> uses named parameter arguments (courtesy
  51. of the <a href="../../parameter/doc/html/index.html">Boost.Parameter</a>
  52. library) to specify what the function actually does. Some examples are:
  53. <ul>
  54. <li>Testing whether or not a graph is planar:
  55. <pre>
  56. bool is_planar = boyer_myrvold_planarity_test(g);
  57. </pre>
  58. <li>Computing a planar embedding for a graph if it is planar, otherwise finding
  59. a set of edges that forms an obstructing Kuratowski subgraph:
  60. <pre>
  61. if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
  62. boyer_myrvold_params::embedding = embedding_pmap,
  63. boyer_myrvold_params::kuratowski_subgraph = out_itr
  64. )
  65. )
  66. {
  67. //do something with the embedding in embedding_pmap
  68. }
  69. else
  70. {
  71. //do something with the kuratowski subgraph output to out_itr
  72. }
  73. </pre>
  74. </ul>
  75. <p>
  76. The parameters passed to <tt>boyer_myrvold_planarity_test</tt> in the examples
  77. above do more than just carry the data structures used for input and output -
  78. the algorithm is optimized at compile time based on which parameters are
  79. present. A complete list of parameters accepted and their interactions are
  80. described below.
  81. <p>
  82. <tt>boyer_myrvold_planarity_test</tt> accepts as input any undirected graph,
  83. even those with self-loops and multiple edges.
  84. However, many planar graph drawing algorithms make additional restrictions
  85. on the structure of the input graph - for example, requiring that the input
  86. graph is connected, biconnected, or even maximal planar (triangulated.)
  87. Fortunately, any planar graph on <i>n</i> vertices that lacks one of these
  88. properties can be augmented with additional edges so that it satisfies that
  89. property in <i>O(n)</i> time - the functions
  90. <tt><a href="./make_connected.html">make_connected</a></tt>,
  91. <tt><a href="./make_biconnected_planar.html">make_biconnected_planar</a></tt>,
  92. and <tt><a href="./make_maximal_planar.html">make_maximal_planar</a></tt>
  93. exist for this purpose. If the graph drawing algorithm you're using requires,
  94. say, a biconnected graph, then you must make your input graph biconnected
  95. <i>before</i> passing it into <tt>boyer_myrvold_planarity_test</tt> so that the
  96. computed planar embedding includes these additional edges. This may require
  97. more than one call to <tt>boyer_myrvold_planarity_test</tt> depending on the
  98. structure of the graph you begin with, since both
  99. <tt>make_biconnected_planar</tt> and <tt>make_maximal_planar</tt> require a
  100. planar embedding of the existing graph as an input parameter.
  101. <p><p>
  102. The named parameters accepted by <tt>boyer_myrvold_planarity_test</tt> are:
  103. <ul>
  104. <li><b><tt>graph</tt></b> : The input graph - this is the only required
  105. parameter.
  106. <li><b><tt>vertex_index_map</tt></b> : A mapping from vertices of the input
  107. graph to indexes in the range <tt>[0..num_vertices(g))</tt>. If this parameter
  108. is not provided, the vertex index map is assumed to be available as an interior
  109. property of the graph, accessible by calling <tt>get(vertex_index, g)</tt>.
  110. <li><b><tt>edge_index_map</tt></b>: A mapping from the edges of the input graph
  111. to indexes in the range <tt>[0..num_edges(g))</tt>. This parameter is only
  112. needed if the <tt>kuratowski_subgraph</tt> argument is provided. If the
  113. <tt>kuratowski_subgraph</tt> argument is provided and this parameter is not
  114. provided, the EdgeIndexMap is assumed to be available as an interior property
  115. accessible by calling <tt>get(edge_index, g)</tt>.
  116. <li><b><tt>embedding</tt></b> : If the graph is planar, this will be populated
  117. with a mapping from vertices to the clockwise order of neighbors in the planar
  118. embedding.
  119. <li><b><tt>kuratowski_subgraph</tt></b> : If the graph is not planar, a minimal
  120. set of edges that form the obstructing Kuratowski subgraph will be written to
  121. this iterator.
  122. </ul>
  123. These named parameters all belong to the namespace
  124. <tt>boyer_myrvold_params</tt>. See below for more information on the concepts
  125. required for these arguments.
  126. <H3>Verifying the output</H3>
  127. Whether or not the input graph is planar, <tt>boyer_myrvold_planarity_test</tt>
  128. can produce a certificate that can be automatically checked to verify that the
  129. function is working properly.
  130. <p>
  131. If the graph is planar, a planar embedding can be produced. The
  132. planar embedding can be verified by passing it to a plane drawing routine
  133. (such as <tt><a href="straight_line_drawing.html">
  134. chrobak_payne_straight_line_drawing</a></tt>) and using the function
  135. <tt><a href="is_straight_line_drawing.html">is_straight_line_drawing</a></tt>
  136. to verify that the resulting graph is planar.
  137. <p>
  138. If the graph is not planar, a set of edges that forms a Kuratowski subgraph in
  139. the original graph can be produced. This set of edges can be passed to the
  140. function <tt><a href="is_kuratowski_subgraph.html">is_kuratowski_subgraph</a>
  141. </tt> to verify that they can be contracted into a <i>K<sub>5</sub></i> or
  142. <i>K<sub>3,3</sub></i>. <tt>boyer_myrvold_planarity_test</tt> chooses the set
  143. of edges forming the Kuratowski subgraph in such a way that the contraction to
  144. a <i>K<sub>5</sub></i> or <i>K<sub>3,3</sub></i> can be done by a simple
  145. deterministic process which is described in the documentation to
  146. <tt>is_kuratowski_subgraph</tt>.
  147. <H3>Where Defined</H3>
  148. <P>
  149. <a href="../../../boost/graph/boyer_myrvold_planar_test.hpp">
  150. <TT>boost/graph/boyer_myrvold_planar_test.hpp</TT>
  151. </a>
  152. <H3>Parameters</H3>
  153. IN: <tt>Graph&amp; g</tt>
  154. <blockquote>
  155. Any undirected graph. The graph type must be a model of
  156. <a href="VertexAndEdgeListGraph.html">VertexAndEdgeListGraph</a> and
  157. <a href="IncidenceGraph.html">IncidenceGraph</a>.
  158. </blockquote>
  159. OUT <tt>PlanarEmbedding embedding</tt>
  160. <blockquote>
  161. Must model the <a href="PlanarEmbedding.html">PlanarEmbedding</a> concept.
  162. </blockquote>
  163. IN <tt>OutputIterator kuratowski_subgraph</tt>
  164. <blockquote>
  165. An OutputIterator which accepts values of the type
  166. <tt>graph_traits&lt;Graph&gt;::edge_descriptor</tt>
  167. </blockquote>
  168. IN <tt>VertexIndexMap vm</tt>
  169. <blockquote>
  170. A <a href="../../property_map/doc/ReadablePropertyMap.html">Readable Property Map
  171. </a> that maps vertices from <tt>g</tt> to distinct integers in the range
  172. <tt>[0, num_vertices(g) )</tt><br>
  173. <b>Default</b>: <tt>get(vertex_index,g)</tt><br>
  174. </blockquote>
  175. IN <tt>EdgeIndexMap em</tt>
  176. <blockquote>
  177. A <a href="../../property_map/doc/ReadablePropertyMap.html">Readable Property Map
  178. </a> that maps edges from <tt>g</tt> to distinct integers in the range
  179. <tt>[0, num_edges(g) )</tt><br>
  180. <b>Default</b>: <tt>get(edge_index,g)</tt>, but this parameter is only used if
  181. the <tt>kuratowski_subgraph_iterator</tt> is provided.<br>
  182. </blockquote>
  183. <H3>Complexity</H3>
  184. Assuming that both the vertex index and edge index supplied take time
  185. <i>O(1)</i> to return an index and there are <i>O(n)</i>
  186. total self-loops and parallel edges in the graph, most combinations of
  187. arguments given to
  188. <tt>boyer_myrvold_planarity_test</tt> result in an algorithm that runs in time
  189. <i>O(n)</i> for a graph with <i>n</i> vertices and <i>m</i> edges. The only
  190. exception is when Kuratowski subgraph isolation is requested for a dense graph
  191. (a graph with <i>n = o(m)</i>) - the running time will be <i>O(n+m)</i>
  192. <a href = "#2">[2]</a>.
  193. <H3>Examples</H3>
  194. <P>
  195. <ul>
  196. <li><a href="../example/simple_planarity_test.cpp">A simple planarity test</a>
  197. <li><a href="../example/kuratowski_subgraph.cpp">Isolating a Kuratowski
  198. Subgraph</a>
  199. <li><a href="../example/straight_line_drawing.cpp">Using a planar embedding to
  200. create a straight line drawing</a>
  201. </ul>
  202. <h3>See Also</h3>
  203. <a href="./planar_graphs.html">Planar Graphs in the Boost Graph Library</a>
  204. <h3>Notes</h3>
  205. <p><a name="1">[1] A planar embedding is also called a <i>combinatorial
  206. embedding</i>.
  207. <p><a name="2">[2] The algorithm can still be made to run in time <i>O(n)</i>
  208. for this case, if needed. <a href="planar_graphs.html#EulersFormula">Euler's
  209. formula</a> implies that a planar graph with <i>n</i> vertices can have no more
  210. than <i>3n - 6</i> edges, which means that any non-planar graph on <i>n</i>
  211. vertices has a subgraph of only <i>3n - 5</i> edges that contains a Kuratowski
  212. subgraph. So, if you need to find a Kuratowski subgraph of a graph with more
  213. than <i>3n - 5</i> edges in time <i>O(n)</i>, you can create a subgraph of the
  214. original graph consisting of any arbitrary <i>3n - 5</i> edges and pass that
  215. graph to <tt>boyer_myrvold_planarity_test</tt>.
  216. <br>
  217. <HR>
  218. Copyright &copy; 2007 Aaron Windsor (<a href="mailto:aaron.windsor@gmail.com">
  219. aaron.windsor@gmail.com</a>)
  220. </BODY>
  221. </HTML>