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