src/work/marci/edmonds_karp_demo.cc
author marci
Mon, 01 Mar 2004 12:06:56 +0000
changeset 138 c6297c121409
parent 133 0631992fe7a1
child 139 c76f1eea05d2
permissions -rw-r--r--
.
marci@73
     1
#include <iostream>
marci@73
     2
#include <fstream>
marci@73
     3
marci@73
     4
#include <list_graph.hh>
marci@73
     5
#include <dimacs.hh>
marci@73
     6
#include <edmonds_karp.hh>
marci@73
     7
#include <time_measure.h>
marci@73
     8
alpar@105
     9
using namespace hugo;
marci@73
    10
marci@73
    11
// Use a DIMACS max flow file as stdin.
marci@73
    12
// read_dimacs_demo < dimacs_max_flow_file
marci@73
    13
int main(int, char **) {
marci@73
    14
  typedef ListGraph::NodeIt NodeIt;
marci@73
    15
  typedef ListGraph::EachEdgeIt EachEdgeIt;
marci@73
    16
marci@73
    17
  ListGraph G;
marci@73
    18
  NodeIt s, t;
marci@73
    19
  ListGraph::EdgeMap<int> cap(G);
marci@73
    20
  readDimacsMaxFlow(std::cin, G, s, t, cap);
marci@73
    21
marci@133
    22
  {
marci@133
    23
  std::cout << "edmonds karp demo (blocking flow augmentation)..." << std::endl;
marci@73
    24
  ListGraph::EdgeMap<int> flow(G); //0 flow
marci@73
    25
marci@73
    26
  double pre_time=currTime();
marci@73
    27
  MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@133
    28
  //max_flow_test.augmentWithBlockingFlow<ListGraph>();
marci@138
    29
  int i=0;
marci@138
    30
  while (max_flow_test.augmentOnBlockingFlow<ListGraph>()) { ++i; }
marci@73
    31
  double post_time=currTime();
marci@133
    32
marci@73
    33
  //std::cout << "maximum flow: "<< std::endl;
marci@73
    34
  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
marci@73
    35
  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@73
    36
  //}
marci@73
    37
  //std::cout<<std::endl;
marci@73
    38
  std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
marci@138
    39
  std::cout << "number of augmentation phases: " << i << std::endl; 
marci@73
    40
  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@133
    41
  }
marci@133
    42
marci@133
    43
  {
marci@133
    44
  std::cout << "edmonds karp demo (shortest path augmentation)..." << std::endl;
marci@133
    45
  ListGraph::EdgeMap<int> flow(G); //0 flow
marci@133
    46
marci@133
    47
  double pre_time=currTime();
marci@133
    48
  MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@133
    49
  //max_flow_test.augmentWithBlockingFlow<ListGraph>();
marci@138
    50
  int i=0;
marci@138
    51
  while (max_flow_test.augmentOnShortestPath()) { ++i; }
marci@133
    52
  double post_time=currTime();
marci@133
    53
marci@133
    54
  //std::cout << "maximum flow: "<< std::endl;
marci@133
    55
  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
marci@133
    56
  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@133
    57
  //}
marci@133
    58
  //std::cout<<std::endl;
marci@133
    59
  std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
marci@138
    60
  std::cout << "number of augmentation phases: " << i << std::endl; 
marci@133
    61
  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@133
    62
  }
marci@73
    63
marci@73
    64
  return 0;
marci@73
    65
}