src/work/marci/edmonds_karp_demo.cc
author alpar
Mon, 26 Apr 2004 08:07:53 +0000
changeset 405 a2d8ec38e8db
parent 389 770cc1f4861f
child 415 679e64913c5e
permissions -rw-r--r--
#define HUGO_SMART_GRAPH_H ---> #define HUGO_LIST_GRAPH_H
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@389
     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@390
    12
#include <preflow_res.h>
marci@333
    13
#include <for_each_macros.h>
marci@266
    14
alpar@105
    15
using namespace hugo;
marci@73
    16
marci@73
    17
// Use a DIMACS max flow file as stdin.
marci@73
    18
// read_dimacs_demo < dimacs_max_flow_file
marci@139
    19
marci@174
    20
marci@174
    21
//   struct Ize {
marci@174
    22
//   };
marci@139
    23
  
marci@174
    24
//   struct Mize {
marci@174
    25
//     Ize bumm;
marci@174
    26
//   };
marci@139
    27
marci@174
    28
//   template <typename B>
marci@174
    29
//     class Huha {
marci@174
    30
//     public:
marci@174
    31
//       int u;
marci@174
    32
//       B brr;
marci@174
    33
//     };
marci@174
    34
marci@139
    35
marci@73
    36
int main(int, char **) {
marci@73
    37
marci@174
    38
  typedef ListGraph MutableGraph;
marci@139
    39
marci@317
    40
//  typedef SmartGraph Graph;
marci@317
    41
  typedef ListGraph Graph;
marci@174
    42
  typedef Graph::Node Node;
marci@174
    43
  typedef Graph::EdgeIt EdgeIt;
marci@139
    44
marci@139
    45
marci@174
    46
//   Mize mize[10];
marci@174
    47
//   Mize bize[0];
marci@174
    48
//   Mize zize;
marci@174
    49
//   typedef Mize Tize[0];
marci@146
    50
marci@174
    51
//   std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
marci@174
    52
//   std::cout << sizeof(bize) << std::endl;
marci@146
    53
marci@146
    54
marci@174
    55
//   Huha<Tize> k;
marci@174
    56
//   std::cout << sizeof(k) << std::endl;
marci@139
    57
marci@174
    58
marci@174
    59
//   struct Bumm {
marci@174
    60
//     //int a;
marci@174
    61
//     bool b;
marci@174
    62
//   };
marci@174
    63
marci@174
    64
//   std::cout << sizeof(Bumm) << std::endl;
marci@174
    65
marci@174
    66
marci@174
    67
  Graph G;
marci@174
    68
  Node s, t;
marci@174
    69
  Graph::EdgeMap<int> cap(G);
marci@73
    70
  readDimacsMaxFlow(std::cin, G, s, t, cap);
marci@333
    71
  Timer ts;
marci@333
    72
  Graph::EdgeMap<int> flow(G); //0 flow
marci@333
    73
  Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@376
    74
    pre_flow_test(G, s, t, cap, flow, true);
marci@390
    75
  PreflowRes<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@390
    76
    pre_flow_res(G, s, t, cap, flow, true);
marci@333
    77
  MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@333
    78
    max_flow_test(G, s, t, cap, flow);
marci@155
    79
marci@311
    80
  {
marci@311
    81
    std::cout << "preflow ..." << std::endl;
marci@311
    82
    ts.reset();
marci@333
    83
    pre_flow_test.run();
marci@311
    84
    std::cout << "elapsed time: " << ts << std::endl;
marci@333
    85
    std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
marci@311
    86
  }
marci@73
    87
marci@133
    88
  {
marci@376
    89
    std::cout << "wrapped preflow ..." << std::endl;
marci@376
    90
    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@376
    91
    ts.reset();
marci@390
    92
    pre_flow_res.run();
marci@376
    93
    std::cout << "elapsed time: " << ts << std::endl;
marci@376
    94
    std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
marci@376
    95
  }
marci@376
    96
marci@376
    97
  {
marci@311
    98
    std::cout << "physical blocking flow augmentation ..." << std::endl;
marci@333
    99
    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@174
   100
    ts.reset();
marci@174
   101
    int i=0;
marci@333
   102
    while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174
   103
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
   104
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   105
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@168
   106
  }
marci@168
   107
marci@268
   108
  {
marci@311
   109
    std::cout << "faster physical blocking flow augmentation ..." << std::endl;
marci@333
   110
    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@268
   111
    ts.reset();
marci@268
   112
    int i=0;
marci@333
   113
    while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
marci@268
   114
    std::cout << "elapsed time: " << ts << std::endl;
marci@268
   115
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@268
   116
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@268
   117
  }
marci@266
   118
marci@269
   119
  {
marci@311
   120
    std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
marci@333
   121
    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@269
   122
    ts.reset();
marci@269
   123
    int i=0;
marci@333
   124
    while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@269
   125
    std::cout << "elapsed time: " << ts << std::endl;
marci@269
   126
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@269
   127
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@269
   128
  }
marci@266
   129
marci@168
   130
  {
marci@311
   131
    std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
marci@333
   132
    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@206
   133
    ts.reset();
marci@174
   134
    int i=0;
marci@333
   135
    while (max_flow_test.augmentOnShortestPath()) { ++i; }
marci@174
   136
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
   137
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   138
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@168
   139
  }
marci@133
   140
marci@73
   141
marci@73
   142
  return 0;
marci@73
   143
}