src/work/marci/lg_vs_sg_vs_sg.cc
author athos
Wed, 23 Mar 2005 10:35:36 +0000
changeset 1246 925002e098e7
parent 777 a82713ed19f3
permissions -rw-r--r--
Csak a te kedvedert.
marci@174
     1
// -*- c++ -*-
marci@174
     2
#include <iostream>
marci@174
     3
#include <fstream>
marci@174
     4
#include <string>
marci@174
     5
marci@642
     6
#include <sage_graph.h>
alpar@921
     7
#include <lemon/list_graph.h>
alpar@921
     8
#include <lemon/smart_graph.h>
alpar@921
     9
#include <lemon/dimacs.h>
alpar@921
    10
#include <lemon/max_flow.h>
marci@762
    11
#include <augmenting_flow.h>
alpar@921
    12
#include <lemon/time_measure.h>
marci@762
    13
#include <for_each_macros.h>
marci@174
    14
alpar@921
    15
using namespace lemon;
marci@174
    16
marci@174
    17
// Use a DIMACS max flow file as stdin.
marci@174
    18
// read_dimacs_demo dimacs_max_flow_file
marci@174
    19
marci@174
    20
int main(int, char** argv) {
marci@174
    21
marci@174
    22
  std::string in=argv[1];
marci@642
    23
  typedef SageGraph MutableGraph;
marci@174
    24
marci@174
    25
  {
marci@642
    26
    typedef SageGraph Graph;
marci@174
    27
    typedef Graph::Node Node;
marci@174
    28
    typedef Graph::EdgeIt EdgeIt;
marci@174
    29
marci@577
    30
    Graph g;
marci@174
    31
    Node s, t;
marci@577
    32
    Graph::EdgeMap<int> cap(g);
marci@174
    33
    std::ifstream ins(in.c_str());
marci@577
    34
    //readDimacsMaxFlow(ins, g, s, t, cap);
marci@577
    35
    readDimacs(ins, g, cap, s, t);
marci@174
    36
marci@334
    37
    Timer ts;
marci@577
    38
    Graph::EdgeMap<int> flow(g); //0 flow
marci@334
    39
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@577
    40
      max_flow_test(g, s, t, cap, flow/*, true*/);
marci@762
    41
    AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@762
    42
      augmenting_flow_test(g, s, t, cap, flow/*, true*/);
marci@334
    43
marci@642
    44
    std::cout << "SageGraph ..." << std::endl;
marci@334
    45
marci@174
    46
    {
marci@334
    47
      std::cout << "preflow ..." << std::endl;
marci@334
    48
      ts.reset();
marci@476
    49
      max_flow_test.run();
marci@334
    50
      std::cout << "elapsed time: " << ts << std::endl;
marci@476
    51
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@334
    52
    }
marci@174
    53
marci@334
    54
    {
marci@334
    55
      std::cout << "physical blocking flow augmentation ..." << std::endl;
marci@777
    56
      for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@174
    57
      ts.reset();
marci@174
    58
      int i=0;
marci@762
    59
      while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174
    60
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
    61
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762
    62
      std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@174
    63
    }
marci@174
    64
marci@476
    65
//     {
marci@476
    66
//       std::cout << "faster physical blocking flow augmentation ..." << std::endl;
marci@577
    67
//       FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
marci@476
    68
//       ts.reset();
marci@476
    69
//       int i=0;
marci@476
    70
//       while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
marci@476
    71
//       std::cout << "elapsed time: " << ts << std::endl;
marci@476
    72
//       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@476
    73
//       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@476
    74
//     }
marci@174
    75
marci@174
    76
    {
marci@334
    77
      std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
marci@777
    78
      for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@334
    79
      ts.reset();
marci@334
    80
      int i=0;
marci@762
    81
      while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@334
    82
      std::cout << "elapsed time: " << ts << std::endl;
marci@334
    83
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762
    84
      std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@334
    85
    }
marci@174
    86
marci@334
    87
    {
marci@334
    88
      std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
marci@777
    89
      for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@174
    90
      ts.reset();
marci@174
    91
      int i=0;
marci@762
    92
      while (augmenting_flow_test.augmentOnShortestPath()) { ++i; }
marci@174
    93
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
    94
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762
    95
      std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@174
    96
    }
marci@174
    97
  }
marci@174
    98
marci@174
    99
  {
marci@174
   100
    typedef SmartGraph Graph;
marci@174
   101
    typedef Graph::Node Node;
marci@174
   102
    typedef Graph::EdgeIt EdgeIt;
marci@174
   103
marci@577
   104
    Graph g;
marci@174
   105
    Node s, t;
marci@577
   106
    Graph::EdgeMap<int> cap(g);
marci@174
   107
    std::ifstream ins(in.c_str());
marci@577
   108
    //readDimacsMaxFlow(ins, g, s, t, cap);
marci@577
   109
    readDimacs(ins, g, cap, s, t);
marci@174
   110
marci@334
   111
    Timer ts;
marci@577
   112
    Graph::EdgeMap<int> flow(g); //0 flow
marci@334
   113
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@577
   114
      max_flow_test(g, s, t, cap, flow/*, true*/);
marci@762
   115
    AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@762
   116
      augmenting_flow_test(g, s, t, cap, flow/*, true*/);
marci@476
   117
    //    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@577
   118
    //  max_flow_test(g, s, t, cap, flow);
marci@334
   119
marci@642
   120
    std::cout << "SmartGraph ..." << std::endl;
marci@334
   121
marci@174
   122
    {
marci@334
   123
      std::cout << "preflow ..." << std::endl;
marci@777
   124
      for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@334
   125
      ts.reset();
marci@476
   126
      max_flow_test.run();
marci@334
   127
      std::cout << "elapsed time: " << ts << std::endl;
marci@476
   128
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@334
   129
    }
marci@174
   130
marci@334
   131
    {
marci@334
   132
      std::cout << "physical blocking flow augmentation ..." << std::endl;
marci@777
   133
      for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@174
   134
      ts.reset();
marci@174
   135
      int i=0;
marci@762
   136
      while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174
   137
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
   138
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762
   139
      std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@174
   140
    }
marci@174
   141
marci@476
   142
//     {
marci@476
   143
//       std::cout << "faster physical blocking flow augmentation ..." << std::endl;
marci@577
   144
//       FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
marci@476
   145
//       ts.reset();
marci@476
   146
//       int i=0;
marci@476
   147
//       while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
marci@476
   148
//       std::cout << "elapsed time: " << ts << std::endl;
marci@476
   149
//       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@476
   150
//       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@476
   151
//     }
marci@174
   152
marci@174
   153
    {
marci@334
   154
      std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
marci@777
   155
      for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@334
   156
      ts.reset();
marci@334
   157
      int i=0;
marci@762
   158
      while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@334
   159
      std::cout << "elapsed time: " << ts << std::endl;
marci@334
   160
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762
   161
      std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@334
   162
    }
marci@174
   163
marci@334
   164
    {
marci@334
   165
      std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
marci@777
   166
      for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@174
   167
      ts.reset();
marci@174
   168
      int i=0;
marci@762
   169
      while (augmenting_flow_test.augmentOnShortestPath()) { ++i; }
marci@174
   170
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
   171
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762
   172
      std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@174
   173
    }
marci@174
   174
  }
marci@174
   175
marci@642
   176
  {
marci@642
   177
    typedef ListGraph Graph;
marci@642
   178
    typedef Graph::Node Node;
marci@642
   179
    typedef Graph::EdgeIt EdgeIt;
marci@642
   180
marci@642
   181
    Graph g;
marci@642
   182
    Node s, t;
marci@642
   183
    Graph::EdgeMap<int> cap(g);
marci@642
   184
    std::ifstream ins(in.c_str());
marci@642
   185
    //readDimacsMaxFlow(ins, g, s, t, cap);
marci@642
   186
    readDimacs(ins, g, cap, s, t);
marci@642
   187
marci@642
   188
    Timer ts;
marci@642
   189
    Graph::EdgeMap<int> flow(g); //0 flow
marci@642
   190
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@642
   191
      max_flow_test(g, s, t, cap, flow/*, true*/);
marci@762
   192
    AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@762
   193
      augmenting_flow_test(g, s, t, cap, flow/*, true*/);
marci@642
   194
    //    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@642
   195
    //  max_flow_test(g, s, t, cap, flow);
marci@642
   196
marci@642
   197
    std::cout << "ListGraph ..." << std::endl;
marci@642
   198
marci@642
   199
    {
marci@642
   200
      std::cout << "preflow ..." << std::endl;
marci@777
   201
      for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@642
   202
      ts.reset();
marci@642
   203
      max_flow_test.run();
marci@642
   204
      std::cout << "elapsed time: " << ts << std::endl;
marci@642
   205
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@642
   206
    }
marci@642
   207
marci@642
   208
    {
marci@642
   209
      std::cout << "physical blocking flow augmentation ..." << std::endl;
marci@777
   210
      for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@642
   211
      ts.reset();
marci@642
   212
      int i=0;
marci@762
   213
      while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@642
   214
      std::cout << "elapsed time: " << ts << std::endl;
marci@642
   215
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762
   216
      std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@642
   217
    }
marci@642
   218
marci@642
   219
//     {
marci@642
   220
//       std::cout << "faster physical blocking flow augmentation ..." << std::endl;
marci@642
   221
//       FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
marci@642
   222
//       ts.reset();
marci@642
   223
//       int i=0;
marci@642
   224
//       while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
marci@642
   225
//       std::cout << "elapsed time: " << ts << std::endl;
marci@642
   226
//       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@642
   227
//       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@642
   228
//     }
marci@642
   229
marci@642
   230
    {
marci@642
   231
      std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
marci@777
   232
      for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@642
   233
      ts.reset();
marci@642
   234
      int i=0;
marci@762
   235
      while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@642
   236
      std::cout << "elapsed time: " << ts << std::endl;
marci@642
   237
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762
   238
      std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@642
   239
    }
marci@642
   240
marci@642
   241
    {
marci@642
   242
      std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
marci@777
   243
      for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@642
   244
      ts.reset();
marci@642
   245
      int i=0;
marci@762
   246
      while (augmenting_flow_test.augmentOnShortestPath()) { ++i; }
marci@642
   247
      std::cout << "elapsed time: " << ts << std::endl;
marci@642
   248
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762
   249
      std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@642
   250
    }
marci@642
   251
  }
marci@642
   252
marci@174
   253
  return 0;
marci@174
   254
}