src/work/marci/preflow_demo_jacint.cc
author marci
Wed, 18 Feb 2004 12:45:44 +0000
changeset 95 3322fbf254d2
parent 87 46705346edd4
child 100 f1de2ab64e1c
permissions -rw-r--r--
.
     1 #include <iostream>
     2 #include <fstream>
     3 
     4 #include <list_graph.hh>
     5 #include <dimacs.hh>
     6 #include <preflow_push_max_flow.h>
     7 #include <preflow_push_hl.h>
     8 #include <time_measure.h>
     9 
    10 using namespace marci;
    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 ListGraph::NodeIt NodeIt;
    16   typedef ListGraph::EachEdgeIt EachEdgeIt;
    17 
    18   ListGraph G;
    19   NodeIt s, t;
    20   ListGraph::EdgeMap<int> cap(G);
    21   readDimacsMaxFlow(std::cin, G, s, t, cap);
    22 
    23   {
    24   std::cout << "preflow demo (preflow_push_max_flow by JACINT)..." << std::endl;
    25   //ListGraph::EdgeMap<int> flow(G); //0 flow
    26 
    27   double pre_time=currTime();
    28   preflow_push_max_flow<ListGraph, int> max_flow_test(G, s, t, cap);
    29   max_flow_test.run();
    30   ListGraph::NodeMap<bool> cut=max_flow_test.mincut();
    31   int cut_value=0;
    32   for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
    33     if (cut.get(G.tail(e)) && !cut.get(G.head(e))) cut_value+=cap.get(e);
    34   }
    35   double post_time=currTime();
    36   //std::cout << "maximum flow: "<< std::endl;
    37   //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
    38   //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
    39   //}
    40   //std::cout<<std::endl;
    41   std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
    42   std::cout << "flow value: "<< max_flow_test.maxflow() << std::endl;
    43   std::cout << "cut value: "<< cut_value << std::endl;
    44   }
    45 
    46     {
    47   std::cout << "preflow demo (preflow_push_hl by JACINT)..." << std::endl;
    48   //ListGraph::EdgeMap<int> flow(G); //0 flow
    49 
    50   double pre_time=currTime();
    51   preflow_push_hl<ListGraph, int> max_flow_test(G, s, t, cap);
    52   max_flow_test.run();
    53   ListGraph::NodeMap<bool> cut=max_flow_test.mincut();
    54   int cut_value=0;
    55   for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
    56     if (cut.get(G.tail(e)) && !cut.get(G.head(e))) cut_value+=cap.get(e);
    57   }
    58   double post_time=currTime();
    59   //std::cout << "maximum flow: "<< std::endl;
    60   //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
    61   //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
    62   //}
    63   //std::cout<<std::endl;
    64   std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
    65   std::cout << "flow value: "<< max_flow_test.maxflow() << std::endl;
    66   std::cout << "cut value: "<< cut_value << std::endl;
    67   }
    68 
    69 
    70   return 0;
    71 }