1 //=======================================================================
2 // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
8 #include <boost/config.hpp>
9 #include <iostream>
10 #include <boost/graph/copy.hpp>
11 #include <boost/graph/adjacency_list.hpp>
12 #include <boost/graph/filtered_graph.hpp>
13 #include <boost/graph/graph_utility.hpp>
14
15 template <typename Graph>
16 struct non_zero_degree {
non_zero_degreenon_zero_degree17 non_zero_degree() { } // has to have a default constructor!
18
non_zero_degreenon_zero_degree19 non_zero_degree(const Graph& g) : g(&g) { }
20
operator ()non_zero_degree21 bool operator()(typename boost::graph_traits<Graph>::vertex_descriptor v) const
22 {
23 return degree(v, *g) != 0;
24 }
25 const Graph* g;
26 };
27
28 int
main()29 main()
30 {
31 using namespace boost;
32 typedef adjacency_list < vecS, vecS, bidirectionalS,
33 property < vertex_name_t, char > > graph_t;
34
35 enum { a, b, c, d, e, f, g, N };
36 graph_t G(N);
37 property_map < graph_t, vertex_name_t >::type
38 name_map = get(vertex_name, G);
39 char name = 'a';
40 graph_traits < graph_t >::vertex_iterator v, v_end;
41 for (boost::tie(v, v_end) = vertices(G); v != v_end; ++v, ++name)
42 name_map[*v] = name;
43
44 typedef std::pair < int, int >E;
45 E edges[] = { E(a, c), E(a, d), E(b, a), E(b, d), E(c, f),
46 E(d, c), E(d, e), E(d, f), E(e, b), E(e, g), E(f, e), E(f, g)
47 };
48 for (int i = 0; i < 12; ++i)
49 add_edge(edges[i].first, edges[i].second, G);
50
51 print_graph(G, name_map);
52 std::cout << std::endl;
53
54 clear_vertex(b, G);
55 clear_vertex(d, G);
56
57 graph_t G_copy;
58 copy_graph(make_filtered_graph(G, keep_all(), non_zero_degree<graph_t>(G)), G_copy);
59
60 print_graph(G_copy, get(vertex_name, G_copy));
61
62 return 0;
63 }
64