cc-internet.cpp 1.6 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 <vector>
  17. #include <string>
  18. #include <boost/graph/connected_components.hpp>
  19. #include <boost/graph/graphviz.hpp>
  20. int
  21. main()
  22. {
  23. using namespace boost;
  24. GraphvizGraph g;
  25. read_graphviz("figs/cc-internet.dot", g);
  26. std::vector<int> component(num_vertices(g));
  27. connected_components
  28. (g, make_iterator_property_map(component.begin(),
  29. get(vertex_index, g), component[0]));
  30. property_map < GraphvizGraph, vertex_attribute_t >::type
  31. vertex_attr_map = get(vertex_attribute, g);
  32. std::string color[] = {
  33. "white", "gray", "black", "lightgray"};
  34. graph_traits < GraphvizGraph >::vertex_iterator vi, vi_end;
  35. for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) {
  36. vertex_attr_map[*vi]["color"] = color[component[*vi]];
  37. vertex_attr_map[*vi]["style"] = "filled";
  38. if (vertex_attr_map[*vi]["color"] == "black")
  39. vertex_attr_map[*vi]["fontcolor"] = "white";
  40. }
  41. write_graphviz("figs/cc-internet-out.dot", g);
  42. }