src/work/jacint/preflow_hl1.cc
author marci
Mon, 01 Mar 2004 12:06:56 +0000
changeset 138 c6297c121409
permissions -rw-r--r--
.
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_hl1.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_hl1 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_hl1<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
  double pre_time=currTime();
jacint@109
    34
  preflow_hl1<ListGraph, int> max_flow_test(G, s, t, cap);
jacint@109
    35
  double post_time=currTime();
jacint@109
    36
     
jacint@109
    37
  ListGraph::NodeMap<bool> cut(G);
jacint@109
    38
  max_flow_test.minCut(cut); 
jacint@109
    39
  int min_cut_value=0;
jacint@109
    40
  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
jacint@109
    41
    if (cut.get(G.tail(e)) && !cut.get(G.head(e))) min_cut_value+=cap.get(e);
jacint@109
    42
  }
jacint@109
    43
jacint@109
    44
  ListGraph::NodeMap<bool> cut1(G);
jacint@109
    45
  max_flow_test.minMinCut(cut1); 
jacint@109
    46
  int min_min_cut_value=0;
jacint@109
    47
  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
jacint@109
    48
    if (cut.get(G.tail(e)) && !cut.get(G.head(e))) 
jacint@109
    49
      min_min_cut_value+=cap.get(e);
jacint@109
    50
  }
jacint@109
    51
jacint@109
    52
  ListGraph::NodeMap<bool> cut2(G);
jacint@109
    53
  max_flow_test.maxMinCut(cut2); 
jacint@109
    54
  int max_min_cut_value=0;
jacint@109
    55
  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
jacint@109
    56
    if (cut2.get(G.tail(e)) && !cut2.get(G.head(e))) 
jacint@109
    57
      max_min_cut_value+=cap.get(e);
jacint@109
    58
  }
jacint@109
    59
  
jacint@109
    60
  std::cout << "min time of 10 runs: " << mintime << " sec"<< std::endl; 
jacint@109
    61
  std::cout << "phase 0: " << max_flow_test.time-pre_time 
jacint@109
    62
	    << " sec"<< std::endl; 
jacint@109
    63
  std::cout << "phase 1: " << post_time-max_flow_test.time 
jacint@109
    64
	    << " sec"<< std::endl; 
jacint@109
    65
  std::cout << "flow value: "<< max_flow_test.maxFlow() << 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
  
jacint@109
    72
  return 0;
jacint@109
    73
}