]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/max_flow.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / graph / example / max_flow.cpp
1 //=======================================================================
2 // Copyright 2000 University of Notre Dame.
3 // Authors: Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee
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 #ifdef _MSC_VER
11 #define _CRT_SECURE_NO_WARNINGS
12 #endif
13
14 #include <boost/config.hpp>
15 #include <iostream>
16 #include <string>
17 #include <boost/graph/push_relabel_max_flow.hpp>
18 #include <boost/graph/adjacency_list.hpp>
19 #include <boost/graph/read_dimacs.hpp>
20 #include <boost/graph/graph_utility.hpp>
21
22 // Use a DIMACS network flow file as stdin.
23 // max_flow < max_flow.dat
24 //
25 // Sample output:
26 // c The total flow:
27 // s 13
28 //
29 // c flow values:
30 // f 0 6 3
31 // f 0 1 6
32 // f 0 2 4
33 // f 1 5 1
34 // f 1 0 0
35 // f 1 3 5
36 // f 2 4 4
37 // f 2 3 0
38 // f 2 0 0
39 // f 3 7 5
40 // f 3 2 0
41 // f 3 1 0
42 // f 4 5 4
43 // f 4 6 0
44 // f 5 4 0
45 // f 5 7 5
46 // f 6 7 3
47 // f 6 4 0
48 // f 7 6 0
49 // f 7 5 0
50
51 int main()
52 {
53 using namespace boost;
54
55 typedef adjacency_list_traits< vecS, vecS, directedS > Traits;
56 typedef adjacency_list< listS, vecS, directedS,
57 property< vertex_name_t, std::string >,
58 property< edge_capacity_t, long,
59 property< edge_residual_capacity_t, long,
60 property< edge_reverse_t, Traits::edge_descriptor > > > >
61 Graph;
62
63 Graph g;
64
65 property_map< Graph, edge_capacity_t >::type capacity
66 = get(edge_capacity, g);
67 property_map< Graph, edge_reverse_t >::type rev = get(edge_reverse, g);
68 property_map< Graph, edge_residual_capacity_t >::type residual_capacity
69 = get(edge_residual_capacity, g);
70
71 Traits::vertex_descriptor s, t;
72 read_dimacs_max_flow(g, capacity, rev, s, t);
73
74 long flow;
75 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
76 // Use non-named parameter version
77 property_map< Graph, vertex_index_t >::type indexmap = get(vertex_index, g);
78 flow = push_relabel_max_flow(
79 g, s, t, capacity, residual_capacity, rev, indexmap);
80 #else
81 flow = push_relabel_max_flow(g, s, t);
82 #endif
83
84 std::cout << "c The total flow:" << std::endl;
85 std::cout << "s " << flow << std::endl << std::endl;
86
87 std::cout << "c flow values:" << std::endl;
88 graph_traits< Graph >::vertex_iterator u_iter, u_end;
89 graph_traits< Graph >::out_edge_iterator ei, e_end;
90 for (boost::tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter)
91 for (boost::tie(ei, e_end) = out_edges(*u_iter, g); ei != e_end; ++ei)
92 if (capacity[*ei] > 0)
93 std::cout << "f " << *u_iter << " " << target(*ei, g) << " "
94 << (capacity[*ei] - residual_capacity[*ei])
95 << std::endl;
96
97 return 0;
98 }