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