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