src/work/marci/edmonds_karp_demo.cc
author jacint
Mon, 01 Mar 2004 14:43:07 +0000
changeset 140 ca164520d31a
parent 138 c6297c121409
child 144 a1323efc5753
permissions -rw-r--r--
*** empty log message ***
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@139
    13
marci@139
    14
/*
marci@139
    15
  struct Ize {
marci@139
    16
  };
marci@139
    17
  
marci@139
    18
  struct Mize {
marci@139
    19
    Ize bumm;
marci@139
    20
  };
marci@139
    21
marci@139
    22
  template <typename B>
marci@139
    23
    class Huha {
marci@139
    24
    public:
marci@139
    25
      int u;
marci@139
    26
      B brr;
marci@139
    27
    };
marci@139
    28
*/
marci@139
    29
marci@73
    30
int main(int, char **) {
marci@73
    31
  typedef ListGraph::NodeIt NodeIt;
marci@73
    32
  typedef ListGraph::EachEdgeIt EachEdgeIt;
marci@73
    33
marci@139
    34
/*
marci@139
    35
  Mize mize[10];
marci@139
    36
  Mize bize[0];
marci@139
    37
  Mize zize;
marci@139
    38
  typedef Mize Tize[0];
marci@139
    39
marci@139
    40
  std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
marci@139
    41
  std::cout << sizeof(bize) << std::endl;
marci@139
    42
marci@139
    43
marci@139
    44
  Huha<Tize> k;
marci@139
    45
  std::cout << sizeof(k) << std::endl;
marci@139
    46
*/
marci@139
    47
marci@73
    48
  ListGraph G;
marci@73
    49
  NodeIt s, t;
marci@73
    50
  ListGraph::EdgeMap<int> cap(G);
marci@73
    51
  readDimacsMaxFlow(std::cin, G, s, t, cap);
marci@73
    52
marci@133
    53
  {
marci@133
    54
  std::cout << "edmonds karp demo (blocking flow augmentation)..." << std::endl;
marci@73
    55
  ListGraph::EdgeMap<int> flow(G); //0 flow
marci@73
    56
marci@73
    57
  double pre_time=currTime();
marci@73
    58
  MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@133
    59
  //max_flow_test.augmentWithBlockingFlow<ListGraph>();
marci@138
    60
  int i=0;
marci@138
    61
  while (max_flow_test.augmentOnBlockingFlow<ListGraph>()) { ++i; }
marci@73
    62
  double post_time=currTime();
marci@133
    63
marci@73
    64
  //std::cout << "maximum flow: "<< std::endl;
marci@73
    65
  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
marci@73
    66
  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@73
    67
  //}
marci@73
    68
  //std::cout<<std::endl;
marci@73
    69
  std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
marci@138
    70
  std::cout << "number of augmentation phases: " << i << std::endl; 
marci@73
    71
  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@133
    72
  }
marci@133
    73
marci@133
    74
  {
marci@133
    75
  std::cout << "edmonds karp demo (shortest path augmentation)..." << std::endl;
marci@133
    76
  ListGraph::EdgeMap<int> flow(G); //0 flow
marci@133
    77
marci@133
    78
  double pre_time=currTime();
marci@133
    79
  MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@133
    80
  //max_flow_test.augmentWithBlockingFlow<ListGraph>();
marci@138
    81
  int i=0;
marci@138
    82
  while (max_flow_test.augmentOnShortestPath()) { ++i; }
marci@133
    83
  double post_time=currTime();
marci@133
    84
marci@133
    85
  //std::cout << "maximum flow: "<< std::endl;
marci@133
    86
  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
marci@133
    87
  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@133
    88
  //}
marci@133
    89
  //std::cout<<std::endl;
marci@133
    90
  std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
marci@138
    91
  std::cout << "number of augmentation phases: " << i << std::endl; 
marci@133
    92
  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@133
    93
  }
marci@73
    94
marci@73
    95
  return 0;
marci@73
    96
}