src/work/jacint/preflow.cc
author alpar
Sat, 20 Mar 2004 16:13:19 +0000
changeset 217 fc549fac0dd0
parent 113 cf7b01232d86
child 220 7deda4d6a07a
permissions -rw-r--r--
Several bugfixes
jacint@109
     1
#include <iostream>
jacint@109
     2
#include <fstream>
jacint@109
     3
jacint@211
     4
#include <list_graph.h>
jacint@211
     5
#include <dimacs.h>
jacint@109
     6
#include <preflow.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@211
    14
  typedef ListGraph::Node Node;
jacint@211
    15
  typedef ListGraph::EdgeIt EdgeIt;
jacint@109
    16
jacint@109
    17
  ListGraph G;
jacint@211
    18
  Node 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 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@211
    27
    ListGraph::EdgeMap<int> flow(G);
jacint@109
    28
    double pre_time=currTime();
jacint@211
    29
    Preflow<ListGraph, int> max_flow_test(G, s, t, cap, flow);
jacint@211
    30
    max_flow_test.run();
jacint@109
    31
    double post_time=currTime();
jacint@109
    32
    if ( mintime > post_time-pre_time ) mintime = post_time-pre_time;
jacint@109
    33
  }
jacint@109
    34
jacint@211
    35
  ListGraph::EdgeMap<int> flow(G);
jacint@211
    36
  Preflow<ListGraph, int> max_flow_test(G, s, t, cap, flow);
jacint@211
    37
  max_flow_test.run();
jacint@211
    38
  
jacint@109
    39
  ListGraph::NodeMap<bool> cut(G);
jacint@109
    40
  max_flow_test.minCut(cut); 
jacint@109
    41
  int min_cut_value=0;
jacint@211
    42
  EdgeIt e;
jacint@211
    43
  for(G.first(e); G.valid(e); G.next(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@211
    50
  for(G.first(e); G.valid(e); G.next(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@211
    58
  for(G.first(e); G.valid(e); G.next(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@211
    64
  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
jacint@109
    65
  std::cout << "min cut value: "<< min_cut_value << std::endl;
jacint@109
    66
  std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
jacint@109
    67
  std::cout << "max min cut value: "<< max_min_cut_value << 
jacint@109
    68
    std::endl<< std::endl;
jacint@109
    69
  
jacint@109
    70
  return 0;
jacint@109
    71
}