filtered_vec_as_graph.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //=======================================================================
  2. // Copyright 2001 University of Notre Dame.
  3. // Author: Jeremy G. Siek
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //=======================================================================
  9. /*
  10. Sample output:
  11. filtered out-edges:
  12. A -->
  13. B -->
  14. C --> E
  15. D --> E
  16. E -->
  17. */
  18. #include <boost/config.hpp>
  19. #include <iostream>
  20. #include <boost/graph/vector_as_graph.hpp>
  21. #include <boost/graph/filtered_graph.hpp>
  22. #include <boost/graph/graph_utility.hpp>
  23. struct constant_target {
  24. constant_target() { }
  25. constant_target(int t) : target(t) { }
  26. bool operator()(const std::pair<int,int>& e) const {
  27. return e.second == target;
  28. }
  29. int target;
  30. };
  31. int main()
  32. {
  33. using namespace boost;
  34. enum { A, B, C, D, E, N };
  35. const char* name = "ABCDE";
  36. typedef std::vector < std::list < int > > Graph;
  37. Graph g(N);
  38. g[A].push_back(B);
  39. g[A].push_back(C);
  40. g[C].push_back(D);
  41. g[C].push_back(E);
  42. g[D].push_back(E);
  43. g[E].push_back(C);
  44. constant_target filter(E);
  45. filtered_graph<Graph, constant_target> fg(g, filter);
  46. std::cout << "filtered out-edges:" << std::endl;
  47. print_graph(fg, name);
  48. return 0;
  49. }