src/work/jacint/preflow_max_flow.cc
changeset 113 cf7b01232d86
equal deleted inserted replaced
-1:000000000000 0:5d726b67bb32
       
     1 #include <iostream>
       
     2 #include <fstream>
       
     3 
       
     4 #include <list_graph.hh>
       
     5 #include <dimacs.hh>
       
     6 #include <preflow_max_flow.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 typedef ListGraph::EachNodeIt EachNodeIt;
       
    17 
       
    18   ListGraph G;
       
    19   NodeIt s, t;
       
    20   ListGraph::EdgeMap<int> cap(G);
       
    21   readDimacsMaxFlow(std::cin, G, s, t, cap);
       
    22 
       
    23   std::cout << "preflow_max_flow demo ..." << std::endl;
       
    24   
       
    25   double pre_time=currTime();
       
    26   preflow_max_flow<ListGraph, int> max_flow_test(G, s, t, cap);
       
    27   ListGraph::NodeMap<bool> cut=max_flow_test.minCut();
       
    28   double post_time=currTime();
       
    29   
       
    30   int cut_value=0;
       
    31   for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
       
    32     if (cut.get(G.tail(e)) && !cut.get(G.head(e))) cut_value+=cap.get(e);
       
    33   }
       
    34   
       
    35   std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
       
    36   std::cout << "flow value: "<< max_flow_test.maxFlow() << std::endl;
       
    37   std::cout << "cut value: "<< cut_value << std::endl;
       
    38 
       
    39   return 0;
       
    40 }