src/work/jacint/preflow.cc
author jacint
Thu, 22 Apr 2004 14:11:28 +0000
changeset 372 e6a156fc186d
parent 220 7deda4d6a07a
child 374 0fc9cd9b854a
permissions -rw-r--r--
(none)
jacint@109
     1
#include <iostream>
jacint@109
     2
jacint@220
     3
#include <smart_graph.h>
jacint@211
     4
#include <list_graph.h>
jacint@211
     5
#include <dimacs.h>
jacint@372
     6
#include <preflowproba.h>
jacint@109
     7
#include <time_measure.h>
jacint@109
     8
jacint@109
     9
using namespace hugo;
jacint@109
    10
jacint@109
    11
int main(int, char **) {
jacint@372
    12
 
jacint@372
    13
  typedef SmartGraph Graph;
jacint@372
    14
  
jacint@372
    15
  typedef Graph::Node Node;
jacint@372
    16
  typedef Graph::EdgeIt EdgeIt;
jacint@109
    17
jacint@372
    18
  Graph G;
jacint@211
    19
  Node s, t;
jacint@372
    20
  Graph::EdgeMap<int> cap(G);
jacint@109
    21
  readDimacsMaxFlow(std::cin, G, s, t, cap);
jacint@372
    22
  Timer ts;
jacint@372
    23
  
jacint@109
    24
  std::cout << "preflow demo ..." << std::endl;
jacint@109
    25
  
jacint@372
    26
  Graph::EdgeMap<int> flow(G);
jacint@372
    27
  Preflow<Graph, int> max_flow_test(G, s, t, cap, flow, 1);
jacint@372
    28
  ts.reset();
jacint@211
    29
  max_flow_test.run();
jacint@372
    30
  std::cout << "elapsed time: " << ts << std::endl;
jacint@211
    31
  
jacint@372
    32
  Graph::NodeMap<bool> cut(G);
jacint@109
    33
  max_flow_test.minCut(cut); 
jacint@109
    34
  int min_cut_value=0;
jacint@211
    35
  EdgeIt e;
jacint@211
    36
  for(G.first(e); G.valid(e); G.next(e)) {
jacint@220
    37
    if (cut[G.tail(e)] && !cut[G.head(e)]) min_cut_value+=cap[e];
jacint@109
    38
  }
jacint@109
    39
jacint@372
    40
  Graph::NodeMap<bool> cut1(G);
jacint@109
    41
  max_flow_test.minMinCut(cut1); 
jacint@109
    42
  int min_min_cut_value=0;
jacint@211
    43
  for(G.first(e); G.valid(e); G.next(e)) {
jacint@220
    44
    if (cut[G.tail(e)] && !cut[G.head(e)]) 
jacint@220
    45
      min_min_cut_value+=cap[e];
jacint@109
    46
  }
jacint@109
    47
jacint@372
    48
  Graph::NodeMap<bool> cut2(G);
jacint@109
    49
  max_flow_test.maxMinCut(cut2); 
jacint@109
    50
  int max_min_cut_value=0;
jacint@211
    51
  for(G.first(e); G.valid(e); G.next(e)) {
jacint@220
    52
    if (cut2[G.tail(e)] && !cut2[G.head(e)]) 
jacint@220
    53
      max_min_cut_value+=cap[e];
jacint@109
    54
      }
jacint@109
    55
  
jacint@211
    56
  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
jacint@109
    57
  std::cout << "min cut value: "<< min_cut_value << std::endl;
jacint@109
    58
  std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
jacint@109
    59
  std::cout << "max min cut value: "<< max_min_cut_value << 
jacint@109
    60
    std::endl<< std::endl;
jacint@109
    61
  
jacint@109
    62
  return 0;
jacint@109
    63
}