reachable-loop-tail.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //=======================================================================
  2. // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
  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. /*
  9. IMPORTANT!!!
  10. ~~~~~~~~~~~~
  11. This example uses interfaces that have been deprecated and removed from Boost.Grpah.
  12. Someone needs to update it, as it does NOT compile.
  13. */
  14. #include <boost/config.hpp>
  15. #include <iostream>
  16. #include <fstream>
  17. #include <boost/graph/adjacency_list.hpp>
  18. #include <boost/graph/depth_first_search.hpp>
  19. #include <boost/graph/graphviz.hpp>
  20. #include <boost/graph/copy.hpp>
  21. #include <boost/graph/reverse_graph.hpp>
  22. int
  23. main(int argc, char *argv[])
  24. {
  25. if (argc < 3) {
  26. std::cerr << "usage: reachable-loop-tail.exe <in-file> <out-file>"
  27. << std::endl;
  28. return -1;
  29. }
  30. using namespace boost;
  31. GraphvizDigraph g_in;
  32. read_graphviz(argv[1], g_in);
  33. typedef adjacency_list < vecS, vecS, bidirectionalS,
  34. GraphvizVertexProperty,
  35. GraphvizEdgeProperty, GraphvizGraphProperty > Graph;
  36. Graph g;
  37. copy_graph(g_in, g);
  38. graph_traits < GraphvizDigraph >::vertex_descriptor loop_tail = 6;
  39. typedef color_traits < default_color_type > Color;
  40. default_color_type c;
  41. std::vector < default_color_type > reachable_to_tail(num_vertices(g));
  42. reverse_graph < Graph > reverse_g(g);
  43. depth_first_visit(reverse_g, loop_tail, default_dfs_visitor(),
  44. make_iterator_property_map(reachable_to_tail.begin(),
  45. get(vertex_index, g), c));
  46. std::ofstream loops_out(argv[2]);
  47. loops_out << "digraph G {\n"
  48. << " graph [ratio=\"fill\",size=\"3,3\"];\n"
  49. << " node [shape=\"box\"];\n" << " edge [style=\"bold\"];\n";
  50. property_map<Graph, vertex_attribute_t>::type
  51. vattr_map = get(vertex_attribute, g);
  52. graph_traits < GraphvizDigraph >::vertex_iterator i, i_end;
  53. for (boost::tie(i, i_end) = vertices(g_in); i != i_end; ++i) {
  54. loops_out << *i << "[label=\"" << vattr_map[*i]["label"]
  55. << "\"";
  56. if (reachable_to_tail[*i] != Color::white()) {
  57. loops_out << ", color=\"gray\", style=\"filled\"";
  58. }
  59. loops_out << "]\n";
  60. }
  61. graph_traits < GraphvizDigraph >::edge_iterator e, e_end;
  62. for (boost::tie(e, e_end) = edges(g_in); e != e_end; ++e)
  63. loops_out << source(*e, g) << " -> " << target(*e, g) << ";\n";
  64. loops_out << "}\n";
  65. return EXIT_SUCCESS;
  66. }