src/work/marci/edmonds_karp_demo.cc
author marci
Fri, 12 Mar 2004 20:11:31 +0000
changeset 181 96f647f568c7
parent 168 27fbd1559fb7
child 188 ad1417e74042
permissions -rw-r--r--
leda graph wrapper
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@174
    37
  typedef SmartGraph Graph;
marci@174
    38
  typedef Graph::Node Node;
marci@174
    39
  typedef Graph::EdgeIt EdgeIt;
marci@139
    40
marci@139
    41
marci@174
    42
//   Mize mize[10];
marci@174
    43
//   Mize bize[0];
marci@174
    44
//   Mize zize;
marci@174
    45
//   typedef Mize Tize[0];
marci@146
    46
marci@174
    47
//   std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
marci@174
    48
//   std::cout << sizeof(bize) << std::endl;
marci@146
    49
marci@146
    50
marci@174
    51
//   Huha<Tize> k;
marci@174
    52
//   std::cout << sizeof(k) << std::endl;
marci@139
    53
marci@174
    54
marci@174
    55
//   struct Bumm {
marci@174
    56
//     //int a;
marci@174
    57
//     bool b;
marci@174
    58
//   };
marci@174
    59
marci@174
    60
//   std::cout << sizeof(Bumm) << std::endl;
marci@174
    61
marci@174
    62
marci@174
    63
  Graph G;
marci@174
    64
  Node s, t;
marci@174
    65
  Graph::EdgeMap<int> cap(G);
marci@73
    66
  readDimacsMaxFlow(std::cin, G, s, t, cap);
marci@155
    67
marci@174
    68
//   typedef TrivGraphWrapper<Graph> TGW;
marci@174
    69
//   TGW gw(G);
marci@174
    70
//   TGW::NodeIt sw;
marci@174
    71
//   gw./*getF*/first(sw);
marci@174
    72
//   std::cout << "p1:" << gw.nodeNum() << std::endl;
marci@174
    73
//   gw.erase(sw);
marci@174
    74
//   std::cout << "p2:" << gw.nodeNum() << std::endl;
marci@174
    75
marci@174
    76
//   typedef const Graph cLG;
marci@174
    77
//   typedef TrivGraphWrapper<const cLG> CTGW;
marci@174
    78
//   CTGW cgw(G);
marci@174
    79
//   CTGW::NodeIt csw;
marci@174
    80
//   cgw./*getF*/first(csw);
marci@174
    81
//   std::cout << "p1:" << cgw.nodeNum() << std::endl;
marci@174
    82
//   //cgw.erase(csw);
marci@174
    83
//   std::cout << "p2:" << cgw.nodeNum() << std::endl;
marci@174
    84
marci@73
    85
marci@133
    86
  {
marci@174
    87
    std::cout << "SmartGraph..." << std::endl;
marci@174
    88
    std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
marci@174
    89
    Graph::EdgeMap<int> flow(G); //0 flow
marci@73
    90
marci@174
    91
    Timer ts;
marci@174
    92
    ts.reset();
marci@174
    93
marci@174
    94
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
    95
    //max_flow_test.augmentWithBlockingFlow<Graph>();
marci@174
    96
    int i=0;
marci@174
    97
    while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { 
marci@174
    98
//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@168
    99
//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@168
   100
//     }
marci@168
   101
//     std::cout<<std::endl;
marci@174
   102
      ++i; 
marci@174
   103
    }
marci@168
   104
marci@174
   105
//   std::cout << "maximum flow: "<< std::endl;
marci@174
   106
//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@174
   107
//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@174
   108
//   }
marci@174
   109
//   std::cout<<std::endl;
marci@174
   110
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
   111
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   112
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@168
   113
  }
marci@168
   114
marci@168
   115
  {
marci@174
   116
    std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
marci@174
   117
    Graph::EdgeMap<int> flow(G); //0 flow
marci@168
   118
marci@174
   119
    Timer ts;
marci@174
   120
    ts.reset();
marci@174
   121
marci@174
   122
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
   123
    //max_flow_test.augmentWithBlockingFlow<Graph>();
marci@174
   124
    int i=0;
marci@174
   125
    while (max_flow_test.augmentOnBlockingFlow2()) { 
marci@174
   126
//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@168
   127
//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@168
   128
//     }
marci@168
   129
//     std::cout<<std::endl;
marci@174
   130
      ++i; 
marci@174
   131
    }
marci@133
   132
marci@174
   133
//   std::cout << "maximum flow: "<< std::endl;
marci@174
   134
//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@174
   135
//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@174
   136
//   }
marci@174
   137
//   std::cout<<std::endl;
marci@174
   138
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
   139
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   140
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@133
   141
  }
marci@133
   142
marci@133
   143
  {
marci@174
   144
    std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
marci@174
   145
    Graph::EdgeMap<int> flow(G); //0 flow
marci@133
   146
marci@174
   147
    Timer ts;
marci@174
   148
    ts.reset();
marci@174
   149
marci@174
   150
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
   151
    //max_flow_test.augmentWithBlockingFlow<Graph>();
marci@174
   152
    int i=0;
marci@174
   153
    while (max_flow_test.augmentOnShortestPath()) { 
marci@174
   154
//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@168
   155
//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@168
   156
//     }
marci@168
   157
//     std::cout<<std::endl;
marci@174
   158
      ++i; 
marci@174
   159
    }
marci@174
   160
marci@174
   161
//   std::cout << "maximum flow: "<< std::endl;
marci@174
   162
//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@174
   163
//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@174
   164
//   }
marci@174
   165
//   std::cout<<std::endl;
marci@174
   166
    std::cout << "elapsed time: " << ts << std::endl;
marci@174
   167
    std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   168
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@168
   169
  }
marci@133
   170
marci@73
   171
marci@73
   172
  return 0;
marci@73
   173
}