transitive_closure.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) Jeremy Siek 2001
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // NOTE: this final is generated by libs/graph/doc/transitive_closure.w
  7. #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  8. #error The transitive closure algorithm uses partial specialization.
  9. #endif
  10. #include <boost/graph/transitive_closure.hpp>
  11. #include <boost/graph/graphviz.hpp>
  12. #include <boost/graph/graph_utility.hpp>
  13. int
  14. main(int, char *[])
  15. {
  16. using namespace boost;
  17. typedef property < vertex_name_t, char >Name;
  18. typedef property < vertex_index_t, std::size_t, Name > Index;
  19. typedef adjacency_list < listS, listS, directedS, Index > graph_t;
  20. typedef graph_traits < graph_t >::vertex_descriptor vertex_t;
  21. graph_t G;
  22. std::vector < vertex_t > verts(4);
  23. for (int i = 0; i < 4; ++i)
  24. verts[i] = add_vertex(Index(i, Name('a' + i)), G);
  25. add_edge(verts[1], verts[2], G);
  26. add_edge(verts[1], verts[3], G);
  27. add_edge(verts[2], verts[1], G);
  28. add_edge(verts[3], verts[2], G);
  29. add_edge(verts[3], verts[0], G);
  30. std::cout << "Graph G:" << std::endl;
  31. print_graph(G, get(vertex_name, G));
  32. adjacency_list <> TC;
  33. transitive_closure(G, TC);
  34. std::cout << std::endl << "Graph G+:" << std::endl;
  35. char name[] = "abcd";
  36. print_graph(TC, name);
  37. std::cout << std::endl;
  38. std::ofstream out("tc-out.dot");
  39. write_graphviz(out, TC, make_label_writer(name));
  40. return 0;
  41. }