scc.cpp 1.5 KB

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