src/work/jacint/preflow.cc
author jacint
Sat, 20 Mar 2004 20:06:23 +0000
changeset 220 7deda4d6a07a
parent 211 9222a9b8b323
child 372 e6a156fc186d
permissions -rw-r--r--
*** empty log message ***
jacint@109
     1
#include <iostream>
jacint@109
     2
#include <fstream>
jacint@109
     3
jacint@220
     4
#include <smart_graph.h>
jacint@211
     5
#include <list_graph.h>
jacint@211
     6
#include <dimacs.h>
jacint@109
     7
#include <preflow.h>
jacint@109
     8
#include <time_measure.h>
jacint@109
     9
jacint@109
    10
using namespace hugo;
jacint@109
    11
jacint@109
    12
// Use a DIMACS max flow file as stdin.
jacint@109
    13
// read_dimacs_demo < dimacs_max_flow_file
jacint@109
    14
int main(int, char **) {
jacint@220
    15
  typedef SmartGraph::Node Node;
jacint@220
    16
  typedef SmartGraph::EdgeIt EdgeIt;
jacint@109
    17
jacint@220
    18
  SmartGraph G;
jacint@211
    19
  Node s, t;
jacint@220
    20
  SmartGraph::EdgeMap<int> cap(G);
jacint@109
    21
  readDimacsMaxFlow(std::cin, G, s, t, cap);
jacint@109
    22
jacint@109
    23
  std::cout << "preflow demo ..." << std::endl;
jacint@109
    24
  
jacint@109
    25
  double mintime=1000000;
jacint@109
    26
jacint@109
    27
  for ( int i=1; i!=11; ++i ) {
jacint@220
    28
    SmartGraph::EdgeMap<int> flow(G);
jacint@109
    29
    double pre_time=currTime();
jacint@220
    30
    Preflow<SmartGraph, int> max_flow_test(G, s, t, cap, flow);
jacint@211
    31
    max_flow_test.run();
jacint@109
    32
    double post_time=currTime();
jacint@109
    33
    if ( mintime > post_time-pre_time ) mintime = post_time-pre_time;
jacint@109
    34
  }
jacint@109
    35
jacint@220
    36
  SmartGraph::EdgeMap<int> flow(G);
jacint@220
    37
  Preflow<SmartGraph, int> max_flow_test(G, s, t, cap, flow);
jacint@211
    38
  max_flow_test.run();
jacint@211
    39
  
jacint@220
    40
  SmartGraph::NodeMap<bool> cut(G);
jacint@109
    41
  max_flow_test.minCut(cut); 
jacint@109
    42
  int min_cut_value=0;
jacint@211
    43
  EdgeIt e;
jacint@211
    44
  for(G.first(e); G.valid(e); G.next(e)) {
jacint@220
    45
    if (cut[G.tail(e)] && !cut[G.head(e)]) min_cut_value+=cap[e];
jacint@109
    46
  }
jacint@109
    47
jacint@220
    48
  SmartGraph::NodeMap<bool> cut1(G);
jacint@109
    49
  max_flow_test.minMinCut(cut1); 
jacint@109
    50
  int min_min_cut_value=0;
jacint@211
    51
  for(G.first(e); G.valid(e); G.next(e)) {
jacint@220
    52
    if (cut[G.tail(e)] && !cut[G.head(e)]) 
jacint@220
    53
      min_min_cut_value+=cap[e];
jacint@109
    54
  }
jacint@109
    55
jacint@220
    56
  SmartGraph::NodeMap<bool> cut2(G);
jacint@109
    57
  max_flow_test.maxMinCut(cut2); 
jacint@109
    58
  int max_min_cut_value=0;
jacint@211
    59
  for(G.first(e); G.valid(e); G.next(e)) {
jacint@220
    60
    if (cut2[G.tail(e)] && !cut2[G.head(e)]) 
jacint@220
    61
      max_min_cut_value+=cap[e];
jacint@109
    62
      }
jacint@109
    63
  
jacint@109
    64
  std::cout << "min time of 10 runs: " << mintime << " sec"<< std::endl; 
jacint@211
    65
  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
jacint@109
    66
  std::cout << "min cut value: "<< min_cut_value << std::endl;
jacint@109
    67
  std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
jacint@109
    68
  std::cout << "max min cut value: "<< max_min_cut_value << 
jacint@109
    69
    std::endl<< std::endl;
jacint@109
    70
  
jacint@109
    71
  return 0;
jacint@109
    72
}