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