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 //=======================================================================
14 // 1 --(12, 20)--> 4 --(12, 40)--> 3
15 // <--(8,10)-- 0 <--(16,20)-- 2
24 // 6 --(16, 20)--> 5 --(8, 10)--> 8
25 // <--(12,20)-- 7 <--(12,40)-- 3
34 // 1 --(12, 2)--> 4 --(12, 3)--> 3
35 // <--(8,1)-- 0 <--(16,4)-- 2
45 // <--(12,10)-- 7 <--(12,5)-- 3
51 #include <boost/config.hpp>
54 #include <boost/utility.hpp>
55 #include <boost/property_map/property_map.hpp>
56 #include <boost/graph/adjacency_list.hpp>
59 using namespace boost
;
63 enum edge_myflow_t
{ edge_myflow
};
64 enum edge_mycapacity_t
{ edge_mycapacity
};
67 BOOST_INSTALL_PROPERTY(edge
, myflow
);
68 BOOST_INSTALL_PROPERTY(edge
, mycapacity
);
72 template <class Graph
>
73 void print_network(const Graph
& G
)
75 typedef typename
boost::graph_traits
<Graph
>::vertex_iterator Viter
;
76 typedef typename
boost::graph_traits
<Graph
>::out_edge_iterator OutEdgeIter
;
77 typedef typename
boost::graph_traits
<Graph
>::in_edge_iterator InEdgeIter
;
79 typename property_map
<Graph
, edge_mycapacity_t
>::const_type
80 capacity
= get(edge_mycapacity
, G
);
81 typename property_map
<Graph
, edge_myflow_t
>::const_type
82 flow
= get(edge_myflow
, G
);
85 boost::tie(ui
, uiend
) = vertices(G
);
87 for (; ui
!= uiend
; ++ui
) {
88 OutEdgeIter out
, out_end
;
91 boost::tie(out
, out_end
) = out_edges(*ui
, G
);
92 for(; out
!= out_end
; ++out
)
93 cout
<< "--(" << capacity
[*out
] << ", " << flow
[*out
] << ")--> "
94 << target(*out
,G
) << "\t";
96 InEdgeIter in
, in_end
;
98 boost::tie(in
, in_end
) = in_edges(*ui
, G
);
99 for(; in
!= in_end
; ++in
)
100 cout
<< "<--(" << capacity
[*in
] << "," << flow
[*in
] << ")-- "
101 << source(*in
,G
) << "\t";
108 int main(int , char* [])
110 typedef property
<edge_mycapacity_t
, int> Cap
;
111 typedef property
<edge_myflow_t
, int, Cap
> Flow
;
112 typedef adjacency_list
<vecS
, vecS
, bidirectionalS
,
113 no_property
, Flow
> Graph
;
115 const int num_vertices
= 9;
116 Graph
G(num_vertices
);
122 0 ---->1---->3----->6--->8
129 add_edge(0, 1, Flow(10, Cap(8)), G
);
131 add_edge(1, 4, Flow(20, Cap(12)), G
);
132 add_edge(4, 7, Flow(20, Cap(12)), G
);
133 add_edge(7, 6, Flow(20, Cap(12)), G
);
135 add_edge(1, 3, Flow(40, Cap(12)), G
);
136 add_edge(3, 6, Flow(40, Cap(12)), G
);
138 add_edge(6, 5, Flow(20, Cap(16)), G
);
139 add_edge(5, 2, Flow(20, Cap(16)), G
);
140 add_edge(2, 1, Flow(20, Cap(16)), G
);
142 add_edge(6, 8, Flow(10, Cap(8)), G
);
146 property_map
<Graph
, edge_myflow_t
>::type
147 flow
= get(edge_myflow
, G
);
149 boost::graph_traits
<Graph
>::vertex_iterator v
, v_end
;
150 boost::graph_traits
<Graph
>::out_edge_iterator e
, e_end
;
152 for (boost::tie(v
, v_end
) = vertices(G
); v
!= v_end
; ++v
)
153 for (boost::tie(e
, e_end
) = out_edges(*v
, G
); e
!= e_end
; ++e
)
155 cout
<< endl
<< endl
;
157 remove_edge(6, 8, G
);