src/work/marci/edmonds_karp_demo.cc
author marci
Thu, 04 Mar 2004 19:45:06 +0000
changeset 156 a34e5a909e97
parent 146 c4adf922624f
child 168 27fbd1559fb7
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@155
     8
#include <graph_wrapper.h>
marci@73
     9
alpar@105
    10
using namespace hugo;
marci@73
    11
marci@73
    12
// Use a DIMACS max flow file as stdin.
marci@73
    13
// read_dimacs_demo < dimacs_max_flow_file
marci@139
    14
marci@139
    15
/*
marci@139
    16
  struct Ize {
marci@139
    17
  };
marci@139
    18
  
marci@139
    19
  struct Mize {
marci@139
    20
    Ize bumm;
marci@139
    21
  };
marci@139
    22
marci@139
    23
  template <typename B>
marci@139
    24
    class Huha {
marci@139
    25
    public:
marci@139
    26
      int u;
marci@139
    27
      B brr;
marci@139
    28
    };
marci@139
    29
*/
marci@139
    30
marci@73
    31
int main(int, char **) {
marci@73
    32
  typedef ListGraph::NodeIt NodeIt;
marci@73
    33
  typedef ListGraph::EachEdgeIt EachEdgeIt;
marci@73
    34
marci@139
    35
/*
marci@139
    36
  Mize mize[10];
marci@139
    37
  Mize bize[0];
marci@139
    38
  Mize zize;
marci@139
    39
  typedef Mize Tize[0];
marci@139
    40
marci@139
    41
  std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
marci@139
    42
  std::cout << sizeof(bize) << std::endl;
marci@139
    43
marci@139
    44
marci@139
    45
  Huha<Tize> k;
marci@139
    46
  std::cout << sizeof(k) << std::endl;
marci@146
    47
marci@146
    48
marci@146
    49
  struct Bumm {
marci@146
    50
    //int a;
marci@146
    51
    bool b;
marci@146
    52
  };
marci@146
    53
marci@146
    54
  std::cout << sizeof(Bumm) << std::endl;
marci@139
    55
*/
marci@139
    56
marci@73
    57
  ListGraph G;
marci@73
    58
  NodeIt s, t;
marci@73
    59
  ListGraph::EdgeMap<int> cap(G);
marci@73
    60
  readDimacsMaxFlow(std::cin, G, s, t, cap);
marci@155
    61
/*
marci@155
    62
  typedef TrivGraphWrapper<ListGraph> TGW;
marci@155
    63
  TGW gw(G);
marci@155
    64
  TGW::EachNodeIt sw;
marci@155
    65
  gw.getFirst(sw);
marci@155
    66
  std::cout << "p1:" << gw.nodeNum() << std::endl;
marci@155
    67
  gw.erase(sw);
marci@155
    68
  std::cout << "p2:" << gw.nodeNum() << std::endl;
marci@155
    69
marci@155
    70
  typedef const ListGraph cLG;
marci@155
    71
  typedef TrivGraphWrapper<const cLG> CTGW;
marci@155
    72
  CTGW cgw(G);
marci@155
    73
  CTGW::EachNodeIt csw;
marci@155
    74
  cgw.getFirst(csw);
marci@155
    75
  std::cout << "p1:" << cgw.nodeNum() << std::endl;
marci@155
    76
  //cgw.erase(csw);
marci@155
    77
  std::cout << "p2:" << cgw.nodeNum() << std::endl;
marci@155
    78
*/
marci@73
    79
marci@133
    80
  {
marci@133
    81
  std::cout << "edmonds karp demo (blocking flow augmentation)..." << std::endl;
marci@73
    82
  ListGraph::EdgeMap<int> flow(G); //0 flow
marci@73
    83
marci@144
    84
  Timer ts;
marci@144
    85
  ts.reset();
marci@144
    86
  //double pre_time=currTime();
marci@73
    87
  MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@133
    88
  //max_flow_test.augmentWithBlockingFlow<ListGraph>();
marci@138
    89
  int i=0;
marci@138
    90
  while (max_flow_test.augmentOnBlockingFlow<ListGraph>()) { ++i; }
marci@144
    91
  //double post_time=currTime();
marci@133
    92
marci@73
    93
  //std::cout << "maximum flow: "<< std::endl;
marci@73
    94
  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
marci@73
    95
  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@73
    96
  //}
marci@73
    97
  //std::cout<<std::endl;
marci@144
    98
  std::cout << "elapsed time: " << ts << std::endl;
marci@138
    99
  std::cout << "number of augmentation phases: " << i << std::endl; 
marci@73
   100
  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@133
   101
  }
marci@133
   102
marci@133
   103
  {
marci@133
   104
  std::cout << "edmonds karp demo (shortest path augmentation)..." << std::endl;
marci@133
   105
  ListGraph::EdgeMap<int> flow(G); //0 flow
marci@133
   106
marci@144
   107
  Timer ts;
marci@144
   108
  ts.reset();
marci@144
   109
  //double pre_time=currTime();
marci@133
   110
  MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@133
   111
  //max_flow_test.augmentWithBlockingFlow<ListGraph>();
marci@138
   112
  int i=0;
marci@138
   113
  while (max_flow_test.augmentOnShortestPath()) { ++i; }
marci@144
   114
  //double post_time=currTime();
marci@133
   115
marci@133
   116
  //std::cout << "maximum flow: "<< std::endl;
marci@133
   117
  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
marci@133
   118
  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@133
   119
  //}
marci@133
   120
  //std::cout<<std::endl;
marci@144
   121
  std::cout << "elapsed time: " << ts << std::endl;
marci@138
   122
  std::cout << "number of augmentation phases: " << i << std::endl; 
marci@133
   123
  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@133
   124
  }
marci@73
   125
marci@73
   126
  return 0;
marci@73
   127
}