Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/graph/example/max_flow.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.6 KB
Line 
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#include <boost/config.hpp>
11#include <iostream>
12#include <string>
13#include <boost/graph/push_relabel_max_flow.hpp>
14#include <boost/graph/adjacency_list.hpp>
15#include <boost/graph/read_dimacs.hpp>
16#include <boost/graph/graph_utility.hpp>
17
18// Use a DIMACS network flow file as stdin.
19// max_flow < max_flow.dat
20//
21// Sample output:
22//  c  The total flow:
23//  s 13
24//
25//  c flow values:
26//  f 0 6 3
27//  f 0 1 6
28//  f 0 2 4
29//  f 1 5 1
30//  f 1 0 0
31//  f 1 3 5
32//  f 2 4 4
33//  f 2 3 0
34//  f 2 0 0
35//  f 3 7 5
36//  f 3 2 0
37//  f 3 1 0
38//  f 4 5 4
39//  f 4 6 0
40//  f 5 4 0
41//  f 5 7 5
42//  f 6 7 3
43//  f 6 4 0
44//  f 7 6 0
45//  f 7 5 0
46
47int
48main()
49{
50  using namespace boost;
51
52  typedef adjacency_list_traits<vecS, vecS, directedS> Traits;
53  typedef adjacency_list<listS, vecS, directedS, 
54    property<vertex_name_t, std::string>,
55    property<edge_capacity_t, long,
56      property<edge_residual_capacity_t, long,
57        property<edge_reverse_t, Traits::edge_descriptor> > >
58  > Graph;
59
60  Graph g;
61
62  property_map<Graph, edge_capacity_t>::type
63    capacity = get(edge_capacity, g);
64  property_map<Graph, edge_reverse_t>::type
65    rev = get(edge_reverse, g);
66  property_map<Graph, edge_residual_capacity_t>::type
67    residual_capacity = get(edge_residual_capacity, g);
68
69  Traits::vertex_descriptor s, t;
70  read_dimacs_max_flow(g, capacity, rev, s, t);
71
72  long flow;
73#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
74  // Use non-named parameter version
75  property_map<Graph, vertex_index_t>::type
76    indexmap = get(vertex_index, g);
77  flow = push_relabel_max_flow(g, s, t, capacity, residual_capacity, rev, indexmap);
78#else
79  flow = push_relabel_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 (tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter)
89    for (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 0;
95}
Note: See TracBrowser for help on using the repository browser.