src/work/jacint/preflow_max_flow.cc
author jacint
Mon, 01 Mar 2004 17:24:34 +0000
changeset 142 01d47457aff3
permissions -rw-r--r--
nagytakaritas
     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 }