| 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 | #include <boost/graph/graphviz.hpp> |
|---|
| 9 | #include <boost/graph/depth_first_search.hpp> |
|---|
| 10 | |
|---|
| 11 | char name[] = "abcdefghij"; |
|---|
| 12 | |
|---|
| 13 | struct parenthesis_visitor : public boost::default_dfs_visitor |
|---|
| 14 | { |
|---|
| 15 | template <class Vertex, class Graph> void |
|---|
| 16 | start_vertex(Vertex v, const Graph &) |
|---|
| 17 | { |
|---|
| 18 | std::cout << ' '; |
|---|
| 19 | } |
|---|
| 20 | template <class Vertex, class Graph> void |
|---|
| 21 | discover_vertex(Vertex v, const Graph &) |
|---|
| 22 | { |
|---|
| 23 | std::cout << "(" << name[v] << ' '; |
|---|
| 24 | } |
|---|
| 25 | template <class Vertex, class Graph> void |
|---|
| 26 | finish_vertex(Vertex v, const Graph &) |
|---|
| 27 | { |
|---|
| 28 | std::cout << ' ' << name[v] << ")"; |
|---|
| 29 | } |
|---|
| 30 | }; |
|---|
| 31 | |
|---|
| 32 | int |
|---|
| 33 | main() |
|---|
| 34 | { |
|---|
| 35 | using namespace boost; |
|---|
| 36 | GraphvizGraph g; |
|---|
| 37 | read_graphviz("figs/dfs-example.dot", g); |
|---|
| 38 | graph_traits < GraphvizGraph >::edge_iterator e, e_end; |
|---|
| 39 | for (tie(e, e_end) = edges(g); e != e_end; ++e) |
|---|
| 40 | std::cout << '(' << name[source(*e, g)] << ' ' |
|---|
| 41 | << name[target(*e, g)] << ')' << std::endl; |
|---|
| 42 | parenthesis_visitor |
|---|
| 43 | paren_vis; |
|---|
| 44 | depth_first_search(g, visitor(paren_vis)); |
|---|
| 45 | std::cout << std::endl; |
|---|
| 46 | return 0; |
|---|
| 47 | } |
|---|