os/ossrv/ossrv_pub/boost_apis/boost/graph/isomorphism.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (C) 2001 Jeremy Siek, Douglas Gregor, Brian Osman
sl@0
     2
//
sl@0
     3
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     4
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     5
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     6
#ifndef BOOST_GRAPH_ISOMORPHISM_HPP
sl@0
     7
#define BOOST_GRAPH_ISOMORPHISM_HPP
sl@0
     8
sl@0
     9
#include <utility>
sl@0
    10
#include <vector>
sl@0
    11
#include <iterator>
sl@0
    12
#include <algorithm>
sl@0
    13
#include <boost/config.hpp>
sl@0
    14
#include <boost/graph/depth_first_search.hpp>
sl@0
    15
#include <boost/utility.hpp>
sl@0
    16
#include <boost/detail/algorithm.hpp>
sl@0
    17
#include <boost/pending/indirect_cmp.hpp> // for make_indirect_pmap
sl@0
    18
sl@0
    19
#ifndef BOOST_GRAPH_ITERATION_MACROS_HPP
sl@0
    20
#define BOOST_ISO_INCLUDED_ITER_MACROS // local macro, see bottom of file
sl@0
    21
#include <boost/graph/iteration_macros.hpp>
sl@0
    22
#endif
sl@0
    23
sl@0
    24
