jacint@388: /*
jacint@388: The only difference between preflow.h and preflow_res.h is that the latter
jacint@388: uses the ResGraphWrapper, while the first does not. (Bfs is implemented by
jacint@388: hand in both.) This test program runs Preflow and PreflowRes on the same
jacint@388: graph, tests the result of these implementations and writes the running time
jacint@388: of them.  */
jacint@388: #include <iostream>
jacint@388: 
jacint@388: #include <smart_graph.h>
jacint@388: #include <dimacs.h>
jacint@388: #include <preflow.h>
jacint@388: #include <preflow_res.h>
jacint@388: #include <time_measure.h>
jacint@388: 
jacint@388: using namespace hugo;
jacint@388: 
jacint@388: int main(int, char **) {
jacint@388:  
jacint@388:   typedef SmartGraph Graph;
jacint@388:   
jacint@388:   typedef Graph::Node Node;
jacint@388:   typedef Graph::EdgeIt EdgeIt;
jacint@388: 
jacint@388:   Graph G;
jacint@388:   Node s, t;
jacint@388:   Graph::EdgeMap<int> cap(G);
jacint@388:   readDimacsMaxFlow(std::cin, G, s, t, cap);
jacint@388:   Timer ts;
jacint@388:   
jacint@388:   std::cout <<
jacint@388:     "\n  In which way are we faster: using ResGraphWrapper or not?"
jacint@388: 	    <<std::endl;
jacint@388:   std::cout <<
jacint@388:     "\n  Running preflow.h on a graph with " << 
jacint@388:     G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
jacint@388: 	   << std::endl<<std::endl;
jacint@388: 
jacint@388: 
jacint@388:   
jacint@388:   Graph::EdgeMap<int> flow(G,0);
jacint@388:   Preflow<Graph, int> max_flow_test(G, s, t, cap, flow, 1);
jacint@388:   ts.reset();
jacint@388:   max_flow_test.run();
jacint@388:   std::cout << "Elapsed time NOT using the ResGraphWrapper: " << std::endl 
jacint@388: 	    <<ts << std::endl;
jacint@388:   
jacint@388:   Graph::NodeMap<bool> mincut(G);
jacint@388:   max_flow_test.minMinCut(mincut); 
jacint@388:   int min_min_cut_value=0;
jacint@388:   EdgeIt e;
jacint@388:   for(G.first(e); G.valid(e); G.next(e)) {
jacint@388:     if (mincut[G.tail(e)] && !mincut[G.head(e)]) min_min_cut_value+=cap[e];
jacint@388:   }
jacint@388: 
jacint@388:   Graph::NodeMap<bool> cut(G);
jacint@388:   max_flow_test.minCut(cut); 
jacint@388:   int min_cut_value=0;
jacint@388:   for(G.first(e); G.valid(e); G.next(e)) {
jacint@388:     if (cut[G.tail(e)] && !cut[G.head(e)]) 
jacint@388:       min_cut_value+=cap[e];
jacint@388:   }
jacint@388: 
jacint@388:   Graph::NodeMap<bool> maxcut(G);
jacint@388:   max_flow_test.maxMinCut(maxcut); 
jacint@388:   int max_min_cut_value=0;
jacint@388:   for(G.first(e); G.valid(e); G.next(e)) {
jacint@388:     if (maxcut[G.tail(e)] && !maxcut[G.head(e)]) 
jacint@388:       max_min_cut_value+=cap[e];
jacint@388:       }
jacint@388: 
jacint@388:   std::cout << "\n Checking the result: " <<std::endl;  
jacint@388:   std::cout << "Flow value: "<< max_flow_test.flowValue() << std::endl;
jacint@388:   std::cout << "Min cut value: "<< min_cut_value << std::endl;
jacint@388:   std::cout << "Min min cut value: "<< min_min_cut_value << std::endl;
jacint@388:   std::cout << "Max min cut value: "<< max_min_cut_value << 
jacint@388:     std::endl;
jacint@388: 
jacint@388:   if ( max_flow_test.flowValue() == min_cut_value &&
jacint@388:        min_cut_value == min_min_cut_value &&
jacint@388:        min_min_cut_value == max_min_cut_value )
jacint@388:     std::cout << "They are equal! " <<std::endl<< std::endl<<"\n";  
jacint@388:   
jacint@388:   Graph::EdgeMap<int> flow2(G,0);
jacint@388:   PreflowRes<Graph, int> max_flow_test2(G, s, t, cap, flow2, 1);
jacint@388:   ts.reset();
jacint@388:   max_flow_test2.run();
jacint@388:   std::cout << "Elapsed time using the ResGraphWrapper: " << std::endl 
jacint@388: 	    << ts << std::endl;
jacint@388:   
jacint@388:   Graph::NodeMap<bool> mincut2(G);
jacint@388:   max_flow_test2.minMinCut(mincut2); 
jacint@388:   int min_min_cut_value2=0;
jacint@388:     for(G.first(e); G.valid(e); G.next(e)) {
jacint@388:     if (mincut2[G.tail(e)] && !mincut2[G.head(e)]) min_min_cut_value2+=cap[e];
jacint@388:   }
jacint@388: 
jacint@388:   Graph::NodeMap<bool> cut2(G);
jacint@388:   max_flow_test2.minCut(cut2); 
jacint@388:   int min_cut_value2=0;
jacint@388:   for(G.first(e); G.valid(e); G.next(e)) {
jacint@388:     if (cut2[G.tail(e)] && !cut2[G.head(e)]) 
jacint@388:       min_cut_value2+=cap[e];
jacint@388:   }
jacint@388: 
jacint@388:   Graph::NodeMap<bool> maxcut2(G);
jacint@388:   max_flow_test2.maxMinCut(maxcut2); 
jacint@388:   int max_min_cut_value2=0;
jacint@388:   for(G.first(e); G.valid(e); G.next(e)) {
jacint@388:     if (maxcut2[G.tail(e)] && !maxcut2[G.head(e)]) 
jacint@388:       max_min_cut_value2+=cap[e];
jacint@388:       }
jacint@388:   
jacint@388:   std::cout << "\n Checking the result: " <<std::endl;  
jacint@388:   std::cout << "Flow value: "<< max_flow_test2.flowValue() << std::endl;
jacint@388:   std::cout << "Min cut value: "<< min_cut_value2 << std::endl;
jacint@388:   std::cout << "Min min cut value: "<< min_min_cut_value2 << std::endl;
jacint@388:   std::cout << "Max min cut value: "<< max_min_cut_value2 << 
jacint@388:     std::endl;  
jacint@388:   if ( max_flow_test.flowValue() == min_cut_value &&
jacint@388:        min_cut_value == min_min_cut_value &&
jacint@388:        min_min_cut_value == max_min_cut_value )
jacint@388:     std::cout << "They are equal! " <<std::endl<<"/n";  
jacint@388:   
jacint@388:   return 0;
jacint@388: }