src/work/jacint/preflow.cc
author alpar
Fri, 23 Apr 2004 13:31:34 +0000
changeset 382 f177fc597abd
parent 374 0fc9cd9b854a
permissions -rw-r--r--
(none)
     1 #include <iostream>
     2 
     3 #include <smart_graph.h>
     4 #include <list_graph.h>
     5 #include <dimacs.h>
     6 #include <preflowproba.h>
     7 #include <time_measure.h>
     8 
     9 using namespace hugo;
    10 
    11 int main(int, char **) {
    12  
    13   typedef SmartGraph Graph;
    14   
    15   typedef Graph::Node Node;
    16   typedef Graph::EdgeIt EdgeIt;
    17 
    18   Graph G;
    19   Node s, t;
    20   Graph::EdgeMap<int> cap(G);
    21   readDimacsMaxFlow(std::cin, G, s, t, cap);
    22   Timer ts;
    23   
    24   std::cout << "preflow demo ..." << std::endl;
    25   
    26   Graph::EdgeMap<int> flow(G);
    27   Preflow<Graph, int> max_flow_test(G, s, t, cap, flow, 1,1);
    28   ts.reset();
    29   max_flow_test.run();
    30   std::cout << "elapsed time with res: " << ts << std::endl;
    31   
    32   std::cout << "preflow demo ..." << std::endl;
    33   
    34   Graph::EdgeMap<int> flow2(G);
    35   Preflow<Graph, int> max_flow_test2(G, s, t, cap, flow2, 1,0);
    36   ts.reset();
    37   max_flow_test2.run();
    38   std::cout << "elapsed time without res: " << ts << std::endl;
    39   
    40   Graph::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   Graph::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   Graph::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 << "flow value: "<< max_flow_test.flowValue() << std::endl;
    65   std::cout << "min cut value: "<< min_cut_value << std::endl;
    66   std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
    67   std::cout << "max min cut value: "<< max_min_cut_value << 
    68     std::endl<< std::endl;
    69   
    70   return 0;
    71 }