src/work/marci/edmonds_karp_demo.cc
author marci
Mon, 22 Mar 2004 15:53:05 +0000
changeset 232 cb87fb9d4c94
parent 188 ad1417e74042
child 243 a85fd87460e3
permissions -rw-r--r--
.
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@174
     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@155
    10
#include <graph_wrapper.h>
marci@73
    11
alpar@105
    12
using namespace hugo;
marci@73
    13
marci@73
    14
// Use a DIMACS max flow file as stdin.
marci@73
    15
// read_dimacs_demo < dimacs_max_flow_file
marci@139
    16
marci@174
    17
marci@174
    18
//   struct Ize {
marci@174
    19
//   };
marci@139
    20
  
marci@174
    21
//   struct Mize {
marci@174
    22
//     Ize bumm;
marci@174
    23
//   };
marci@139
    24
marci@174
    25
//   template <typename B>
marci@174
    26
//     class Huha {
marci@174
    27
//     public:
marci@174
    28
//       int u;
marci@174
    29
//       B brr;
marci@174
    30
//     };
marci@174
    31
marci@139
    32
marci@73
    33
int main(int, char **) {
marci@73
    34
marci@174
    35
  typedef ListGraph MutableGraph;
marci@139
    36
marci@206
    37
  typedef SmartGraph Graph;
marci@206
    38
  //typedef ListGraph Graph;
marci@174
    39
  typedef Graph::Node Node;
marci@174
    40
  typedef Graph::EdgeIt EdgeIt;
marci@139
    41
marci@139
    42
marci@174
    43
//   Mize mize[10];
marci@174
    44
//   Mize bize[0];
marci@174
    45
//   Mize zize;
marci@174
    46
//   typedef Mize Tize[0];
marci@146
    47
marci@174
    48
//   std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
marci@174
    49
//   std::cout << sizeof(bize) << std::endl;
marci@146
    50
marci@146
    51
marci@174
    52
//   Huha<Tize> k;
marci@174
    53
//   std::cout << sizeof(k) << std::endl;
marci@139
    54
marci@174
    55
marci@174
    56
//   struct Bumm {
marci@174
    57
//     //int a;
marci@174
    58
//     bool b;
marci@174
    59
//   };
marci@174
    60
marci@174
    61
//   std::cout << sizeof(Bumm) << std::endl;
marci@174
    62
marci@174
    63
marci@174
    64
  Graph G;
marci@174
    65
  Node s, t;
marci@174
    66
  Graph::EdgeMap<int> cap(G);
marci@73
    67
  readDimacsMaxFlow(std::cin, G, s, t, cap);
marci@155
    68
marci@174
    69
//   typedef TrivGraphWrapper<Graph> TGW;
marci@174
    70
//   TGW gw(G);
marci@174
    71
//   TGW::NodeIt sw;
marci@174
    72
//   gw./*getF*/first(sw);
marci@174
    73
//   std::cout << "p1:" << gw.nodeNum() << std::endl;
marci@174
    74
//   gw.erase(sw);
marci@174
    75
//   std::cout << "p2:" << gw.nodeNum() << std::endl;
marci@174
    76
marci@174
    77
//   typedef const Graph cLG;
marci@174
    78
//   typedef TrivGraphWrapper<const cLG> CTGW;
marci@174
    79
//   CTGW cgw(G);
marci@174
    80
//   CTGW::NodeIt csw;
marci@174
    81
//   cgw./*getF*/first(csw);
marci@174
    82
//   std::cout << "p1:" << cgw.nodeNum() << std::endl;
marci@174
    83
//   //cgw.erase(csw);
marci@174
    84
//   std::cout << "p2:" << cgw.nodeNum() << std::endl;
marci@174
    85
marci@73
    86
marci@133
    87
  {
marci@174
    88
    std::cout << "SmartGraph..." << std::endl;
marci@174
    89
    std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
marci@174
    90
    Graph::EdgeMap<int> flow(G); //0 flow
marci@73
    91
marci@174
    92
    Timer ts;
marci@174
    93
    ts.reset();
marci@174
    94
marci@174
    95
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
    96
    //max_flow_test.augmentWithBlockingFlow<Graph>();
marci@174
    97
    int i=0;
marci@174
    98
    while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { 
marci@174
    99
//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@168
   100
//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@168
   101
//     }
marci@168
   102
//     std::cout<<std::endl;
marci@174
   103
      ++i; 
marci@174
   104
    }
marci@168
   105
marci@174
   106
//   std::cout << "maximum flow: "<< std::endl;
marci@174
   107
//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@174
   108
//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@174
   109
//   }
marci@174
   110
//   std::cout<<std::endl;
marci@174
   111
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
   112
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   113
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@168
   114
  }
marci@168
   115
marci@168
   116
  {
marci@206
   117
    std::cout << "SmartGraph..." << std::endl;
marci@206
   118
    std::cout << "edmonds karp demo (physical blocking flow 1 augmentation)..." << std::endl;
marci@206
   119
    Graph::EdgeMap<int> flow(G); //0 flow
marci@206
   120
marci@206
   121
    Timer ts;
marci@206
   122
    ts.reset();
marci@206
   123
marci@206
   124
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@206
   125
    //max_flow_test.augmentWithBlockingFlow<Graph>();
marci@206
   126
    int i=0;
marci@206
   127
    while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { 
marci@206
   128
//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@206
   129
//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@206
   130
//     }
marci@206
   131
//     std::cout<<std::endl;
marci@206
   132
      ++i; 
marci@206
   133
    }
marci@206
   134
marci@206
   135
//   std::cout << "maximum flow: "<< std::endl;
marci@206
   136
//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@206
   137
//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@206
   138
//   }
marci@206
   139
//   std::cout<<std::endl;
marci@206
   140
    std::cout << "elapsed time: " << ts << std::endl;
marci@206
   141
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@206
   142
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@206
   143
  }
marci@206
   144
marci@206
   145
  {
marci@174
   146
    std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
marci@174
   147
    Graph::EdgeMap<int> flow(G); //0 flow
marci@168
   148
marci@174
   149
    Timer ts;
marci@174
   150
    ts.reset();
marci@174
   151
marci@174
   152
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
   153
    //max_flow_test.augmentWithBlockingFlow<Graph>();
marci@174
   154
    int i=0;
marci@174
   155
    while (max_flow_test.augmentOnBlockingFlow2()) { 
marci@174
   156
//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@168
   157
//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@168
   158
//     }
marci@168
   159
//     std::cout<<std::endl;
marci@174
   160
      ++i; 
marci@174
   161
    }
marci@133
   162
marci@174
   163
//   std::cout << "maximum flow: "<< std::endl;
marci@174
   164
//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@174
   165
//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@174
   166
//   }
marci@174
   167
//   std::cout<<std::endl;
marci@174
   168
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
   169
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   170
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@133
   171
  }
marci@133
   172
marci@133
   173
  {
marci@174
   174
    std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
marci@174
   175
    Graph::EdgeMap<int> flow(G); //0 flow
marci@133
   176
marci@174
   177
    Timer ts;
marci@174
   178
    ts.reset();
marci@174
   179
marci@174
   180
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
   181
    //max_flow_test.augmentWithBlockingFlow<Graph>();
marci@174
   182
    int i=0;
marci@174
   183
    while (max_flow_test.augmentOnShortestPath()) { 
marci@174
   184
//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@168
   185
//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@168
   186
//     }
marci@168
   187
//     std::cout<<std::endl;
marci@174
   188
      ++i; 
marci@174
   189
    }
marci@174
   190
marci@174
   191
//   std::cout << "maximum flow: "<< std::endl;
marci@174
   192
//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@174
   193
//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@174
   194
//   }
marci@174
   195
//   std::cout<<std::endl;
marci@174
   196
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
   197
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   198
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@168
   199
  }
marci@133
   200
marci@73
   201
marci@73
   202
  return 0;
marci@73
   203
}