vf2_sub_graph_iso_multi_example.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //=======================================================================
  2. // Copyright (C) 2012 Flavio De Lorenzi (fdlorenzi@gmail.com)
  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. //=======================================================================
  8. #include <boost/graph/adjacency_list.hpp>
  9. #include <boost/graph/vf2_sub_graph_iso.hpp>
  10. using namespace boost;
  11. int main() {
  12. typedef property<edge_name_t, char> edge_property;
  13. typedef property<vertex_name_t, char, property<vertex_index_t, int> > vertex_property;
  14. // Using a vecS graphs => the index maps are implicit.
  15. typedef adjacency_list<vecS, vecS, bidirectionalS, vertex_property, edge_property> graph_type;
  16. // Build graph1
  17. graph_type graph1;
  18. add_vertex(vertex_property('a'), graph1);
  19. add_vertex(vertex_property('a'), graph1);
  20. add_vertex(vertex_property('a'), graph1);
  21. add_edge(0, 1, edge_property('b'), graph1);
  22. add_edge(0, 1, edge_property('b'), graph1);
  23. add_edge(0, 1, edge_property('d'), graph1);
  24. add_edge(1, 2, edge_property('s'), graph1);
  25. add_edge(2, 2, edge_property('l'), graph1);
  26. add_edge(2, 2, edge_property('l'), graph1);
  27. // Build graph2
  28. graph_type graph2;
  29. add_vertex(vertex_property('a'), graph2);
  30. add_vertex(vertex_property('a'), graph2);
  31. add_vertex(vertex_property('a'), graph2);
  32. add_vertex(vertex_property('a'), graph2);
  33. add_vertex(vertex_property('a'), graph2);
  34. add_vertex(vertex_property('a'), graph2);
  35. add_edge(0, 1, edge_property('a'), graph2);
  36. add_edge(0, 1, edge_property('a'), graph2);
  37. add_edge(0, 1, edge_property('b'), graph2);
  38. add_edge(1, 2, edge_property('s'), graph2);
  39. add_edge(2, 3, edge_property('b'), graph2);
  40. add_edge(2, 3, edge_property('d'), graph2);
  41. add_edge(2, 3, edge_property('b'), graph2);
  42. add_edge(3, 4, edge_property('s'), graph2);
  43. add_edge(4, 4, edge_property('l'), graph2);
  44. add_edge(4, 4, edge_property('l'), graph2);
  45. add_edge(4, 5, edge_property('c'), graph2);
  46. add_edge(4, 5, edge_property('c'), graph2);
  47. add_edge(4, 5, edge_property('c'), graph2);
  48. add_edge(5, 0, edge_property('s'), graph2);
  49. // create predicates
  50. typedef property_map<graph_type, vertex_name_t>::type vertex_name_map_t;
  51. typedef property_map_equivalent<vertex_name_map_t, vertex_name_map_t> vertex_comp_t;
  52. vertex_comp_t vertex_comp =
  53. make_property_map_equivalent(get(vertex_name, graph1), get(vertex_name, graph2));
  54. typedef property_map<graph_type, edge_name_t>::type edge_name_map_t;
  55. typedef property_map_equivalent<edge_name_map_t, edge_name_map_t> edge_comp_t;
  56. edge_comp_t edge_comp =
  57. make_property_map_equivalent(get(edge_name, graph1), get(edge_name, graph2));
  58. // Create callback
  59. vf2_print_callback<graph_type, graph_type> callback(graph1, graph2);
  60. // Print out all subgraph isomorphism mappings between graph1 and graph2.
  61. // Function vertex_order_by_mult is used to compute the order of
  62. // vertices of graph1. This is the order in which the vertices are examined
  63. // during the matching process.
  64. vf2_subgraph_iso(graph1, graph2, callback, vertex_order_by_mult(graph1),
  65. edges_equivalent(edge_comp).vertices_equivalent(vertex_comp));
  66. return 0;
  67. }