remove_edge_if_dir.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //=======================================================================
  2. // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
  3. // Authors: Andrew Lumsdaine, Lie-Quan Lee, 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. #include <boost/config.hpp>
  10. #include <iostream>
  11. #include <boost/graph/adjacency_list.hpp>
  12. #include <boost/graph/graph_utility.hpp>
  13. /*
  14. Sample output:
  15. original graph:
  16. 0 --> 3 2 3
  17. 1 --> 3
  18. 2 --> 0
  19. 3 --> 2
  20. removing edges (0,3)
  21. 0 --> 2
  22. 1 --> 3
  23. 2 --> 0
  24. 3 --> 2
  25. removing edge (0,2) and (3, 2)
  26. 0 -->
  27. 1 --> 3
  28. 2 --> 0
  29. 3 -->
  30. */
  31. using namespace boost;
  32. typedef adjacency_list<vecS, vecS, directedS> Graph;
  33. int
  34. main()
  35. {
  36. typedef std::pair<std::size_t,std::size_t> Edge;
  37. Edge edges[6] = { Edge(0,3), Edge(0,2), Edge(0, 3),
  38. Edge(1,3),
  39. Edge(2, 0),
  40. Edge(3, 2) };
  41. #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
  42. // VC++ can't handle iterator constructor
  43. Graph g(4);
  44. for (std::size_t j = 0; j < 6; ++j)
  45. add_edge(edges[j].first, edges[j].second, g);
  46. #else
  47. Graph g(edges, edges + 6, 4);
  48. #endif
  49. std::cout << "original graph:" << std::endl;
  50. print_graph(g, get(vertex_index, g));
  51. std::cout << std::endl;
  52. std::cout << "removing edges (0,3)" << std::endl;
  53. remove_out_edge_if(vertex(0,g), incident_to(vertex(3,g), g), g);
  54. print_graph(g, get(vertex_index, g));
  55. std::cout << "removing edge (0,2) and (3, 2)" << std::endl;
  56. remove_edge_if(incident_to(vertex(2,g), g), g);
  57. print_graph(g, get(vertex_index, g));
  58. return 0;
  59. }