finish_edge_bug.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Author: Alex Lauser
  2. // Output (Note that 'finish_edge' is never printed):
  3. // The example graph:
  4. // 0 --> 1 2
  5. // 1 --> 2
  6. // 2 --> 0
  7. #include <boost/config.hpp>
  8. #include <iostream>
  9. #include <vector>
  10. #include <boost/graph/adjacency_list.hpp>
  11. #include <boost/graph/graph_utility.hpp>
  12. template<typename graph_t>
  13. struct TalkativeVisitor
  14. : boost::dfs_visitor<>
  15. {
  16. typedef typename boost::graph_traits<graph_t>::vertex_descriptor vertex_descriptor;
  17. typedef typename boost::graph_traits<graph_t>::edge_descriptor edge_descriptor;
  18. // // Commented out to avoid clutter of the output.
  19. // void discover_vertex(vertex_descriptor u, const graph_t&) { // check!
  20. // std::cout << "discover_vertex: " << u << std::endl;
  21. // }
  22. // void finish_vertex(vertex_descriptor u, const graph_t&) { // check!
  23. // std::cout << "finish_vertex: " << u << std::endl;
  24. // }
  25. // void initialize_vertex(vertex_descriptor u, const graph_t&) { // check!
  26. // std::cout << "initialize_vertex: " << u << std::endl;
  27. // }
  28. // void start_vertex(vertex_descriptor u, const graph_t&) { // check!
  29. // std::cout << "start_vertex: " << u << std::endl;
  30. // }
  31. // void examine_edge(edge_descriptor u, const graph_t&) { // check!
  32. // std::cout << "examine_edge: " << u << std::endl;
  33. // }
  34. // void tree_edge(edge_descriptor u, const graph_t&) { // check!
  35. // std::cout << "tree_edge: " << u << std::endl;
  36. // }
  37. // void back_edge(edge_descriptor u, const graph_t&) { // check!
  38. // std::cout << "back_edge: " << u << std::endl;
  39. // }
  40. // void forward_or_cross_edge(edge_descriptor u, const graph_t&) { // check!
  41. // std::cout << "forward_or_cross_edge: " << u << std::endl;
  42. // }
  43. void finish_edge(edge_descriptor u, const graph_t&) { // uncalled!
  44. std::cout << "finish_edge: " << u << std::endl;
  45. }
  46. };
  47. template <typename t>
  48. std::ostream &operator<<(std::ostream &os, const std::pair<t,t> &x) {
  49. return os << "(" << x.first << ", " << x.second << ")";
  50. }
  51. int main(int, char*[])
  52. {
  53. using namespace boost;
  54. typedef adjacency_list<vecS, vecS, directedS> Graph;
  55. Graph G;
  56. typedef graph_traits<adjacency_list<vecS, vecS, directedS> >::vertex_descriptor Vertex;
  57. Vertex a = add_vertex(G);
  58. Vertex b = add_vertex(G);
  59. Vertex c = add_vertex(G);
  60. add_edge(a, b, G);
  61. add_edge(b, c, G);
  62. add_edge(c, a, G);
  63. add_edge(a, c, G);
  64. std::cout << "The example graph:" << std::endl;
  65. print_graph(G);
  66. std::vector<default_color_type> color(num_vertices(G));
  67. depth_first_search(G, visitor(TalkativeVisitor<Graph>()));
  68. return 0;
  69. }