eg1-iso.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Boost.Graph library isomorphism test
  2. // Copyright (C) 2001 Douglas Gregor (gregod@cs.rpi.edu)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // For more information, see http://www.boost.org
  8. //
  9. // Revision History:
  10. //
  11. // 29 Nov 2001 Jeremy Siek
  12. // Changed to use Boost.Random.
  13. // 29 Nov 2001 Doug Gregor
  14. // Initial checkin.
  15. #define BOOST_INCLUDE_MAIN
  16. #include <boost/test/test_tools.hpp>
  17. #include <boost/graph/adjacency_list.hpp>
  18. #include <boost/graph/isomorphism.hpp>
  19. //#include "isomorphism-v3.hpp"
  20. #include <boost/property_map/property_map.hpp>
  21. #include <iostream>
  22. #include <fstream>
  23. #include <map>
  24. #include <algorithm>
  25. #include <cstdlib>
  26. #include <ctime>
  27. using namespace boost;
  28. enum { a, b, c, d, e, f, g, h };
  29. enum { _1, _2, _3, _4, _5, _6, _7, _8 };
  30. void test_isomorphism()
  31. {
  32. typedef adjacency_list<vecS, vecS, bidirectionalS> GraphA;
  33. typedef adjacency_list<vecS, vecS, bidirectionalS> GraphB;
  34. char a_names[] = "abcdefgh";
  35. char b_names[] = "12345678";
  36. GraphA Ga(8);
  37. add_edge(a, d, Ga);
  38. add_edge(a, h, Ga);
  39. add_edge(b, c, Ga);
  40. add_edge(b, e, Ga);
  41. add_edge(c, f, Ga);
  42. add_edge(d, a, Ga);
  43. add_edge(d, h, Ga);
  44. add_edge(e, b, Ga);
  45. add_edge(f, b, Ga);
  46. add_edge(f, e, Ga);
  47. add_edge(g, d, Ga);
  48. add_edge(g, f, Ga);
  49. add_edge(h, c, Ga);
  50. add_edge(h, g, Ga);
  51. GraphB Gb(8);
  52. add_edge(_1, _6, Gb);
  53. add_edge(_2, _1, Gb);
  54. add_edge(_2, _5, Gb);
  55. add_edge(_3, _2, Gb);
  56. add_edge(_3, _4, Gb);
  57. add_edge(_4, _2, Gb);
  58. add_edge(_4, _3, Gb);
  59. add_edge(_5, _4, Gb);
  60. add_edge(_5, _6, Gb);
  61. add_edge(_6, _7, Gb);
  62. add_edge(_6, _8, Gb);
  63. add_edge(_7, _8, Gb);
  64. add_edge(_8, _1, Gb);
  65. add_edge(_8, _7, Gb);
  66. std::vector<std::size_t> in_degree_A(num_vertices(Ga));
  67. boost::detail::compute_in_degree(Ga, &in_degree_A[0]);
  68. std::vector<std::size_t> in_degree_B(num_vertices(Gb));
  69. boost::detail::compute_in_degree(Gb, &in_degree_B[0]);
  70. degree_vertex_invariant<std::size_t*, GraphA>
  71. invariantA(&in_degree_A[0], Ga);
  72. degree_vertex_invariant<std::size_t*, GraphB>
  73. invariantB(&in_degree_B[0], Gb);
  74. std::vector<graph_traits<GraphB>::vertex_descriptor> f(num_vertices(Ga));
  75. bool ret = isomorphism(Ga, Gb, &f[0], invariantA, invariantB,
  76. (invariantB.max)(),
  77. get(vertex_index, Ga), get(vertex_index, Gb));
  78. assert(ret == true);
  79. for (std::size_t i = 0; i < num_vertices(Ga); ++i)
  80. std::cout << "f(" << a_names[i] << ")=" << b_names[f[i]] << std::endl;
  81. BOOST_TEST(verify_isomorphism(Ga, Gb, &f[0]));
  82. }
  83. int test_main(int, char* [])
  84. {
  85. test_isomorphism();
  86. return boost::report_errors();
  87. }