src/work/jacint/preflow_hl4.cc
author klao
Thu, 26 Feb 2004 16:07:40 +0000
changeset 132 1ac27e476e25
permissions -rw-r--r--
makefile: tobb include konyvtar, jobb depend keszites
flow_test.cc: torolve, mert a depend-et megakasztja, igy gondolom nem is fordul
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_hl4.h>
jacint@109
     7
#include <time_measure.h>
jacint@109
     8
jacint@109
     9
using namespace hugo;
jacint@109
    10
jacint@109
    11
//Note, that preflow_hl4.h has a member NodeMap<bool> cut, 
jacint@109
    12
//the construction of which slowing the running time by 1-10%.
jacint@109
    13
jacint@109
    14
// Use a DIMACS max flow file as stdin.
jacint@109
    15
// read_dimacs_demo < dimacs_max_flow_file
jacint@109
    16
int main(int, char **) {
jacint@109
    17
  typedef ListGraph::NodeIt NodeIt;
jacint@109
    18
  typedef ListGraph::EachEdgeIt EachEdgeIt;
jacint@109
    19
jacint@109
    20
  ListGraph G;
jacint@109
    21
  NodeIt s, t;
jacint@109
    22
  ListGraph::EdgeMap<int> cap(G);
jacint@109
    23
  readDimacsMaxFlow(std::cin, G, s, t, cap);
jacint@109
    24
jacint@109
    25
  std::cout << "preflow_hl4 demo ..." << std::endl;
jacint@109
    26
  
jacint@109
    27
  double mintime=1000000;
jacint@109
    28
jacint@109
    29
  for ( int i=1; i!=11; ++i ) {
jacint@109
    30
    double pre_time=currTime();
jacint@109
    31
    preflow_hl4<ListGraph, int> max_flow_test(G, s, t, cap);
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@109
    36
  double pre_time=currTime();
jacint@109
    37
  preflow_hl4<ListGraph, int> max_flow_test(G, s, t, cap);
jacint@109
    38
  double post_time=currTime();
jacint@109
    39
     
jacint@109
    40
  ListGraph::NodeMap<bool> cut(G);
jacint@109
    41
  max_flow_test.minCut(cut); 
jacint@109
    42
  int min_cut_value=0;
jacint@109
    43
  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
jacint@109
    44
    if (cut.get(G.tail(e)) && !cut.get(G.head(e))) min_cut_value+=cap.get(e);
jacint@109
    45
  }
jacint@109
    46
jacint@109
    47
  ListGraph::NodeMap<bool> cut1(G);
jacint@109
    48
  max_flow_test.minMinCut(cut1); 
jacint@109
    49
  int min_min_cut_value=0;
jacint@109
    50
  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
jacint@109
    51
    if (cut.get(G.tail(e)) && !cut.get(G.head(e))) 
jacint@109
    52
      min_min_cut_value+=cap.get(e);
jacint@109
    53
  }
jacint@109
    54
jacint@109
    55
  ListGraph::NodeMap<bool> cut2(G);
jacint@109
    56
  max_flow_test.maxMinCut(cut2); 
jacint@109
    57
  int max_min_cut_value=0;
jacint@109
    58
  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
jacint@109
    59
    if (cut2.get(G.tail(e)) && !cut2.get(G.head(e))) 
jacint@109
    60
      max_min_cut_value+=cap.get(e);
jacint@109
    61
  }
jacint@109
    62
  
jacint@109
    63
  std::cout << "min time of 10 runs: " << mintime << " sec"<< std::endl; 
jacint@109
    64
  std::cout << "phase 0: " << max_flow_test.time-pre_time 
jacint@109
    65
	    << " sec"<< std::endl; 
jacint@109
    66
  std::cout << "phase 1: " << post_time-max_flow_test.time 
jacint@109
    67
	    << " sec"<< std::endl; 
jacint@109
    68
  std::cout << "flow value: "<< max_flow_test.maxFlow() << std::endl;
jacint@109
    69
  std::cout << "min cut value: "<< min_cut_value << std::endl;
jacint@109
    70
  std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
jacint@109
    71
  std::cout << "max min cut value: "<< max_min_cut_value << 
jacint@109
    72
    std::endl<< std::endl;
jacint@109
    73
jacint@109
    74
  
jacint@109
    75
  return 0;
jacint@109
    76
}