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