src/work/marci/lg_vs_sg.cc
author alpar
Mon, 26 Apr 2004 17:39:38 +0000
changeset 428 3544872b38c2
parent 334 63703ea7d02f
child 465 d72e56f1730d
permissions -rw-r--r--
time_measure.h went to src/include.
marci@174
     1
// -*- c++ -*-
marci@174
     2
#include <iostream>
marci@174
     3
#include <fstream>
marci@174
     4
#include <string>
marci@174
     5
marci@174
     6
#include <list_graph.h>
marci@174
     7
#include <smart_graph.h>
marci@174
     8
#include <dimacs.h>
marci@174
     9
#include <edmonds_karp.h>
marci@334
    10
#include <preflow.h>
marci@174
    11
#include <time_measure.h>
marci@334
    12
#include <for_each_macros.h>
marci@174
    13
marci@174
    14
using namespace hugo;
marci@174
    15
marci@174
    16
// Use a DIMACS max flow file as stdin.
marci@174
    17
// read_dimacs_demo dimacs_max_flow_file
marci@174
    18
marci@174
    19
int main(int, char** argv) {
marci@174
    20
marci@174
    21
  std::string in=argv[1];
marci@174
    22
  typedef ListGraph MutableGraph;
marci@174
    23
marci@174
    24
  {
marci@174
    25
    typedef ListGraph Graph;
marci@174
    26
    typedef Graph::Node Node;
marci@174
    27
    typedef Graph::EdgeIt EdgeIt;
marci@174
    28
marci@174
    29
    Graph G;
marci@174
    30
    Node s, t;
marci@174
    31
    Graph::EdgeMap<int> cap(G);
marci@174
    32
    std::ifstream ins(in.c_str());
marci@174
    33
    readDimacsMaxFlow(ins, G, s, t, cap);
marci@174
    34
marci@334
    35
    Timer ts;
marci@334
    36
    Graph::EdgeMap<int> flow(G); //0 flow
marci@334
    37
    Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@379
    38
      pre_flow_test(G, s, t, cap, flow, true);
marci@334
    39
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@334
    40
      max_flow_test(G, s, t, cap, flow);
marci@334
    41
marci@334
    42
    std::cout << "ListGraph ..." << std::endl;
marci@334
    43
marci@174
    44
    {
marci@334
    45
      std::cout << "preflow ..." << std::endl;
marci@334
    46
      ts.reset();
marci@334
    47
      pre_flow_test.run();
marci@334
    48
      std::cout << "elapsed time: " << ts << std::endl;
marci@334
    49
      std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
marci@334
    50
    }
marci@174
    51
marci@334
    52
    {
marci@334
    53
      std::cout << "physical blocking flow augmentation ..." << std::endl;
marci@334
    54
      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@174
    55
      ts.reset();
marci@174
    56
      int i=0;
marci@174
    57
      while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174
    58
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
    59
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
    60
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174
    61
    }
marci@174
    62
marci@174
    63
    {
marci@334
    64
      std::cout << "faster physical blocking flow augmentation ..." << std::endl;
marci@334
    65
      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@174
    66
      ts.reset();
marci@174
    67
      int i=0;
marci@334
    68
      while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
marci@174
    69
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
    70
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
    71
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174
    72
    }
marci@174
    73
marci@174
    74
    {
marci@334
    75
      std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
marci@334
    76
      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@334
    77
      ts.reset();
marci@334
    78
      int i=0;
marci@334
    79
      while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@334
    80
      std::cout << "elapsed time: " << ts << std::endl;
marci@334
    81
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@334
    82
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@334
    83
    }
marci@174
    84
marci@334
    85
    {
marci@334
    86
      std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
marci@334
    87
      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@174
    88
      ts.reset();
marci@174
    89
      int i=0;
marci@174
    90
      while (max_flow_test.augmentOnShortestPath()) { ++i; }
marci@174
    91
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
    92
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
    93
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174
    94
    }
marci@174
    95
  }
marci@174
    96
marci@174
    97
marci@174
    98
  {
marci@174
    99
    typedef SmartGraph Graph;
marci@174
   100
    typedef Graph::Node Node;
marci@174
   101
    typedef Graph::EdgeIt EdgeIt;
marci@174
   102
marci@174
   103
    Graph G;
marci@174
   104
    Node s, t;
marci@174
   105
    Graph::EdgeMap<int> cap(G);
marci@174
   106
    std::ifstream ins(in.c_str());
marci@174
   107
    readDimacsMaxFlow(ins, G, s, t, cap);
marci@174
   108
marci@334
   109
    Timer ts;
marci@334
   110
    Graph::EdgeMap<int> flow(G); //0 flow
marci@334
   111
    Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@379
   112
      pre_flow_test(G, s, t, cap, flow, true);
marci@334
   113
    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@334
   114
      max_flow_test(G, s, t, cap, flow);
marci@334
   115
marci@334
   116
    std::cout << "SmatrGraph ..." << std::endl;
marci@334
   117
marci@174
   118
    {
marci@334
   119
      std::cout << "preflow ..." << std::endl;
marci@334
   120
      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@334
   121
      ts.reset();
marci@334
   122
      pre_flow_test.run();
marci@334
   123
      std::cout << "elapsed time: " << ts << std::endl;
marci@334
   124
      std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
marci@334
   125
    }
marci@174
   126
marci@334
   127
    {
marci@334
   128
      std::cout << "physical blocking flow augmentation ..." << std::endl;
marci@334
   129
      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@174
   130
      ts.reset();
marci@174
   131
      int i=0;
marci@174
   132
      while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174
   133
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
   134
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   135
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174
   136
    }
marci@174
   137
marci@174
   138
    {
marci@334
   139
      std::cout << "faster physical blocking flow augmentation ..." << std::endl;
marci@334
   140
      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@174
   141
      ts.reset();
marci@174
   142
      int i=0;
marci@334
   143
      while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
marci@174
   144
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
   145
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   146
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174
   147
    }
marci@174
   148
marci@174
   149
    {
marci@334
   150
      std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
marci@334
   151
      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@334
   152
      ts.reset();
marci@334
   153
      int i=0;
marci@334
   154
      while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@334
   155
      std::cout << "elapsed time: " << ts << std::endl;
marci@334
   156
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@334
   157
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@334
   158
    }
marci@174
   159
marci@334
   160
    {
marci@334
   161
      std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
marci@334
   162
      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
marci@174
   163
      ts.reset();
marci@174
   164
      int i=0;
marci@174
   165
      while (max_flow_test.augmentOnShortestPath()) { ++i; }
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@174
   169
    }
marci@174
   170
  }
marci@174
   171
marci@334
   172
marci@334
   173
marci@334
   174
marci@174
   175
  return 0;
marci@174
   176
}