| 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/config.hpp> | 
|---|
| 9 | #include <fstream> | 
|---|
| 10 | #include <map> | 
|---|
| 11 | #include <string> | 
|---|
| 12 | #include <boost/graph/strong_components.hpp> | 
|---|
| 13 | #include <boost/graph/graphviz.hpp> | 
|---|
| 14 |  | 
|---|
| 15 | int | 
|---|
| 16 | main() | 
|---|
| 17 | { | 
|---|
| 18 |   using namespace boost; | 
|---|
| 19 |   GraphvizDigraph g; | 
|---|
| 20 |   read_graphviz("figs/scc.dot", g); | 
|---|
| 21 |  | 
|---|
| 22 |   typedef graph_traits < GraphvizDigraph >::vertex_descriptor vertex_t; | 
|---|
| 23 |   std::map < vertex_t, int >component; | 
|---|
| 24 |  | 
|---|
| 25 |   strong_components(g, make_assoc_property_map(component)); | 
|---|
| 26 |  | 
|---|
| 27 |   property_map < GraphvizDigraph, vertex_attribute_t >::type | 
|---|
| 28 |     vertex_attr_map = get(vertex_attribute, g); | 
|---|
| 29 |   std::string color[] = { | 
|---|
| 30 |   "white", "gray", "black", "lightgray"}; | 
|---|
| 31 |   graph_traits < GraphvizDigraph >::vertex_iterator vi, vi_end; | 
|---|
| 32 |   for (tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) { | 
|---|
| 33 |     vertex_attr_map[*vi]["color"] = color[component[*vi]]; | 
|---|
| 34 |     vertex_attr_map[*vi]["style"] = "filled"; | 
|---|
| 35 |     if (vertex_attr_map[*vi]["color"] == "black") | 
|---|
| 36 |       vertex_attr_map[*vi]["fontcolor"] = "white"; | 
|---|
| 37 |   } | 
|---|
| 38 |   write_graphviz("figs/scc-out.dot", g); | 
|---|
| 39 |  | 
|---|
| 40 |   return EXIT_SUCCESS; | 
|---|
| 41 | } | 
|---|