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