• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 #include <boost/config.hpp>
11 #include <iostream>
12 #include <boost/graph/adjacency_list.hpp>
13 #include <boost/graph/graph_utility.hpp>
14 
15 /*
16   Sample output:
17 
18   original graph:
19   0 --> 3 2 3
20   1 --> 3
21   2 --> 0
22   3 --> 2
23   1(0,3) 2(0,2) 3(0,3) 4(1,3) 5(2,0) 6(3,2)
24 
25   removing edges connecting 0 to 3
26   0 --> 2
27   1 --> 3
28   2 --> 0
29   3 --> 2
30   2(0,2) 4(1,3) 5(2,0) 6(3,2)
31   removing edges with weight greater than 3
32   0 --> 2
33   1 -->
34   2 -->
35   3 -->
36   2(0,2)
37 
38 
39  */
40 
41 using namespace boost;
42 
43 typedef adjacency_list< vecS, vecS, bidirectionalS, no_property,
44     property< edge_weight_t, int > >
45     Graph;
46 
47 struct has_weight_greater_than
48 {
has_weight_greater_thanhas_weight_greater_than49     has_weight_greater_than(int w_, Graph& g_) : w(w_), g(g_) {}
operator ()has_weight_greater_than50     bool operator()(graph_traits< Graph >::edge_descriptor e)
51     {
52 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
53         property_map< Graph, edge_weight_t >::type weight = get(edge_weight, g);
54         return get(weight, e) > w;
55 #else
56         // This version of get() breaks VC++
57         return get(edge_weight, g, e) > w;
58 #endif
59     }
60     int w;
61     Graph& g;
62 };
63 
main()64 int main()
65 {
66     typedef std::pair< std::size_t, std::size_t > Edge;
67     Edge edge_array[6] = { Edge(0, 3), Edge(0, 2), Edge(0, 3), Edge(1, 3),
68         Edge(2, 0), Edge(3, 2) };
69 
70 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
71     Graph g(4);
72     for (std::size_t j = 0; j < 6; ++j)
73         add_edge(edge_array[j].first, edge_array[j].second, g);
74 #else
75     Graph g(edge_array, edge_array + 6, 4);
76 #endif
77     property_map< Graph, edge_weight_t >::type weight = get(edge_weight, g);
78 
79     int w = 0;
80     graph_traits< Graph >::edge_iterator ei, ei_end;
81     for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
82         weight[*ei] = ++w;
83 
84     property_map< Graph, vertex_index_t >::type indexmap = get(vertex_index, g);
85 
86     std::cout << "original graph:" << std::endl;
87     print_graph(g, indexmap);
88     print_edges2(g, indexmap, weight);
89     std::cout << std::endl;
90 
91     std::cout << "removing edges connecting 0 to 3" << std::endl;
92     remove_out_edge_if(vertex(0, g), incident_to(vertex(3, g), g), g);
93     print_graph(g, indexmap);
94     print_edges2(g, indexmap, weight);
95 
96     std::cout << "removing edges with weight greater than 3" << std::endl;
97     remove_edge_if(has_weight_greater_than(3, g), g);
98     print_graph(g, indexmap);
99     print_edges2(g, indexmap, weight);
100     return 0;
101 }
102