src/work/marci/lg_vs_sg.cc
author alpar
Sun, 21 Mar 2004 14:59:51 +0000
changeset 224 5bc1c83257f8
child 334 63703ea7d02f
permissions -rw-r--r--
Some doc added
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@174
    10
#include <time_measure.h>
marci@174
    11
#include <graph_wrapper.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@174
    28
    Graph G;
marci@174
    29
    Node s, t;
marci@174
    30
    Graph::EdgeMap<int> cap(G);
marci@174
    31
    std::ifstream ins(in.c_str());
marci@174
    32
    readDimacsMaxFlow(ins, G, s, t, cap);
marci@174
    33
marci@174
    34
    {
marci@174
    35
      std::cout << "ListGraph..." << std::endl;
marci@174
    36
      std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
marci@174
    37
      Graph::EdgeMap<int> flow(G); //0 flow
marci@174
    38
marci@174
    39
      Timer ts;
marci@174
    40
      ts.reset();
marci@174
    41
marci@174
    42
      MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
    43
      int i=0;
marci@174
    44
      while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174
    45
marci@174
    46
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
    47
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
    48
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174
    49
    }
marci@174
    50
marci@174
    51
    {
marci@174
    52
      std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
marci@174
    53
      Graph::EdgeMap<int> flow(G); //0 flow
marci@174
    54
marci@174
    55
      Timer ts;
marci@174
    56
      ts.reset();
marci@174
    57
marci@174
    58
      MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
    59
      int i=0;
marci@174
    60
      while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@174
    61
marci@174
    62
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
    63
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
    64
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174
    65
    }
marci@174
    66
marci@174
    67
    {
marci@174
    68
      std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
marci@174
    69
      Graph::EdgeMap<int> flow(G); //0 flow
marci@174
    70
marci@174
    71
      Timer ts;
marci@174
    72
      ts.reset();
marci@174
    73
marci@174
    74
      MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
    75
      int i=0;
marci@174
    76
      while (max_flow_test.augmentOnShortestPath()) { ++i; }
marci@174
    77
marci@174
    78
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
    79
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
    80
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174
    81
    }
marci@174
    82
  }
marci@174
    83
marci@174
    84
marci@174
    85
  {
marci@174
    86
    typedef SmartGraph Graph;
marci@174
    87
    typedef Graph::Node Node;
marci@174
    88
    typedef Graph::EdgeIt EdgeIt;
marci@174
    89
marci@174
    90
    Graph G;
marci@174
    91
    Node s, t;
marci@174
    92
    Graph::EdgeMap<int> cap(G);
marci@174
    93
    std::ifstream ins(in.c_str());
marci@174
    94
    readDimacsMaxFlow(ins, G, s, t, cap);
marci@174
    95
marci@174
    96
    {
marci@174
    97
      std::cout << "SmartGraph..." << std::endl;
marci@174
    98
      std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
marci@174
    99
      Graph::EdgeMap<int> flow(G); //0 flow
marci@174
   100
marci@174
   101
      Timer ts;
marci@174
   102
      ts.reset();
marci@174
   103
marci@174
   104
      MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
   105
      int i=0;
marci@174
   106
      while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174
   107
marci@174
   108
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
   109
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   110
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174
   111
    }
marci@174
   112
marci@174
   113
    {
marci@174
   114
      std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
marci@174
   115
      Graph::EdgeMap<int> flow(G); //0 flow
marci@174
   116
marci@174
   117
      Timer ts;
marci@174
   118
      ts.reset();
marci@174
   119
marci@174
   120
      MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
   121
      int i=0;
marci@174
   122
      while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@174
   123
marci@174
   124
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
   125
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   126
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174
   127
    }
marci@174
   128
marci@174
   129
    {
marci@174
   130
      std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
marci@174
   131
      Graph::EdgeMap<int> flow(G); //0 flow
marci@174
   132
marci@174
   133
      Timer ts;
marci@174
   134
      ts.reset();
marci@174
   135
marci@174
   136
      MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174
   137
      int i=0;
marci@174
   138
      while (max_flow_test.augmentOnShortestPath()) { ++i; }
marci@174
   139
marci@174
   140
      std::cout << "elapsed time: " << ts << std::endl;
marci@174
   141
      std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174
   142
      std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174
   143
    }
marci@174
   144
  }
marci@174
   145
marci@174
   146
  return 0;
marci@174
   147
}