isomorphism.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <HTML>
  2. <!--
  3. Copyright (c) Jeremy Siek 2000
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <Head>
  9. <Title>Boost Graph Library: Isomorphism</Title>
  10. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  11. ALINK="#ff0000">
  12. <IMG SRC="../../../boost.png"
  13. ALT="C++ Boost" width="277" height="86">
  14. <BR Clear>
  15. <H1>
  16. <img src="figs/python.gif" alt="(Python)"/>
  17. <TT>isomorphism</TT>
  18. </H1>
  19. <PRE>
  20. <i>// named parameter version</i>
  21. template &lt;class Graph1, class Graph2, class P, class T, class R&gt;
  22. bool isomorphism(const Graph1&amp; g1, const Graph2&amp; g2,
  23. const bgl_named_params&lt;P,T,R&gt;&amp; params = <i>all defaults</i>)
  24. <i>// non-named parameter version</i>
  25. template &lt;typename Graph1, typename Graph2, typename IsoMap,
  26. typename VertexInvariant1, typename VertexInvariant2,
  27. typename V1Map, typename V2Map&gt;
  28. bool isomorphism(const Graph1&amp; g1, const Graph2&amp; g2,
  29. IsoMap f, VertexInvariant1 invariant2, VertexInvariant2 invariant2,
  30. std::size_t max_invariant, VertexIndex1Map i1_map, VertexIndex2Map i2_map)
  31. </pre>
  32. <p>
  33. An <b><i>isomorphism</i></b> is a 1-to-1 mapping of the vertices in
  34. one graph to the vertices of another graph such that adjacency is
  35. preserved. Another words, given graphs <i>G<sub>1</sub> =
  36. (V<sub>1</sub>,E<sub>1</sub>)</i> and <i>G<sub>2</sub> =
  37. (V<sub>2</sub>,E<sub>2</sub>)</i> an isomorphism is a function
  38. <i>f</i> such that for all pairs of vertices <i>a,b</i> in
  39. <i>V<sub>1</sub></i>, edge <i>(a,b)</i> is in <i>E<sub>1</sub></i> if
  40. and only if edge <i>(f(a),f(b))</i> is in <i>E<sub>2</sub></i>.
  41. </p>
  42. <p>
  43. This function returns <tt>true</tt> if there exists an isomorphism
  44. between graph 1 and graph 2 and <tt>false</tt> otherwise. Also, if a
  45. isomorphism map named parameter is provided then an isomorphism is
  46. recorded in the map.
  47. </p>
  48. <p>
  49. The current implementation is based on descriptions of a backtracking
  50. algorithm in [<a
  51. href="./bibliography.html#fortin96:_graph_iso_prob">46</a>,<a
  52. href="./bibliography.html#reingold77:_combin_algo">48</a>]. The file
  53. <a href="./isomorphism-impl.pdf">isomorphism-impl.pdf</a> contains a (somewhat out-of-date)
  54. &quot;literate&quot; description of the implementation. The algorithm
  55. used is simple but slow. A more efficient (and much more complex)
  56. algorithm is described in [<a
  57. href="./bibliography.html#mckay81:_pract_graph_iso">47</a>]. When (and
  58. if) a version of this algorithm is ported to the BGL interface it
  59. should replace the current algorithm.
  60. </p>
  61. <H3>Where Defined</H3>
  62. <a href="../../../boost/graph/isomorphism.hpp"><TT>boost/graph/isomorphism.hpp</TT></a>
  63. <h3>Parameters</h3>
  64. IN: <tt>const Graph1&amp; g1</tt>
  65. <blockquote>
  66. A directed or undirected graph. The graph type must model of <a
  67. href="./VertexListGraph.html">Vertex List Graph</a> and <a
  68. href="./EdgeListGraph.html">Edge List Graph</a>.
  69. </blockquote>
  70. IN: <tt>const Graph2&amp; g2</tt>
  71. <blockquote>
  72. A directed or undirected graph. The graph type must model <a
  73. href="./BidirectionalGraph.html">Bidirectional Graph</a> and <a
  74. href="./VertexListGraph.html">Vertex List Graph</a>.
  75. </blockquote>
  76. <h3>Named Parameters</h3>
  77. OUT: <tt>isomorphism_map(IsoMap f)</tt>
  78. <blockquote>
  79. The mapping from vertices in graph 1 to vertices in graph 2. This must
  80. be a <a href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  81. Property Map</a>.<br> <b>Default:</b> an <a
  82. href="../../property_map/doc/iterator_property_map.html"><tt>iterator_property_map</tt></a>
  83. constructed from a <tt>std::vector</tt> of graph 2's vertex
  84. descriptor type and the vertex index map for graph 1.<br>
  85. <b>Python</b>: Must be a <tt>vertex_vertex_map</tt> for the first graph.
  86. </blockquote>
  87. IN: <tt>vertex_invariant1(VertexInvariant1 i1)</tt>
  88. IN: <tt>vertex_invariant2(VertexInvariant2 i2)</tt>
  89. <blockquote>
  90. Mappings from vertices to integers which restrict which vertices may be
  91. considered isomorphic. If a candidate isomorphism maps <i>v1</i> to <i>v2</i>
  92. but <i>i1</i>(<i>v1</i>) != <i>i2</i>(<i>v2</i>), that candidate is rejected.
  93. This mapping can be used either to speed up the search (as is done by the
  94. default value, which requires that the degrees of <i>v1</i> and <i>v2</i> are
  95. equal) or to impose extra conditions on the result. The
  96. <tt>VertexInvariant1</tt> and <tt>VertexInvariant2</tt> types must model <a
  97. href="http://www.boost.org/sgi/stl/UnaryFunction.html">UnaryFunction</a>, with
  98. the argument type of <tt>vertex_invariant1</tt> being <tt>Graph1</tt>'s vertex
  99. descriptor type, the argument type of <tt>vertex_invariant2</tt> being
  100. <tt>Graph2</tt>'s vertex descriptor type, and both functions having integral
  101. result types. The values returned by these two functions must be in the range
  102. [0, <tt>vertex_max_invariant</tt>).
  103. <br>
  104. <b>Default:</b> <tt>degree_vertex_invariant</tt> for both arguments<br>
  105. <b>Python</b>: Unsupported parameter.
  106. </blockquote>
  107. IN: <tt>vertex_max_invariant(std::size_t max_invariant)</tt>
  108. <blockquote>
  109. An upper bound on the possible values returned from either
  110. vertex_invariant1 or vertex_invariant2.
  111. <br>
  112. <b>Default:</b> <tt>vertex_invariant2.max()</tt>. The default
  113. <tt>vertex_invariant2</tt> parameter, an instance of
  114. <tt>degree_vertex_invariant</tt>, defines this function to
  115. return <tt>num_vertices(g2) * (num_vertices(g2)+1)</tt>.<br>
  116. <b>Python</b>: Unsupported parameter.
  117. </blockquote>
  118. IN: <tt>vertex_index1_map(VertexIndex1Map i1_map)</tt>
  119. <blockquote>
  120. This maps each vertex to an integer in the range <tt>[0,
  121. num_vertices(g))</tt>. This is necessary for efficient updates of the
  122. heap data structure when an edge is relaxed. The type
  123. <tt>VertexIndex1Map</tt> must be a model of <a
  124. href="../../property_map/doc/ReadablePropertyMap.html">Readable Property
  125. Map</a>. The value type of the map must be an integer type. The vertex
  126. descriptor type of graph 1 needs to be usable as the key type of the
  127. map.<br>
  128. <b>Default:</b> <tt>get(vertex_index, g1)</tt>
  129. Note: if you use this default, make sure your graph has
  130. an internal <tt>vertex_index</tt> property. For example,
  131. <tt>adjacency_list</tt> with <tt>VertexList=listS</tt> does
  132. not have an internal <tt>vertex_index</tt> property.
  133. <br>
  134. <b>Python</b>: Unsupported parameter.
  135. </blockquote>
  136. IN: <tt>vertex_index2_map(VertexIndex2Map i2_map)</tt>
  137. <blockquote>
  138. This maps each vertex to an integer in the range <tt>[0,
  139. num_vertices(g))</tt>. This is necessary for efficient updates of the
  140. heap data structure when an edge is relaxed. The type
  141. <tt>VertexIndex2Map</tt> must be a model of <a
  142. href="../../property_map/doc/ReadablePropertyMap.html">Readable Property
  143. Map</a>. The value type of the map must be an integer type. The vertex
  144. descriptor type of graph 2 needs to be usable as the key type of the
  145. map.<br>
  146. <b>Default:</b> <tt>get(vertex_index, g2)</tt>
  147. Note: if you use this default, make sure your graph has
  148. an internal <tt>vertex_index</tt> property. For example,
  149. <tt>adjacency_list</tt> with <tt>VertexList=listS</tt> does
  150. not have an internal <tt>vertex_index</tt> property.
  151. <br>
  152. <b>Python</b>: Unsupported parameter.
  153. </blockquote>
  154. <h3>Complexity</h3>
  155. The worst-case time complexity is <i>O(|V|!)</i>.
  156. <h3>Example</h3>
  157. See <a href="../example/isomorphism.cpp"><tt>libs/graph/example/isomorphism.cpp</tt></a>.
  158. <br>
  159. <HR>
  160. <TABLE>
  161. <TR valign=top>
  162. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  163. <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>, Indiana University (<A HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)
  164. </TD></TR></TABLE>
  165. </BODY>
  166. </HTML>