src/work/jacint/preflow.cc
author alpar
Sat, 17 Apr 2004 13:15:53 +0000
changeset 348 b63ea19e502e
parent 211 9222a9b8b323
child 372 e6a156fc186d
permissions -rw-r--r--
A bool Edge Map with iterators that goes through the true or the false edges.
     1 #include <iostream>
     2 #include <fstream>
     3 
     4 #include <smart_graph.h>
     5 #include <list_graph.h>
     6 #include <dimacs.h>
     7 #include <preflow.h>
     8 #include <time_measure.h>
     9 
    10 using namespace hugo;
    11 
    12 // Use a DIMACS max flow file as stdin.
    13 // read_dimacs_demo < dimacs_max_flow_file
    14 int main(int, char **) {
    15   typedef SmartGraph::Node Node;
    16   typedef SmartGraph::EdgeIt EdgeIt;
    17 
    18   SmartGraph G;
    19   Node s, t;
    20   SmartGraph::EdgeMap<int> cap(G);
    21   readDimacsMaxFlow(std::cin, G, s, t, cap);
    22 
    23   std::cout << "preflow demo ..." << std::endl;
    24   
    25   double mintime=1000000;
    26 
    27   for ( int i=1; i!=11; ++i ) {
    28     SmartGraph::EdgeMap<int> flow(G);
    29     double pre_time=currTime();
    30     Preflow<SmartGraph, int> max_flow_test(G, s, t, cap, flow);
    31     max_flow_test.run();
    32     double post_time=currTime();
    33     if ( mintime > post_time-pre_time ) mintime = post_time-pre_time;
    34   }
    35 
    36   SmartGraph::EdgeMap<int> flow(G);
    37   Preflow<SmartGraph, int> max_flow_test(G, s, t, cap, flow);
    38   max_flow_test.run();
    39   
    40   SmartGraph::NodeMap<bool> cut(G);
    41   max_flow_test.minCut(cut); 
    42   int min_cut_value=0;
    43   EdgeIt e;
    44   for(G.first(e); G.valid(e); G.next(e)) {
    45     if (cut[G.tail(e)] && !cut[G.head(e)]) min_cut_value+=cap[e];
    46   }
    47 
    48   SmartGraph::NodeMap<bool> cut1(G);
    49   max_flow_test.minMinCut(cut1); 
    50   int min_min_cut_value=0;
    51   for(G.first(e); G.valid(e); G.next(e)) {
    52     if (cut[G.tail(e)] && !cut[G.head(e)]) 
    53       min_min_cut_value+=cap[e];
    54   }
    55 
    56   SmartGraph::NodeMap<bool> cut2(G);
    57   max_flow_test.maxMinCut(cut2); 
    58   int max_min_cut_value=0;
    59   for(G.first(e); G.valid(e); G.next(e)) {
    60     if (cut2[G.tail(e)] && !cut2[G.head(e)]) 
    61       max_min_cut_value+=cap[e];
    62       }
    63   
    64   std::cout << "min time of 10 runs: " << mintime << " sec"<< std::endl; 
    65   std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
    66   std::cout << "min cut value: "<< min_cut_value << std::endl;
    67   std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
    68   std::cout << "max min cut value: "<< max_min_cut_value << 
    69     std::endl<< std::endl;
    70   
    71   return 0;
    72 }