]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/remove_edge_if_undir.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / graph / example / remove_edge_if_undir.cpp
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 using namespace boost;
16
17 /*
18 Sample output:
19
20 original graph:
21 0 <--> 3 3 2
22 1 <--> 3
23 2 <--> 0 3
24 3 <--> 0 0 1 2
25 1(0,3) 2(0,3) 3(1,3) 4(2,0) 5(3,2)
26
27 removing edges connecting 0 and 3
28 0 <--> 2
29 1 <--> 3
30 2 <--> 0 3
31 3 <--> 1 2
32 3(1,3) 4(2,0) 5(3,2)
33 removing edges with weight greater than 3
34 0 <-->
35 1 <--> 3
36 2 <-->
37 3 <--> 1
38 3(1,3)
39
40 */
41
42 typedef adjacency_list<vecS, vecS, undirectedS,
43 no_property, property<edge_weight_t, int> > Graph;
44
45 struct has_weight_greater_than {
46 has_weight_greater_than(int w_, Graph& g_) : w(w_), g(g_) { }
47 bool operator()(graph_traits<Graph>::edge_descriptor e) {
48 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
49 property_map<Graph, edge_weight_t>::type weight = get(edge_weight, g);
50 return get(weight, e) > w;
51 #else
52 // This version of get breaks VC++
53 return get(edge_weight, g, e) > w;
54 #endif
55 }
56 int w;
57 Graph& g;
58 };
59
60 int
61 main()
62 {
63 typedef std::pair<std::size_t,std::size_t> Edge;
64 Edge edge_array[5] = { Edge(0, 3), Edge(0, 3),
65 Edge(1, 3),
66 Edge(2, 0),
67 Edge(3, 2) };
68
69 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
70 Graph g(4);
71 for (std::size_t j = 0; j < 5; ++j)
72 add_edge(edge_array[j].first, edge_array[j].second, g);
73 #else
74 Graph g(edge_array, edge_array + 5, 4);
75 #endif
76 property_map<Graph, edge_weight_t>::type
77 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 std::cout << "original graph:" << std::endl;
85 print_graph(g, get(vertex_index, g));
86 print_edges2(g, get(vertex_index, g), get(edge_weight, g));
87 std::cout << std::endl;
88
89 std::cout << "removing edges connecting 0 and 3" << std::endl;
90 remove_out_edge_if(vertex(0, g), incident_on(vertex(3, g), g), g);
91 print_graph(g, get(vertex_index, g));
92 print_edges2(g, get(vertex_index, g), get(edge_weight, g));
93
94 std::cout << "removing edges with weight greater than 3" << std::endl;
95 remove_edge_if(has_weight_greater_than(3, g), g);
96 print_graph(g, get(vertex_index, g));
97 print_edges2(g, get(vertex_index, g), get(edge_weight, g));
98
99 return 0;
100 }