namespace boost {
sl@0
    25
sl@0
    26
  namespace detail {
sl@0
    27
sl@0
    28
    template <typename Graph1, typename Graph2, typename IsoMapping,
sl@0
    29
      typename Invariant1, typename Invariant2,
sl@0
    30
      typename IndexMap1, typename IndexMap2>
sl@0
    31
    class isomorphism_algo
sl@0
    32
    {
sl@0
    33
      typedef typename graph_traits<Graph1>::vertex_descriptor vertex1_t;
sl@0
    34
      typedef typename graph_traits<Graph2>::vertex_descriptor vertex2_t;
sl@0
    35
      typedef typename graph_traits<Graph1>::edge_descriptor edge1_t;
sl@0
    36
      typedef typename graph_traits<Graph1>::vertices_size_type size_type;
sl@0
    37
      typedef typename Invariant1::result_type invar1_value;
sl@0
    38
      typedef typename Invariant2::result_type invar2_value;
sl@0
    39
    
sl@0
    40
      const Graph1& G1;
sl@0
    41
      const Graph2& G2;
sl@0
    42
      IsoMapping f;
sl@0
    43
      Invariant1 invariant1;
sl@0
    44
      Invariant2 invariant2;
sl@0
    45
      std::size_t max_invariant;
sl@0
    46
      IndexMap1 index_map1;
sl@0
    47
      IndexMap2 index_map2;
sl@0
    48
    
sl@0
    49
      std::vector<vertex1_t> dfs_vertices;
sl@0
    50
      typedef typename std::vector<vertex1_t>::iterator vertex_iter;
sl@0
    51
      std::vector<int> dfs_num_vec;
sl@0
    52
      typedef safe_iterator_property_map<typename std::vector<int>::iterator,
sl@0
    53
                                         IndexMap1
sl@0
    54
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
sl@0
    55
                                         , int, int&
sl@0
    56
#endif /* BOOST_NO_STD_ITERATOR_TRAITS */
sl@0
    57
                                         > DFSNumMap;
sl@0
    58
      DFSNumMap dfs_num;
sl@0
    59
      std::vector<edge1_t> ordered_edges;
sl@0
    60
      typedef typename std::vector<edge1_t>::iterator edge_iter;
sl@0
    61
    
sl@0
    62
      std::vector<char> in_S_vec;
sl@0
    63
      typedef safe_iterator_property_map<typename std::vector<char>::iterator,
sl@0
    64
                                         IndexMap2
sl@0
    65
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
sl@0
    66
                                         , char, char&
sl@0
    67
#endif /* BOOST_NO_STD_ITERATOR_TRAITS */
sl@0
    68
                                         > InSMap;
sl@0
    69
      InSMap in_S;
sl@0
    70
    
sl@0
    71
      int num_edges_on_k;
sl@0
    72
    
sl@0
    73
      friend struct compare_multiplicity;
sl@0
    74
      struct compare_multiplicity
sl@0
    75
      {
sl@0
    76
        compare_multiplicity(Invariant1 invariant1, size_type* multiplicity)
sl@0
    77
          : invariant1(invariant1), multiplicity(multiplicity) { }
sl@0
    78
        bool operator()(const vertex1_t& x, const vertex1_t& y) const {
sl@0
    79
          return multiplicity[invariant1(x)] < multiplicity[invariant1(y)];
sl@0
    80
        }
sl@0
    81
        Invariant1 invariant1;
sl@0
    82
        size_type* multiplicity;
sl@0
    83
      };
sl@0
    84
    
sl@0
    85
      struct record_dfs_order : default_dfs_visitor
sl@0
    86
      {
sl@0
    87
        record_dfs_order(std::vector<vertex1_t>& v, std::vector<edge1_t>& e) 
sl@0
    88
          : vertices(v), edges(e) { }
sl@0
    89
    
sl@0
    90
        void discover_vertex(vertex1_t v, const Graph1&) const {
sl@0
    91
          vertices.push_back(v);
sl@0
    92
        }
sl@0
    93
        void examine_edge(edge1_t e, const Graph1& G1) const {
sl@0
    94
          edges.push_back(e);
sl@0
    95
        }
sl@0
    96
        std::vector<vertex1_t>& vertices;
sl@0
    97
        std::vector<edge1_t>& edges;
sl@0
    98
      };
sl@0
    99
    
sl@0
   100
      struct edge_cmp {
sl@0
   101
        edge_cmp(const Graph1& G1, DFSNumMap dfs_num)
sl@0
   102
          : G1(G1), dfs_num(dfs_num) { }
sl@0
   103
        bool operator()(const edge1_t& e1, const edge1_t& e2) const {
sl@0
   104
          using namespace std;
sl@0
   105
          int u1 = dfs_num[source(e1,G1)], v1 = dfs_num[target(e1,G1)];
sl@0
   106
          int u2 = dfs_num[source(e2,G1)], v2 = dfs_num[target(e2,G1)];
sl@0
   107
          int m1 = (max)(u1, v1);
sl@0
   108
          int m2 = (max)(u2, v2);
sl@0
   109
          // lexicographical comparison 
sl@0
   110
          return std::make_pair(m1, std::make_pair(u1, v1))
sl@0
   111
            < std::make_pair(m2, std::make_pair(u2, v2));
sl@0
   112
        }
sl@0
   113
        const Graph1& G1;
sl@0
   114
        DFSNumMap dfs_num;
sl@0
   115
      };
sl@0
   116
    
sl@0
   117
    public:
sl@0
   118
      isomorphism_algo(const Graph1& G1, const Graph2& G2, IsoMapping f,
sl@0
   119
                       Invariant1 invariant1, Invariant2 invariant2, std::size_t max_invariant,
sl@0
   120
                       IndexMap1 index_map1, IndexMap2 index_map2)
sl@0
   121
        : G1(G1), G2(G2), f(f), invariant1(invariant1), invariant2(invariant2),
sl@0
   122
          max_invariant(max_invariant),
sl@0
   123
          index_map1(index_map1), index_map2(index_map2)
sl@0
   124
      {
sl@0
   125
        in_S_vec.resize(num_vertices(G1));
sl@0
   126
        in_S = make_safe_iterator_property_map
sl@0
   127
          (in_S_vec.begin(), in_S_vec.size(), index_map2
sl@0
   128
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
sl@0
   129
           , in_S_vec.front()
sl@0
   130
#endif /* BOOST_NO_STD_ITERATOR_TRAITS */
sl@0
   131
           );
sl@0
   132
      }
sl@0
   133
    
sl@0
   134
      bool test_isomorphism()
sl@0
   135
      {
sl@0
   136
        {
sl@0
   137
          std::vector<invar1_value> invar1_array;
sl@0
   138
          BGL_FORALL_VERTICES_T(v, G1, Graph1)
sl@0
   139
            invar1_array.push_back(invariant1(v));
sl@0
   140
          sort(invar1_array);
sl@0
   141
        
sl@0
   142
          std::vector<invar2_value> invar2_array;
sl@0
   143
          BGL_FORALL_VERTICES_T(v, G2, Graph2)
sl@0
   144
            invar2_array.push_back(invariant2(v));
sl@0
   145
          sort(invar2_array);
sl@0
   146
          if (! equal(invar1_array, invar2_array))
sl@0
   147
            return false;
sl@0
   148
        }
sl@0
   149
        
sl@0
   150
        std::vector<vertex1_t> V_mult;
sl@0
   151
        BGL_FORALL_VERTICES_T(v, G1, Graph1)
sl@0
   152
          V_mult.push_back(v);
sl@0
   153
        {
sl@0
   154
          std::vector<size_type> multiplicity(max_invariant, 0);
sl@0
   155
          BGL_FORALL_VERTICES_T(v, G1, Graph1)
sl@0
   156
            ++multiplicity[invariant1(v)];
sl@0
   157
          sort(V_mult, compare_multiplicity(invariant1, &multiplicity[0]));
sl@0
   158
        }
sl@0
   159
        
sl@0
   160
        std::vector<default_color_type> color_vec(num_vertices(G1));
sl@0
   161
        safe_iterator_property_map<std::vector<default_color_type>::iterator,
sl@0
   162
                                   IndexMap1
sl@0
   163
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
sl@0
   164
                                   , default_color_type, default_color_type&
sl@0
   165
#endif /* BOOST_NO_STD_ITERATOR_TRAITS */
sl@0
   166
                                   >
sl@0
   167
          color_map(color_vec.begin(), color_vec.size(), index_map1);
sl@0
   168
        record_dfs_order dfs_visitor(dfs_vertices, ordered_edges);
sl@0
   169
        typedef color_traits<default_color_type> Color;
sl@0
   170
        for (vertex_iter u = V_mult.begin(); u != V_mult.end(); ++u) {
sl@0
   171
          if (color_map[*u] == Color::white()) {
sl@0
   172
            dfs_visitor.start_vertex(*u, G1);
sl@0
   173
            depth_first_visit(G1, *u, dfs_visitor, color_map);
sl@0
   174
          }
sl@0
   175
        }
sl@0
   176
        // Create the dfs_num array and dfs_num_map
sl@0
   177
        dfs_num_vec.resize(num_vertices(G1));
sl@0
   178
        dfs_num = make_safe_iterator_property_map(dfs_num_vec.begin(),
sl@0
   179
                                                  dfs_num_vec.size(), 
sl@0
   180
                                                  index_map1
sl@0
   181
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
sl@0
   182
                                                  , dfs_num_vec.front()
sl@0
   183
#endif /* BOOST_NO_STD_ITERATOR_TRAITS */
sl@0
   184
                                                  );
sl@0
   185
        size_type n = 0;
sl@0
   186
        for (vertex_iter v = dfs_vertices.begin(); v != dfs_vertices.end(); ++v)
sl@0
   187
          dfs_num[*v] = n++;
sl@0
   188
        
sl@0
   189
        sort(ordered_edges, edge_cmp(G1, dfs_num));
sl@0
   190
        
sl@0
   191
    
sl@0
   192
        int dfs_num_k = -1;
sl@0
   193
        return this->match(ordered_edges.begin(), dfs_num_k);
sl@0
   194
      }
sl@0
   195
    
sl@0
   196
    private:
sl@0
   197
      bool match(edge_iter iter, int dfs_num_k)
sl@0
   198
      {
sl@0
   199
        if (iter != ordered_edges.end()) {
sl@0
   200
          vertex1_t i = source(*iter, G1), j = target(*iter, G2);
sl@0
   201
          if (dfs_num[i] > dfs_num_k) {
sl@0
   202
            vertex1_t kp1 = dfs_vertices[dfs_num_k + 1];
sl@0
   203
            BGL_FORALL_VERTICES_T(u, G2, Graph2) {
sl@0
   204
              if (invariant1(kp1) == invariant2(u) && in_S[u] == false) {
sl@0
   205
                f[kp1] = u;
sl@0
   206
                in_S[u] = true;
sl@0
   207
                num_edges_on_k = 0;
sl@0
   208
                
sl@0
   209
                if (match(iter, dfs_num_k + 1))
sl@0
   210
#if 0
sl@0
   211
                    // dwa 2003/7/11 -- this *HAS* to be a bug!
sl@0
   212
                    ;
sl@0
   213
#endif 
sl@0
   214
                    return true;
sl@0
   215
                    
sl@0
   216
                in_S[u] = false;
sl@0
   217
              }
sl@0
   218
            }
sl@0
   219
               
sl@0
   220
          }
sl@0
   221
          else if (dfs_num[j] > dfs_num_k) {
sl@0
   222
            vertex1_t k = dfs_vertices[dfs_num_k];
sl@0
   223
            num_edges_on_k -= 
sl@0
   224
              count_if(adjacent_vertices(f[k], G2), make_indirect_pmap(in_S));
sl@0
   225
                
sl@0
   226
            for (int jj = 0; jj < dfs_num_k; ++jj) {
sl@0
   227
              vertex1_t j = dfs_vertices[jj];
sl@0
   228
              num_edges_on_k -= count(adjacent_vertices(f[j], G2), f[k]);
sl@0
   229
            }
sl@0
   230
                
sl@0
   231
            if (num_edges_on_k != 0)
sl@0
   232
              return false;
sl@0
   233
            BGL_FORALL_ADJ_T(f[i], v, G2, Graph2)
sl@0
   234
              if (invariant2(v) == invariant1(j) && in_S[v] == false) {
sl@0
   235
                f[j] = v;
sl@0
   236
                in_S[v] = true;
sl@0
   237
                num_edges_on_k = 1;
sl@0
   238
                BOOST_USING_STD_MAX();
sl@0
   239
                int next_k = max BOOST_PREVENT_MACRO_SUBSTITUTION(dfs_num_k, max BOOST_PREVENT_MACRO_SUBSTITUTION(dfs_num[i], dfs_num[j]));
sl@0
   240
                if (match(next(iter), next_k))
sl@0
   241
                  return true;
sl@0
   242
                in_S[v] = false;
sl@0
   243
              }
sl@0
   244
                
sl@0
   245
                
sl@0
   246
          }
sl@0
   247
          else {
sl@0
   248
            if (contains(adjacent_vertices(f[i], G2), f[j])) {
sl@0
   249
              ++num_edges_on_k;
sl@0
   250
              if (match(next(iter), dfs_num_k))
sl@0
   251
                return true;
sl@0
   252
            }
sl@0
   253
                
sl@0
   254
          }
sl@0
   255
        } else 
sl@0
   256
          return true;
sl@0
   257
        return false;
sl@0
   258
      }
sl@0
   259
    
sl@0
   260
    };
sl@0
   261
sl@0
   262
    
sl@0
   263
    template <typename Graph, typename InDegreeMap>
sl@0
   264
    void compute_in_degree(const Graph& g, InDegreeMap in_degree_map)
sl@0
   265
    {
sl@0
   266
      BGL_FORALL_VERTICES_T(v, g, Graph)
sl@0
   267
        put(in_degree_map, v, 0);
sl@0
   268
sl@0
   269
      BGL_FORALL_VERTICES_T(u, g, Graph)
sl@0
   270
        BGL_FORALL_ADJ_T(u, v, g, Graph)
sl@0
   271
        put(in_degree_map, v, get(in_degree_map, v) + 1);
sl@0
   272
    }
sl@0
   273
sl@0
   274
  } // namespace detail
sl@0
   275
sl@0
   276
sl@0
   277
  template <typename InDegreeMap, typename Graph>
sl@0
   278
  class degree_vertex_invariant
sl@0
   279
  {
sl@0
   280
    typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
sl@0
   281
    typedef typename graph_traits<Graph>::degree_size_type size_type;
sl@0
   282
  public:
sl@0
   283
    typedef vertex_t argument_type;
sl@0
   284
    typedef size_type result_type;
sl@0
   285
sl@0
   286
    degree_vertex_invariant(const InDegreeMap& in_degree_map, const Graph& g)
sl@0
   287
      : m_in_degree_map(in_degree_map), m_g(g) { }
sl@0
   288
sl@0
   289
    size_type operator()(vertex_t v) const {
sl@0
   290
      return (num_vertices(m_g) + 1) * out_degree(v, m_g)
sl@0
   291
        + get(m_in_degree_map, v);
sl@0
   292
    }
sl@0
   293
    // The largest possible vertex invariant number
sl@0
   294
    size_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { 
sl@0
   295
      return num_vertices(m_g) * num_vertices(m_g) + num_vertices(m_g);
sl@0
   296
    }
sl@0
   297
  private:
sl@0
   298
    InDegreeMap m_in_degree_map;
sl@0
   299
    const Graph& m_g;
sl@0
   300
  };
sl@0
   301
sl@0
   302
sl@0
   303
  template <typename Graph1, typename Graph2, typename IsoMapping, 
sl@0
   304
    typename Invariant1, typename Invariant2,
sl@0
   305
    typename IndexMap1, typename IndexMap2>
sl@0
   306
  bool isomorphism(const Graph1& G1, const Graph2& G2, IsoMapping f, 
sl@0
   307
                   Invariant1 invariant1, Invariant2 invariant2, 
sl@0
   308
                   std::size_t max_invariant,
sl@0
   309
                   IndexMap1 index_map1, IndexMap2 index_map2)
sl@0
   310
sl@0
   311
  {
sl@0
   312
    // Graph requirements
sl@0
   313
    function_requires< VertexListGraphConcept<Graph1> >();
sl@0
   314
    function_requires< EdgeListGraphConcept<Graph1> >();
sl@0
   315
    function_requires< VertexListGraphConcept<Graph2> >();
sl@0
   316
    function_requires< BidirectionalGraphConcept<Graph2> >();
sl@0
   317
    
sl@0
   318
    typedef typename graph_traits<Graph1>::vertex_descriptor vertex1_t;
sl@0
   319
    typedef typename graph_traits<Graph2>::vertex_descriptor vertex2_t;
sl@0
   320
    typedef typename graph_traits<Graph1>::vertices_size_type size_type;
sl@0
   321
    
sl@0
   322
    // Vertex invariant requirement
sl@0
   323
    function_requires< AdaptableUnaryFunctionConcept<Invariant1,
sl@0
   324
      size_type, vertex1_t> >();
sl@0
   325
    function_requires< AdaptableUnaryFunctionConcept<Invariant2,
sl@0
   326
      size_type, vertex2_t> >();
sl@0
   327
    
sl@0
   328
    // Property map requirements
sl@0
   329
    function_requires< ReadWritePropertyMapConcept<IsoMapping, vertex1_t> >();
sl@0
   330
    typedef typename property_traits<IsoMapping>::value_type IsoMappingValue;
sl@0
   331
    BOOST_STATIC_ASSERT((is_same<IsoMappingValue, vertex2_t>::value));
sl@0
   332
    
sl@0
   333
    function_requires< ReadablePropertyMapConcept<IndexMap1, vertex1_t> >();
sl@0
   334
    typedef typename property_traits<IndexMap1>::value_type IndexMap1Value;
sl@0
   335
    BOOST_STATIC_ASSERT((is_convertible<IndexMap1Value, size_type>::value));
sl@0
   336
    
sl@0
   337
    function_requires< ReadablePropertyMapConcept<IndexMap2, vertex2_t> >();
sl@0
   338
    typedef typename property_traits<IndexMap2>::value_type IndexMap2Value;
sl@0
   339
    BOOST_STATIC_ASSERT((is_convertible<IndexMap2Value, size_type>::value));
sl@0
   340
    
sl@0
   341
    if (num_vertices(G1) != num_vertices(G2))
sl@0
   342
      return false;
sl@0
   343
    if (num_vertices(G1) == 0 && num_vertices(G2) == 0)
sl@0
   344
      return true;
sl@0
   345
    
sl@0
   346
    detail::isomorphism_algo<Graph1, Graph2, IsoMapping, Invariant1,
sl@0
   347
      Invariant2, IndexMap1, IndexMap2> 
sl@0
   348
      algo(G1, G2, f, invariant1, invariant2, max_invariant, 
sl@0
   349
           index_map1, index_map2);
sl@0
   350
    return algo.test_isomorphism();
sl@0
   351
  }
sl@0
   352
sl@0
   353
sl@0
   354
  namespace detail {
sl@0
   355
  
sl@0
   356
    template <typename Graph1, typename Graph2, 
sl@0
   357
      typename IsoMapping, 
sl@0
   358
      typename IndexMap1, typename IndexMap2,
sl@0
   359
      typename P, typename T, typename R>
sl@0
   360
    bool isomorphism_impl(const Graph1& G1, const Graph2& G2, 
sl@0
   361
                          IsoMapping f, IndexMap1 index_map1, IndexMap2 index_map2,
sl@0
   362
                          const bgl_named_params<P,T,R>& params)
sl@0
   363
    {
sl@0
   364
      std::vector<std::size_t> in_degree1_vec(num_vertices(G1));
sl@0
   365
      typedef safe_iterator_property_map<std::vector<std::size_t>::iterator,
sl@0
   366
                                         IndexMap1
sl@0
   367
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
sl@0
   368
                                         , std::size_t, std::size_t&
sl@0
   369
#endif /* BOOST_NO_STD_ITERATOR_TRAITS */
sl@0
   370
                                         > InDeg1;
sl@0
   371
      InDeg1 in_degree1(in_degree1_vec.begin(), in_degree1_vec.size(), index_map1);
sl@0
   372
      compute_in_degree(G1, in_degree1);
sl@0
   373
sl@0
   374
      std::vector<std::size_t> in_degree2_vec(num_vertices(G2));
sl@0
   375
      typedef safe_iterator_property_map<std::vector<std::size_t>::iterator, 
sl@0
   376
                                         IndexMap2
sl@0
   377
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
sl@0
   378
                                         , std::size_t, std::size_t&
sl@0
   379
#endif /* BOOST_NO_STD_ITERATOR_TRAITS */
sl@0
   380
                                         > InDeg2;
sl@0
   381
      InDeg2 in_degree2(in_degree2_vec.begin(), in_degree2_vec.size(), index_map2);
sl@0
   382
      compute_in_degree(G2, in_degree2);
sl@0
   383
sl@0
   384
      degree_vertex_invariant<InDeg1, Graph1> invariant1(in_degree1, G1);
sl@0
   385
      degree_vertex_invariant<InDeg2, Graph2> invariant2(in_degree2, G2);
sl@0
   386
sl@0
   387
      return isomorphism(G1, G2, f,
sl@0
   388
                         choose_param(get_param(params, vertex_invariant1_t()), invariant1),
sl@0
   389
                         choose_param(get_param(params, vertex_invariant2_t()), invariant2),
sl@0
   390
                         choose_param(get_param(params, vertex_max_invariant_t()), (invariant2.max)()),
sl@0
   391
                         index_map1, index_map2
sl@0
   392
                         );  
sl@0
   393
    }  
sl@0
   394
   
sl@0
   395
  } // namespace detail
sl@0
   396
sl@0
   397
sl@0
   398
  // Named parameter interface
sl@0
   399
  template <typename Graph1, typename Graph2, class P, class T, class R>
sl@0
   400
  bool isomorphism(const Graph1& g1,
sl@0
   401
                   const Graph2& g2,
sl@0
   402
                   const bgl_named_params<P,T,R>& params)
sl@0
   403
  {
sl@0
   404
    typedef typename graph_traits<Graph2>::vertex_descriptor vertex2_t;
sl@0
   405
    typename std::vector<vertex2_t>::size_type n = num_vertices(g1);
sl@0
   406
    std::vector<vertex2_t> f(n);
sl@0
   407
    return detail::isomorphism_impl
sl@0
   408
      (g1, g2, 
sl@0
   409
       choose_param(get_param(params, vertex_isomorphism_t()),
sl@0
   410
                    make_safe_iterator_property_map(f.begin(), f.size(),
sl@0
   411
                                                    choose_const_pmap(get_param(params, vertex_index1),
sl@0
   412
                                                                      g1, vertex_index), vertex2_t())),
sl@0
   413
       choose_const_pmap(get_param(params, vertex_index1), g1, vertex_index),
sl@0
   414
       choose_const_pmap(get_param(params, vertex_index2), g2, vertex_index),
sl@0
   415
       params
sl@0
   416
       );
sl@0
   417
  }
sl@0
   418
sl@0
   419
  // All defaults interface
sl@0
   420
  template <typename Graph1, typename Graph2>
sl@0
   421
  bool isomorphism(const Graph1& g1, const Graph2& g2)
sl@0
   422
  {
sl@0
   423
    return isomorphism(g1, g2,
sl@0
   424
                       bgl_named_params<int, buffer_param_t>(0));// bogus named param
sl@0
   425
  }
sl@0
   426
sl@0
   427
sl@0
   428
  // Verify that the given mapping iso_map from the vertices of g1 to the
sl@0
   429
  // vertices of g2 describes an isomorphism.
sl@0
   430
  // Note: this could be made much faster by specializing based on the graph
sl@0
   431
  // concepts modeled, but since we're verifying an O(n^(lg n)) algorithm,
sl@0
   432
  // O(n^4) won't hurt us.
sl@0
   433
  template<typename Graph1, typename Graph2, typename IsoMap>
sl@0
   434
  inline bool verify_isomorphism(const Graph1& g1, const Graph2& g2, IsoMap iso_map)
sl@0
   435
  {
sl@0
   436
#if 0
sl@0
   437
    // problematic for filtered_graph!
sl@0
   438
    if (num_vertices(g1) != num_vertices(g2) || num_edges(g1) != num_edges(g2))
sl@0
   439
      return false;
sl@0
   440
#endif
sl@0
   441
  
sl@0
   442
    for (typename graph_traits<Graph1>::edge_iterator e1 = edges(g1).first;
sl@0
   443
         e1 != edges(g1).second; ++e1) {
sl@0
   444
      bool found_edge = false;
sl@0
   445
      for (typename graph_traits<Graph2>::edge_iterator e2 = edges(g2).first;
sl@0
   446
           e2 != edges(g2).second && !found_edge; ++e2) {
sl@0
   447
        if (source(*e2, g2) == get(iso_map, source(*e1, g1)) &&
sl@0
   448
            target(*e2, g2) == get(iso_map, target(*e1, g1))) {
sl@0
   449
          found_edge = true;
sl@0
   450
        }
sl@0
   451
      }
sl@0
   452
    
sl@0
   453
      if (!found_edge)
sl@0
   454
        return false;
sl@0
   455
    }
sl@0
   456
  
sl@0
   457
    return true;
sl@0
   458
  }
sl@0
   459
sl@0
   460
} // namespace boost
sl@0
   461
sl@0
   462
#ifdef BOOST_ISO_INCLUDED_ITER_MACROS
sl@0
   463
#undef BOOST_ISO_INCLUDED_ITER_MACROS
sl@0
   464
#include <boost/graph/iteration_macros_undef.hpp>
sl@0
   465
#endif
sl@0
   466
sl@0
   467
#endif // BOOST_GRAPH_ISOMORPHISM_HPP