1 //=======================================================================
2 // Copyright 2001 University of Notre Dame.
3 // Author: 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 /*
11 Sample output:
12
13 filtered edge set: (A,B) (C,D) (D,B)
14 filtered out-edges:
15 A --> B
16 B -->
17 C --> D
18 D --> B
19 E -->
20 */
21
22 #include <boost/config.hpp>
23 #include <iostream>
24 #include <boost/graph/adjacency_list.hpp>
25 #include <boost/graph/filtered_graph.hpp>
26 #include <boost/graph/graph_utility.hpp>
27
28 template < typename EdgeWeightMap > struct positive_edge_weight
29 {
positive_edge_weightpositive_edge_weight30 positive_edge_weight() {}
positive_edge_weightpositive_edge_weight31 positive_edge_weight(EdgeWeightMap weight) : m_weight(weight) {}
operator ()positive_edge_weight32 template < typename Edge > bool operator()(const Edge& e) const
33 {
34 return 0 < boost::get(m_weight, e);
35 }
36 EdgeWeightMap m_weight;
37 };
38
main()39 int main()
40 {
41 using namespace boost;
42
43 typedef adjacency_list< vecS, vecS, directedS, no_property,
44 property< edge_weight_t, int > >
45 Graph;
46 typedef property_map< Graph, edge_weight_t >::type EdgeWeightMap;
47
48 enum
49 {
50 A,
51 B,
52 C,
53 D,
54 E,
55 N
56 };
57 const char* name = "ABCDE";
58 Graph g(N);
59 add_edge(A, B, 2, g);
60 add_edge(A, C, 0, g);
61 add_edge(C, D, 1, g);
62 add_edge(C, E, 0, g);
63 add_edge(D, B, 3, g);
64 add_edge(E, C, 0, g);
65
66 positive_edge_weight< EdgeWeightMap > filter(get(edge_weight, g));
67 filtered_graph< Graph, positive_edge_weight< EdgeWeightMap > > fg(
68 g, filter);
69
70 std::cout << "filtered edge set: ";
71 print_edges(fg, name);
72
73 std::cout << "filtered out-edges:" << std::endl;
74 print_graph(fg, name);
75
76 return 0;
77 }
78