src/work/jacint/preflow_hl2.cc
author jacint
Mon, 01 Mar 2004 17:24:34 +0000
changeset 142 01d47457aff3
permissions -rw-r--r--
nagytakaritas
jacint@109
     1
#include <iostream>
jacint@109
     2
#include <fstream>
jacint@109
     3
jacint@109
     4
#include <list_graph.hh>
jacint@109
     5
#include <dimacs.hh>
jacint@109
     6
#include <preflow_hl2.h>
jacint@109
     7
#include <time_measure.h>
jacint@109
     8
jacint@109
     9
using namespace hugo;
jacint@109
    10
jacint@109
    11
// Use a DIMACS max flow file as stdin.
jacint@109
    12
// read_dimacs_demo < dimacs_max_flow_file
jacint@109
    13
int main(int, char **) {
jacint@109
    14
  typedef ListGraph::NodeIt NodeIt;
jacint@109
    15
  typedef ListGraph::EachEdgeIt EachEdgeIt;
jacint@109
    16
jacint@109
    17
  ListGraph G;
jacint@109
    18
  NodeIt s, t;
jacint@109
    19
  ListGraph::EdgeMap<int> cap(G);
jacint@109
    20
  readDimacsMaxFlow(std::cin, G, s, t, cap);
jacint@109
    21
jacint@109
    22
  std::cout << "preflow_hl2 demo ..." << std::endl;
jacint@109
    23
  
jacint@109
    24
  double mintime=1000000;
jacint@109
    25
jacint@109
    26
  for ( int i=1; i!=11; ++i ) {
jacint@109
    27
    double pre_time=currTime();
jacint@109
    28
    preflow_hl2<ListGraph, int> max_flow_test(G, s, t, cap);
jacint@109
    29
    double post_time=currTime();
jacint@109
    30
    if ( mintime > post_time-pre_time ) mintime = post_time-pre_time;
jacint@109
    31
  }
jacint@109
    32
jacint@109
    33
  preflow_hl2<ListGraph, int> max_flow_test(G, s, t, cap);
jacint@109
    34
    
jacint@109
    35
  ListGraph::NodeMap<bool> cut(G);
jacint@109
    36
  max_flow_test.minCut(cut); 
jacint@109
    37
  int min_cut_value=0;
jacint@109
    38
  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
jacint@109
    39
    if (cut.get(G.tail(e)) && !cut.get(G.head(e))) min_cut_value+=cap.get(e);
jacint@109
    40
  }
jacint@109
    41
jacint@109
    42
  ListGraph::NodeMap<bool> cut1(G);
jacint@109
    43
  max_flow_test.minMinCut(cut1); 
jacint@109
    44
  int min_min_cut_value=0;
jacint@109
    45
  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
jacint@109
    46
    if (cut.get(G.tail(e)) && !cut.get(G.head(e))) 
jacint@109
    47
      min_min_cut_value+=cap.get(e);
jacint@109
    48
  }
jacint@109
    49
jacint@109
    50
  ListGraph::NodeMap<bool> cut2(G);
jacint@109
    51
  max_flow_test.maxMinCut(cut2); 
jacint@109
    52
  int max_min_cut_value=0;
jacint@109
    53
  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
jacint@109
    54
    if (cut2.get(G.tail(e)) && !cut2.get(G.head(e))) 
jacint@109
    55
      max_min_cut_value+=cap.get(e);
jacint@109
    56
  }
jacint@109
    57
  
jacint@109
    58
  std::cout << "min time of 10 runs: " << mintime << " sec"<< std::endl; 
jacint@109
    59
  std::cout << "flow value: "<< max_flow_test.maxFlow() << std::endl;
jacint@109
    60
  std::cout << "min cut value: "<< min_cut_value << std::endl;
jacint@109
    61
  std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
jacint@109
    62
  std::cout << "max min cut value: "<< max_min_cut_value << std::endl;
jacint@109
    63
jacint@109
    64
  return 0;
jacint@109
    65
}