src/work/marci/edmonds_karp_demo.cc
author marci
Tue, 16 Mar 2004 15:27:20 +0000
changeset 189 04becc472709
parent 174 44700ed9ffaa
child 206 47f62d789fe7
permissions -rw-r--r--
LedaGraph -> LedaGraphWrapper
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@188
    37
//  typedef SmartGraph Graph;
marci@188
    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@174
   117
    std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
marci@174
   118
    Graph::EdgeMap<int> flow(G); //0 flow
marci@168
   119
marci@174
   120
    Timer ts;
marci@174
   121
    ts.reset();
marci@174
   122
marci@174
   123
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
   124
    //max_flow_test.augmentWithBlockingFlow<Graph>();
marci@174
   125
    int i=0;
marci@174
   126
    while (max_flow_test.augmentOnBlockingFlow2()) { 
marci@174
   127
//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@168
   128
//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@168
   129
//     }
marci@168
   130
//     std::cout<<std::endl;
marci@174
   131
      ++i; 
marci@174
   132
    }
marci@133
   133
marci@174
   134
//   std::cout << "maximum flow: "<< std::endl;
marci@174
   135
//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@174
   136
//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@174
   137
//   }
marci@174
   138
//   std::cout<<std::endl;
marci@174
   139
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
   140
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   141
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@133
   142
  }
marci@133
   143
marci@133
   144
  {
marci@174
   145
    std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
marci@174
   146
    Graph::EdgeMap<int> flow(G); //0 flow
marci@133
   147
marci@174
   148
    Timer ts;
marci@174
   149
    ts.reset();
marci@174
   150
marci@174
   151
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
   152
    //max_flow_test.augmentWithBlockingFlow<Graph>();
marci@174
   153
    int i=0;
marci@174
   154
    while (max_flow_test.augmentOnShortestPath()) { 
marci@174
   155
//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@168
   156
//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@168
   157
//     }
marci@168
   158
//     std::cout<<std::endl;
marci@174
   159
      ++i; 
marci@174
   160
    }
marci@174
   161
marci@174
   162
//   std::cout << "maximum flow: "<< std::endl;
marci@174
   163
//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@174
   164
//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@174
   165
//   }
marci@174
   166
//   std::cout<<std::endl;
marci@174
   167
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
   168
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   169
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@168
   170
  }
marci@133
   171
marci@73
   172
marci@73
   173
  return 0;
marci@73
   174
}