]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/edmonds-karp-eg.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / graph / example / edmonds-karp-eg.cpp
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
9 #ifdef _MSC_VER
10 #define _CRT_SECURE_NO_WARNINGS
11 #endif
12
13 #include <boost/config.hpp>
14 #include <iostream>
15 #include <string>
16 #include <boost/graph/edmonds_karp_max_flow.hpp>
17 #include <boost/graph/adjacency_list.hpp>
18 #include <boost/graph/read_dimacs.hpp>
19 #include <boost/graph/graph_utility.hpp>
20
21 // Use a DIMACS network flow file as stdin.
22 // edmonds-karp-eg < max_flow.dat
23 //
24 // Sample output:
25 // c The total flow:
26 // s 13
27 //
28 // c flow values:
29 // f 0 6 3
30 // f 0 1 6
31 // f 0 2 4
32 // f 1 5 1
33 // f 1 0 0
34 // f 1 3 5
35 // f 2 4 4
36 // f 2 3 0
37 // f 2 0 0
38 // f 3 7 5
39 // f 3 2 0
40 // f 3 1 0
41 // f 4 5 4
42 // f 4 6 0
43 // f 5 4 0
44 // f 5 7 5
45 // f 6 7 3
46 // f 6 4 0
47 // f 7 6 0
48 // f 7 5 0
49
50 int
51 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 > > > > Graph;
61
62 Graph g;
63
64 property_map < Graph, edge_capacity_t >::type
65 capacity = get(edge_capacity, g);
66 property_map < Graph, edge_reverse_t >::type rev = get(edge_reverse, g);
67 property_map < Graph, edge_residual_capacity_t >::type
68 residual_capacity = get(edge_residual_capacity, g);
69
70 Traits::vertex_descriptor s, t;
71 read_dimacs_max_flow(g, capacity, rev, s, t);
72
73 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
74 std::vector<default_color_type> color(num_vertices(g));
75 std::vector<Traits::edge_descriptor> pred(num_vertices(g));
76 long flow = edmonds_karp_max_flow
77 (g, s, t, capacity, residual_capacity, rev, &color[0], &pred[0]);
78 #else
79 long flow = edmonds_karp_max_flow(g, s, t);
80 #endif
81
82 std::cout << "c The total flow:" << std::endl;
83 std::cout << "s " << flow << std::endl << std::endl;
84
85 std::cout << "c flow values:" << std::endl;
86 graph_traits < Graph >::vertex_iterator u_iter, u_end;
87 graph_traits < Graph >::out_edge_iterator ei, e_end;
88 for (boost::tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter)
89 for (boost::tie(ei, e_end) = out_edges(*u_iter, g); ei != e_end; ++ei)
90 if (capacity[*ei] > 0)
91 std::cout << "f " << *u_iter << " " << target(*ei, g) << " "
92 << (capacity[*ei] - residual_capacity[*ei]) << std::endl;
93
94 return EXIT_SUCCESS;
95 }