src/work/marci/edmonds_karp_demo_boost.cc
author marci
Fri, 14 May 2004 15:19:18 +0000
changeset 639 a11a4377a816
permissions -rw-r--r--
misc
marci@73
     1
#include <iostream>
marci@73
     2
#include <string>
marci@73
     3
marci@73
     4
#include <boost/config.hpp>
marci@73
     5
#include <boost/graph/edmunds_karp_max_flow.hpp>
marci@73
     6
#include <boost/graph/adjacency_list.hpp>
marci@73
     7
#include <boost/graph/read_dimacs.hpp>
marci@73
     8
#include <boost/graph/graph_utility.hpp>
marci@73
     9
marci@73
    10
#include <time_measure.h>
marci@73
    11
marci@73
    12
// Use a DIMACS network flow file as stdin.
marci@73
    13
// max_flow < max_flow.dat
marci@73
    14
int main()
marci@73
    15
{
marci@73
    16
  using namespace boost;
marci@73
    17
marci@73
    18
  typedef adjacency_list_traits<vecS, vecS, directedS> Traits;
marci@73
    19
  typedef adjacency_list<listS, vecS, directedS, 
marci@73
    20
    property<vertex_name_t, std::string>,
marci@73
    21
    property<edge_capacity_t, long,
marci@73
    22
      property<edge_residual_capacity_t, long,
marci@73
    23
        property<edge_reverse_t, Traits::edge_descriptor> > >
marci@73
    24
  > Graph;
marci@73
    25
marci@73
    26
  Graph g;
marci@73
    27
marci@73
    28
  property_map<Graph, edge_capacity_t>::type 
marci@73
    29
    capacity = get(edge_capacity, g);
marci@73
    30
  property_map<Graph, edge_reverse_t>::type 
marci@73
    31
    rev = get(edge_reverse, g);
marci@73
    32
  property_map<Graph, edge_residual_capacity_t>::type 
marci@73
    33
    residual_capacity = get(edge_residual_capacity, g);
marci@73
    34
marci@73
    35
  Traits::vertex_descriptor s, t;
marci@73
    36
  read_dimacs_max_flow(g, capacity, rev, s, t);
marci@73
    37
marci@73
    38
  std::cout << "edmonds karp demo (BOOST)..." << endl;
marci@73
    39
  double pre_time=currTime();
marci@73
    40
  long flow = edmunds_karp_max_flow(g, s, t);
marci@73
    41
  double post_time=currTime();
marci@73
    42
marci@73
    43
  //std::cout << "maximum flow: " << std::endl;
marci@73
    44
  //graph_traits<Graph>::vertex_iterator u_iter, u_end;
marci@73
    45
  //graph_traits<Graph>::out_edge_iterator ei, e_end;
marci@73
    46
  //for (tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter)
marci@73
    47
  //  for (tie(ei, e_end) = out_edges(*u_iter, g); ei != e_end; ++ei)
marci@73
    48
  //    if (capacity[*ei] > 0)
marci@73
    49
  //      std::cout << "f " << *u_iter << " " << target(*ei, g) << " " 
marci@73
    50
  //                << (capacity[*ei] - residual_capacity[*ei]) << std::endl;
marci@73
    51
  //
marci@73
    52
  //std::cout << std::endl;
marci@73
    53
  std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
marci@73
    54
  std::cout << "flow value: " << flow << std::endl;
marci@73
    55
  
marci@73
    56
  return 0;
marci@73
    57
}