1 //=======================================================================
2 // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
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 //=======================================================================
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.
17 #include <boost/config.hpp>
20 #include <boost/graph/adjacency_list.hpp>
21 #include <boost/graph/depth_first_search.hpp>
22 #include <boost/graph/graphviz.hpp>
23 #include <boost/graph/copy.hpp>
26 main(int argc
, char *argv
[])
29 std::cerr
<< "usage: reachable-loop-head.exe <in-file> <out-file>"
33 using namespace boost
;
35 read_graphviz(argv
[1], g
);
36 graph_traits
< GraphvizDigraph
>::vertex_descriptor loop_head
= 1;
37 typedef color_traits
< default_color_type
> Color
;
39 std::vector
< default_color_type
>
40 reachable_from_head(num_vertices(g
), Color::white());
42 depth_first_visit(g
, loop_head
, default_dfs_visitor(),
43 make_iterator_property_map(reachable_from_head
.begin(),
44 get(vertex_index
, g
), c
));
46 property_map
<GraphvizDigraph
, vertex_attribute_t
>::type
47 vattr_map
= get(vertex_attribute
, g
);
49 graph_traits
< GraphvizDigraph
>::vertex_iterator i
, i_end
;
50 for (boost::tie(i
, i_end
) = vertices(g
); i
!= i_end
; ++i
)
51 if (reachable_from_head
[*i
] != Color::white()) {
52 vattr_map
[*i
]["color"] = "gray";
53 vattr_map
[*i
]["style"] = "filled";
56 std::ofstream
loops_out(argv
[2]);
57 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
58 // VC++ has trouble with the get_property() functions
59 loops_out
<< "digraph G {\n"
63 graph_traits
<GraphvizDigraph
>::vertex_iterator vi
, vi_end
;
64 for (boost::tie(vi
, vi_end
) = vertices(g
); vi
!= vi_end
; ++vi
) {
65 loops_out
<< *vi
<< "[";
66 for (std::map
<std::string
,std::string
>::iterator ai
= vattr_map
[*vi
].begin();
67 ai
!= vattr_map
[*vi
].end(); ++ai
) {
68 loops_out
<< ai
->first
<< "=" << ai
->second
;
69 if (next(ai
) != vattr_map
[*vi
].end())
74 property_map
<GraphvizDigraph
, edge_attribute_t
>::type
75 eattr_map
= get(edge_attribute
, g
);
76 graph_traits
<GraphvizDigraph
>::edge_iterator ei
, ei_end
;
77 for (boost::tie(ei
, ei_end
) = edges(g
); ei
!= ei_end
; ++ei
) {
78 loops_out
<< source(*ei
, g
) << " -> " << target(*ei
, g
) << "[";
79 std::map
<std::string
,std::string
>& attr_map
= eattr_map
[*ei
];
80 for (std::map
<std::string
,std::string
>::iterator eai
= attr_map
.begin();
81 eai
!= attr_map
.end(); ++eai
) {
82 loops_out
<< eai
->first
<< "=" << eai
->second
;
83 if (next(eai
) != attr_map
.end())
90 get_property(g
, graph_graph_attribute
)["size"] = "3,3";
91 get_property(g
, graph_graph_attribute
)["ratio"] = "fill";
92 get_property(g
, graph_vertex_attribute
)["shape"] = "box";
94 write_graphviz(loops_out
, g
,
95 make_vertex_attributes_writer(g
),
96 make_edge_attributes_writer(g
),
97 make_graph_attributes_writer(g
));