]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/remove_edge_if_bidir.cpp
1 //=======================================================================
2 // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
3 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
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 //=======================================================================
10 #include <boost/config.hpp>
12 #include <boost/graph/adjacency_list.hpp>
13 #include <boost/graph/graph_utility.hpp>
23 1(0,3) 2(0,2) 3(0,3) 4(1,3) 5(2,0) 6(3,2)
25 removing edges connecting 0 to 3
30 2(0,2) 4(1,3) 5(2,0) 6(3,2)
31 removing edges with weight greater than 3
41 using namespace boost
;
43 typedef adjacency_list
<vecS
, vecS
, bidirectionalS
,
44 no_property
, property
<edge_weight_t
, int> > Graph
;
46 struct has_weight_greater_than
{
47 has_weight_greater_than(int w_
, Graph
& g_
) : w(w_
), g(g_
) { }
48 bool operator()(graph_traits
<Graph
>::edge_descriptor e
) {
49 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
50 property_map
<Graph
, edge_weight_t
>::type weight
= get(edge_weight
, g
);
51 return get(weight
, e
) > w
;
53 // This version of get() breaks VC++
54 return get(edge_weight
, g
, e
) > w
;
64 typedef std::pair
<std::size_t,std::size_t> Edge
;
65 Edge edge_array
[6] = { Edge(0,3), Edge(0,2), Edge(0, 3),
70 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
72 for (std::size_t j
= 0; j
< 6; ++j
)
73 add_edge(edge_array
[j
].first
, edge_array
[j
].second
, g
);
75 Graph
g(edge_array
, edge_array
+ 6, 4);
77 property_map
<Graph
, edge_weight_t
>::type
78 weight
= get(edge_weight
, g
);
81 graph_traits
<Graph
>::edge_iterator ei
, ei_end
;
82 for (boost::tie(ei
, ei_end
) = edges(g
); ei
!= ei_end
; ++ei
)
85 property_map
<Graph
, vertex_index_t
>::type indexmap
= get(vertex_index
, g
);
87 std::cout
<< "original graph:" << std::endl
;
88 print_graph(g
, indexmap
);
89 print_edges2(g
, indexmap
, weight
);
90 std::cout
<< std::endl
;
92 std::cout
<< "removing edges connecting 0 to 3" << std::endl
;
93 remove_out_edge_if(vertex(0,g
), incident_to(vertex(3,g
), g
), g
);
94 print_graph(g
, indexmap
);
95 print_edges2(g
, indexmap
, weight
);
97 std::cout
<< "removing edges with weight greater than 3" << std::endl
;
98 remove_edge_if(has_weight_greater_than(3, g
), g
);
99 print_graph(g
, indexmap
);
100 print_edges2(g
, indexmap
, weight
);