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