src/work/marci/edmonds_karp_demo.cc
author marci
Wed, 21 Apr 2004 14:50:42 +0000
changeset 358 caf183989ec4
parent 330 7ac0d4e8a31c
child 376 5c12f3515452
permissions -rw-r--r--
time comparison for bfs iterator and iterator by hand
marci@174
     1
// -*- c++ -*-
marci@73
     2
#include <iostream>
marci@73
     3
#include <fstream>
marci@73
     4
marci@174
     5
#include <list_graph.h>
marci@305
     6
#include <smart_graph.h>
marci@174
     7
#include <dimacs.h>
marci@174
     8
#include <edmonds_karp.h>
marci@73
     9
#include <time_measure.h>
marci@303
    10
//#include <graph_wrapper.h>
marci@311
    11
#include <preflow.h>
marci@333
    12
#include <for_each_macros.h>
marci@266
    13
alpar@105
    14
using namespace hugo;
marci@73
    15
marci@73
    16
// Use a DIMACS max flow file as stdin.
marci@73
    17
// read_dimacs_demo < dimacs_max_flow_file
marci@139
    18
marci@174
    19
marci@174
    20
//   struct Ize {
marci@174
    21
//   };
marci@139
    22
  
marci@174
    23
//   struct Mize {
marci@174
    24
//     Ize bumm;
marci@174
    25
//   };
marci@139
    26
marci@174
    27
//   template <typename B>
marci@174
    28
//     class Huha {
marci@174
    29
//     public:
marci@174
    30
//       int u;
marci@174
    31
//       B brr;
marci@174
    32
//     };
marci@174
    33
marci@139
    34
marci@73
    35
int main(int, char **) {
marci@73
    36
marci@174
    37
  typedef ListGraph MutableGraph;
marci@139
    38
marci@317
    39
//  typedef SmartGraph Graph;
marci@317
    40
  typedef ListGraph Graph;
marci@174
    41
  typedef Graph::Node Node;
marci@174
    42
  typedef Graph::EdgeIt EdgeIt;
marci@139
    43
marci@139
    44
marci@174
    45
//   Mize mize[10];
marci@174
    46
//   Mize bize[0];
marci@174
    47
//   Mize zize;
marci@174
    48
//   typedef Mize Tize[0];
marci@146
    49
marci@174
    50
//   std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
marci@174
    51
//   std::cout << sizeof(bize) << std::endl;
marci@146
    52
marci@146
    53
marci@174
    54
//   Huha<Tize> k;
marci@174
    55
//   std::cout << sizeof(k) << std::endl;
marci@139
    56
marci@174
    57
marci@174
    58
//   struct Bumm {
marci@174
    59
//     //int a;
marci@174
    60
//     bool b;
marci@174
    61
//   };
marci@174
    62
marci@174
    63
//   std::cout << sizeof(Bumm) << std::endl;
marci@174
    64
marci@174
    65
marci@174
    66
  Graph G;
marci@174
    67
  Node s, t;
marci@174
    68
  Graph::EdgeMap<int> cap(G);
marci@73
    69
  readDimacsMaxFlow(std::cin, G, s, t, cap);
marci@333
    70
  Timer ts;
marci@333
    71
  Graph::EdgeMap<int> flow(G); //0 flow
marci@333
    72
  Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@333
    73
    pre_flow_test(G, s, t, cap, flow);
marci@333
    74
  MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@333
    75
    max_flow_test(G, s, t, cap, flow);
marci@155
    76
marci@311
    77
  {
marci@311
    78
    std::cout << "preflow ..." << std::endl;
marci@311
    79
    ts.reset();
marci@333
    80
    pre_flow_test.run();
marci@311
    81
    std::cout << "elapsed time: " << ts << std::endl;
marci@333
    82
    std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
marci@311
    83
  }
marci@73
    84
marci@133
    85
  {
marci@311
    86
    std::cout << "physical blocking flow augmentation ..." << std::endl;
marci@333
    87
    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@174
    88
    ts.reset();
marci@174
    89
    int i=0;
marci@333
    90
    while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174
    91
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
    92
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
    93
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@168
    94
  }
marci@168
    95
marci@268
    96
  {
marci@311
    97
    std::cout << "faster physical blocking flow augmentation ..." << std::endl;
marci@333
    98
    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@268
    99
    ts.reset();
marci@268
   100
    int i=0;
marci@333
   101
    while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
marci@268
   102
    std::cout << "elapsed time: " << ts << std::endl;
marci@268
   103
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@268
   104
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@268
   105
  }
marci@266
   106
marci@269
   107
  {
marci@311
   108
    std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
marci@333
   109
    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@269
   110
    ts.reset();
marci@269
   111
    int i=0;
marci@333
   112
    while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@269
   113
    std::cout << "elapsed time: " << ts << std::endl;
marci@269
   114
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@269
   115
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@269
   116
  }
marci@266
   117
marci@168
   118
  {
marci@311
   119
    std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
marci@333
   120
    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@206
   121
    ts.reset();
marci@174
   122
    int i=0;
marci@333
   123
    while (max_flow_test.augmentOnShortestPath()) { ++i; }
marci@174
   124
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
   125
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   126
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@168
   127
  }
marci@133
   128
marci@73
   129
marci@73
   130
  return 0;
marci@73
   131
}