]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/reachable-loop-tail.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / graph / example / reachable-loop-tail.cpp
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
9 /*
10 IMPORTANT!!!
11 ~~~~~~~~~~~~
12 This example uses interfaces that have been deprecated and removed from Boost.Grpah.
13 Someone needs to update it, as it does NOT compile.
14 */
15
16 #include <boost/config.hpp>
17 #include <iostream>
18 #include <fstream>
19 #include <boost/graph/adjacency_list.hpp>
20 #include <boost/graph/depth_first_search.hpp>
21 #include <boost/graph/graphviz.hpp>
22 #include <boost/graph/copy.hpp>
23 #include <boost/graph/reverse_graph.hpp>
24
25 int
26 main(int argc, char *argv[])
27 {
28 if (argc < 3) {
29 std::cerr << "usage: reachable-loop-tail.exe <in-file> <out-file>"
30 << std::endl;
31 return -1;
32 }
33 using namespace boost;
34 GraphvizDigraph g_in;
35 read_graphviz(argv[1], g_in);
36
37 typedef adjacency_list < vecS, vecS, bidirectionalS,
38 GraphvizVertexProperty,
39 GraphvizEdgeProperty, GraphvizGraphProperty > Graph;
40 Graph g;
41 copy_graph(g_in, g);
42
43 graph_traits < GraphvizDigraph >::vertex_descriptor loop_tail = 6;
44 typedef color_traits < default_color_type > Color;
45 default_color_type c;
46
47 std::vector < default_color_type > reachable_to_tail(num_vertices(g));
48 reverse_graph < Graph > reverse_g(g);
49 depth_first_visit(reverse_g, loop_tail, default_dfs_visitor(),
50 make_iterator_property_map(reachable_to_tail.begin(),
51 get(vertex_index, g), c));
52
53 std::ofstream loops_out(argv[2]);
54 loops_out << "digraph G {\n"
55 << " graph [ratio=\"fill\",size=\"3,3\"];\n"
56 << " node [shape=\"box\"];\n" << " edge [style=\"bold\"];\n";
57
58 property_map<Graph, vertex_attribute_t>::type
59 vattr_map = get(vertex_attribute, g);
60 graph_traits < GraphvizDigraph >::vertex_iterator i, i_end;
61 for (boost::tie(i, i_end) = vertices(g_in); i != i_end; ++i) {
62 loops_out << *i << "[label=\"" << vattr_map[*i]["label"]
63 << "\"";
64 if (reachable_to_tail[*i] != Color::white()) {
65 loops_out << ", color=\"gray\", style=\"filled\"";
66 }
67 loops_out << "]\n";
68 }
69 graph_traits < GraphvizDigraph >::edge_iterator e, e_end;
70 for (boost::tie(e, e_end) = edges(g_in); e != e_end; ++e)
71 loops_out << source(*e, g) << " -> " << target(*e, g) << ";\n";
72 loops_out << "}\n";
73 return EXIT_SUCCESS;
74 }