1 | #include <cstring> // for std::size_t
|
---|
2 | #include <iostream>
|
---|
3 | #include <string>
|
---|
4 | using namespace std;
|
---|
5 |
|
---|
6 | #include <boost/graph/adjacency_list.hpp>
|
---|
7 | #include <boost/graph/breadth_first_search.hpp>
|
---|
8 | #include <boost/graph/depth_first_search.hpp>
|
---|
9 | #include <boost/graph/visitors.hpp>
|
---|
10 | using namespace boost;
|
---|
11 |
|
---|
12 | typedef boost::property<boost::vertex_name_t, std::string,
|
---|
13 | boost::property<boost::vertex_index_t,
|
---|
14 | std::size_t> > VertexProperties;
|
---|
15 | typedef boost::adjacency_list<boost::listS,
|
---|
16 | boost::listS,
|
---|
17 | boost::bidirectionalS,
|
---|
18 | VertexProperties> Graph; // Graph object type
|
---|
19 |
|
---|
20 | typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
|
---|
21 | typedef boost::graph_traits<Graph>::edge_descriptor Edge;
|
---|
22 |
|
---|
23 | typedef boost::graph_traits<Graph>::vertex_iterator vertex_iterator;
|
---|
24 | typedef boost::graph_traits<Graph>::adjacency_iterator adjacency_iterator;
|
---|
25 | typedef Graph::inv_adjacency_iterator inv_adjacency_iterator;
|
---|
26 |
|
---|
27 | typedef boost::property_map<Graph,boost::vertex_name_t>::type
|
---|
28 | vertex_name_map_t;
|
---|
29 |
|
---|
30 | class VisitorClass : public dfs_visitor<> {
|
---|
31 | public:
|
---|
32 | VisitorClass() {}
|
---|
33 |
|
---|
34 | template <typename Edge, typename Graph>
|
---|
35 | void back_edge(Edge, const Graph&) const {
|
---|
36 | cout << "back edge" << endl;
|
---|
37 | }
|
---|
38 | };
|
---|
39 |
|
---|
40 | int
|
---|
41 | main() {
|
---|
42 | Graph g;
|
---|
43 | vertex_name_map_t vertex_names = get(vertex_name, g);
|
---|
44 | Vertex v = add_vertex(g);
|
---|
45 | Vertex u = add_vertex(g);
|
---|
46 |
|
---|
47 | vertex_names[v] = string("v");
|
---|
48 | vertex_names[u] = string("u");
|
---|
49 |
|
---|
50 | bool inserted;
|
---|
51 | tie(tuples::ignore, inserted) = add_edge(v, u, g);
|
---|
52 | assert(inserted);
|
---|
53 |
|
---|
54 | VisitorClass vst;
|
---|
55 | depth_first_search(g, visitor(vst));
|
---|
56 | // Should not print "back edge", but does.
|
---|
57 |
|
---|
58 | return 0;
|
---|
59 | }
|
---|