//======================================================================= // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee, // // This file is part of the Boost Graph Library // // You should have received a copy of the License Agreement for the // Boost Graph Library along with the software; see the file LICENSE. // If not, contact Office of Research, Indiana University, // Bloomington, IN 47405. // // Permission to modify the code and to distribute the code is // granted, provided the text of this NOTICE is retained, a notice if // the code was modified is included with the above COPYRIGHT NOTICE // and with the COPYRIGHT NOTICE in the LICENSE file, and that the // LICENSE file is distributed with the modified code. // // LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. // By way of example, but not limitation, Licensor MAKES NO // REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY // PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS // OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS // OR OTHER RIGHTS. //======================================================================= #include #include #include #include #include #include #include int main(int argc, char *argv[]) { if (argc < 3) { std::cerr << "usage: reachable-loop-head.exe " << std::endl; return -1; } using namespace boost; GraphvizDigraph g; read_graphviz(argv[1], g); graph_traits < GraphvizDigraph >::vertex_descriptor loop_head = 1; typedef color_traits < default_color_type > Color; std::vector < default_color_type > reachable_from_head(num_vertices(g), Color::white()); depth_first_visit(g, loop_head, default_dfs_visitor(), make_iterator_property_map(reachable_from_head.begin(), get(vertex_index, g))); graph_traits < GraphvizDigraph >::vertex_iterator i, i_end; for (tie(i, i_end) = vertices(g); i != i_end; ++i) if (reachable_from_head[*i] != Color::white()) { get(vertex_attribute, g)[*i]["color"] = "gray"; get(vertex_attribute, g)[*i]["style"] = "filled"; } get_property(g, graph_graph_attribute)["size"] = "3,3"; get_property(g, graph_graph_attribute)["ratio"] = "fill"; get_property(g, graph_vertex_attribute)["shape"] = "box"; std::ofstream loops_out(argv[2]); write_graphviz(loops_out, g, make_vertex_attributes_writer(g), make_edge_attributes_writer(g), make_graph_attributes_writer(g)); return EXIT_SUCCESS; }