Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/graph/example/isomorphism.cpp @ 30

Last change on this file since 30 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.4 KB
Line 
1// (C) Copyright Jeremy Siek 2001.
2// Distributed under the Boost Software License, Version 1.0. (See
3// accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5
6#include <boost/config.hpp>
7#include <iostream>
8#include <boost/graph/isomorphism.hpp>
9#include <boost/graph/adjacency_list.hpp>
10
11#include <boost/graph/graph_utility.hpp>
12
13/*
14  Sample output:
15  isomorphic? 1
16  f: 9 10 11 0 1 3 2 4 6 8 7 5
17 */
18
19int
20main()
21{
22  using namespace boost;
23 
24  const int n = 12;
25
26  typedef adjacency_list<vecS, listS, undirectedS,
27    property<vertex_index_t, int> > graph_t;
28  graph_t g1(n), g2(n);
29
30  std::vector<graph_traits<graph_t>::vertex_descriptor> v1(n), v2(n);
31
32  property_map<graph_t, vertex_index_t>::type
33    v1_index_map = get(vertex_index, g1),
34    v2_index_map = get(vertex_index, g2);
35
36  graph_traits<graph_t>::vertex_iterator i, end;
37  int id = 0;
38  for (tie(i, end) = vertices(g1); i != end; ++i, ++id) {
39    put(v1_index_map, *i, id);
40    v1[id] = *i;
41  }
42  id = 0;
43  for (tie(i, end) = vertices(g2); i != end; ++i, ++id) {
44    put(v2_index_map, *i, id);
45    v2[id] = *i;
46  }
47  add_edge(v1[0], v1[1], g1); add_edge(v1[1], v1[2], g1); 
48  add_edge(v1[0], v1[2], g1);
49  add_edge(v1[3], v1[4], g1);  add_edge(v1[4], v1[5], g1);
50  add_edge(v1[5], v1[6], g1);  add_edge(v1[6], v1[3], g1);
51  add_edge(v1[7], v1[8], g1);  add_edge(v1[8], v1[9], g1);
52  add_edge(v1[9], v1[10], g1);
53  add_edge(v1[10], v1[11], g1);  add_edge(v1[11], v1[7], g1);
54
55  add_edge(v2[9], v2[10], g2);  add_edge(v2[10], v2[11], g2); 
56  add_edge(v2[11], v2[9], g2);
57  add_edge(v2[0], v2[1], g2);  add_edge(v2[1], v2[3], g2); 
58  add_edge(v2[3], v2[2], g2);  add_edge(v2[2], v2[0], g2);
59  add_edge(v2[4], v2[5], g2); add_edge(v2[5], v2[7], g2); 
60  add_edge(v2[7], v2[8], g2);
61  add_edge(v2[8], v2[6], g2); add_edge(v2[6], v2[4], g2);
62
63  std::vector<graph_traits<graph_t>::vertex_descriptor> f(n);
64
65#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
66  bool ret = isomorphism
67    (g1, g2, make_iterator_property_map(f.begin(), v1_index_map, f[0]),
68     degree_vertex_invariant(), get(vertex_index, g1), get(vertex_index, g2));
69#else
70  bool ret = isomorphism
71    (g1, g2, isomorphism_map
72     (make_iterator_property_map(f.begin(), v1_index_map, f[0])));
73#endif
74  std::cout << "isomorphic? " << ret << std::endl;
75
76  std::cout << "f: ";
77  for (std::size_t v = 0; v != f.size(); ++v)
78    std::cout << get(get(vertex_index, g2), f[v]) << " ";
79  std::cout << std::endl;
80 
81  return 0;
82}
Note: See TracBrowser for help on using the repository browser.