src/work/marci/preflow_demo_jacint.cc
changeset 88 93bb934b0794
parent 82 4d6a48fc0a2d
child 89 57fddb2bc15f
equal deleted inserted replaced
0:24724d03f1f9 1:d037673df454
     2 #include <fstream>
     2 #include <fstream>
     3 
     3 
     4 #include <list_graph.hh>
     4 #include <list_graph.hh>
     5 #include <dimacs.hh>
     5 #include <dimacs.hh>
     6 #include <preflow_push_max_flow.h>
     6 #include <preflow_push_max_flow.h>
       
     7 #include <preflow_push_hl.h>
     7 #include <time_measure.h>
     8 #include <time_measure.h>
     8 
     9 
     9 using namespace marci;
    10 using namespace marci;
    10 
    11 
    11 // Use a DIMACS max flow file as stdin.
    12 // Use a DIMACS max flow file as stdin.
    17   ListGraph G;
    18   ListGraph G;
    18   NodeIt s, t;
    19   NodeIt s, t;
    19   ListGraph::EdgeMap<int> cap(G);
    20   ListGraph::EdgeMap<int> cap(G);
    20   readDimacsMaxFlow(std::cin, G, s, t, cap);
    21   readDimacsMaxFlow(std::cin, G, s, t, cap);
    21 
    22 
    22   std::cout << "preflow demo (JACINT)..." << std::endl;
    23   {
       
    24   std::cout << "preflow demo (preflow_push_max_flow by JACINT)..." << std::endl;
    23   //ListGraph::EdgeMap<int> flow(G); //0 flow
    25   //ListGraph::EdgeMap<int> flow(G); //0 flow
    24 
    26 
    25   double pre_time=currTime();
    27   double pre_time=currTime();
    26   preflow_push_max_flow<ListGraph, int> max_flow_test(G, s, t, cap);
    28   preflow_push_max_flow<ListGraph, int> max_flow_test(G, s, t, cap);
    27   max_flow_test.run();
    29   max_flow_test.run();
    37   //}
    39   //}
    38   //std::cout<<std::endl;
    40   //std::cout<<std::endl;
    39   std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
    41   std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
    40   std::cout << "flow value: "<< max_flow_test.maxflow() << std::endl;
    42   std::cout << "flow value: "<< max_flow_test.maxflow() << std::endl;
    41   std::cout << "cut value: "<< cut_value << std::endl;
    43   std::cout << "cut value: "<< cut_value << std::endl;
       
    44   }
       
    45 
       
    46 /*
       
    47     {
       
    48   std::cout << "preflow demo (preflow_push_hl by JACINT)..." << std::endl;
       
    49   //ListGraph::EdgeMap<int> flow(G); //0 flow
       
    50 
       
    51   double pre_time=currTime();
       
    52   preflow_push_hl<ListGraph, int> max_flow_test(G, s, t, cap);
       
    53   max_flow_test.run();
       
    54   ListGraph::NodeMap<bool> cut=max_flow_test.mincut();
       
    55   int cut_value=0;
       
    56   for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
       
    57     if (cut.get(G.tail(e)) && !cut.get(G.head(e))) cut_value+=cap.get(e);
       
    58   }
       
    59   double post_time=currTime();
       
    60   //std::cout << "maximum flow: "<< std::endl;
       
    61   //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
       
    62   //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
       
    63   //}
       
    64   //std::cout<<std::endl;
       
    65   std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
       
    66   std::cout << "flow value: "<< max_flow_test.maxflow() << std::endl;
       
    67   std::cout << "cut value: "<< cut_value << std::endl;
       
    68   }
       
    69 */
    42 
    70 
    43   return 0;
    71   return 0;
    44 }
    72 }