src/work/jacint/preflow_jgraph.cc
changeset 132 1ac27e476e25
equal deleted inserted replaced
-1:000000000000 0:1c1a503efee6
       
     1 #include <iostream>
       
     2 #include <fstream>
       
     3 
       
     4 #include <j_graph.h>
       
     5 #include <dimacs_jgraph.hh>
       
     6 #include <preflow_jgraph.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 JGraph::TrivNodeIt TrivNodeIt;
       
    15   typedef JGraph::EdgeIt EdgeIt;
       
    16 
       
    17   JGraph G;
       
    18   TrivNodeIt s, t;
       
    19   JGraph::EdgeMap<int> cap(G);
       
    20   readDimacsMaxFlow(std::cin, G, s, t, cap);
       
    21 
       
    22   std::cout << "preflow demo jacint ..." << std::endl;
       
    23   
       
    24   double mintime=1000000;
       
    25 
       
    26   for ( int i=1; i!=11; ++i ) {
       
    27     double pre_time=currTime();
       
    28     preflow<JGraph, 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   double pre_time=currTime();
       
    34     preflow<JGraph, int> max_flow_test(G, s, t, cap);
       
    35   double post_time=currTime();
       
    36     
       
    37   JGraph::NodeMap<bool> cut(G);
       
    38   max_flow_test.minCut(cut); 
       
    39   int min_cut_value=0;
       
    40   for(EdgeIt e=G.firstEdge(); e; G.next(e)) {
       
    41     if (cut.get(G.tail(e)) && !cut.get(G.head(e))) min_cut_value+=cap.get(e);
       
    42   }
       
    43 
       
    44   JGraph::NodeMap<bool> cut1(G);
       
    45   max_flow_test.minMinCut(cut1); 
       
    46   int min_min_cut_value=0;
       
    47   for(EdgeIt e=G.firstEdge(); e; G.next(e)) {
       
    48     if (cut.get(G.tail(e)) && !cut.get(G.head(e))) 
       
    49       min_min_cut_value+=cap.get(e);
       
    50   }
       
    51 
       
    52   JGraph::NodeMap<bool> cut2(G);
       
    53   max_flow_test.maxMinCut(cut2); 
       
    54   int max_min_cut_value=0;
       
    55   for(EdgeIt e=G.firstEdge(); e; G.next(e)) {
       
    56     if (cut2.get(G.tail(e)) && !cut2.get(G.head(e))) 
       
    57       max_min_cut_value+=cap.get(e);
       
    58   }
       
    59   
       
    60   std::cout << "min time of 10 runs: " << mintime << " sec"<< std::endl; 
       
    61   std::cout << "phase 0: " << max_flow_test.time-pre_time 
       
    62 	    << " sec"<< std::endl; 
       
    63   std::cout << "phase 1: " << post_time-max_flow_test.time 
       
    64 	    << " sec"<< std::endl; 
       
    65   std::cout << "flow value: "<< max_flow_test.maxFlow() << 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 }