src/work/jacint/preflow.cc
changeset 870 9bde6cd8e3da
parent 451 6b36be4cffa4
child 921 818510fa3d99
equal deleted inserted replaced
7:bfc2962b9a13 8:d77f3a564572
    17   Graph G;
    17   Graph G;
    18   Node s, t;
    18   Node s, t;
    19   Graph::EdgeMap<int> cap(G);
    19   Graph::EdgeMap<int> cap(G);
    20   readDimacsMaxFlow(std::cin, G, s, t, cap);
    20   readDimacsMaxFlow(std::cin, G, s, t, cap);
    21   Timer ts;
    21   Timer ts;
       
    22   bool error=false;
    22   
    23   
    23   std::cout <<
    24   std::cout <<
    24     "\n  Testing preflow.h on a graph with " << 
    25     "\n  Testing preflow.h on a graph with " << 
    25     G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
    26     G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
    26 	   << std::endl;
    27 	   << std::endl;
    59 
    60 
    60   if ( preflow_test.flowValue() == min_cut_value &&
    61   if ( preflow_test.flowValue() == min_cut_value &&
    61        min_cut_value == min_min_cut_value &&
    62        min_cut_value == min_min_cut_value &&
    62        min_min_cut_value == max_min_cut_value )
    63        min_min_cut_value == max_min_cut_value )
    63     std::cout << "They are equal. " <<std::endl;  
    64     std::cout << "They are equal. " <<std::endl;  
    64 
    65   else {
    65 
    66     std::cout << "ERROR! They are not equal! " <<std::endl;  
       
    67     error=true;
       
    68   }
    66 
    69 
    67 
    70 
    68 
    71 
    69   Preflow<Graph, int> preflow_test2(G, s, t, cap, flow);
    72   Preflow<Graph, int> preflow_test2(G, s, t, cap, flow);
    70   std::cout << "\n\nCalling preflow(GEN_FLOW) with the given maximum flow..."<<std::endl;
    73   std::cout << "\n\nCalling preflow(GEN_FLOW) with the given maximum flow..."<<std::endl;
    94   if ( preflow_test2.flowValue() == min_cut2_value &&
    97   if ( preflow_test2.flowValue() == min_cut2_value &&
    95        min_cut2_value == min_min_cut2_value &&
    98        min_cut2_value == min_min_cut2_value &&
    96        min_min_cut2_value == max_min_cut2_value )
    99        min_min_cut2_value == max_min_cut2_value )
    97     std::cout <<", which is equal to all three min cut values." 
   100     std::cout <<", which is equal to all three min cut values." 
    98 	      <<std::endl;  
   101 	      <<std::endl;  
    99 
   102   else {
   100 
   103     std::cout << "ERROR! It is not equal to all three min cut values! " 
       
   104 	      <<std::endl;  
       
   105     error=true;
       
   106   }
       
   107   
   101 
   108 
   102 
   109 
   103 
   110 
   104   Graph::EdgeMap<int> flow3(G,0);
   111   Graph::EdgeMap<int> flow3(G,0);
   105   Preflow<Graph, int> preflow_test3(G, s, t, cap, flow3);
   112   Preflow<Graph, int> preflow_test3(G, s, t, cap, flow3);
   146        max_min_cut3_value == act_min_cut3_value ) {
   153        max_min_cut3_value == act_min_cut3_value ) {
   147     std::cout << 
   154     std::cout << 
   148       ", which is equal to the given flow value and to all three min cut values after phase 1." 
   155       ", which is equal to the given flow value and to all three min cut values after phase 1." 
   149 	      <<std::endl;  
   156 	      <<std::endl;  
   150   }
   157   }
   151 
   158   else {
       
   159     std::cout << 
       
   160       "ERROR! It is not equal to the given flow value and to all three min cut values after phase 1! " 
       
   161 	      <<std::endl;  
       
   162     error=true;
       
   163   }
       
   164   
   152 
   165 
   153 
   166 
   154 
   167 
   155 
   168 
   156   Graph::EdgeMap<int> flow4(G,0);
   169   Graph::EdgeMap<int> flow4(G,0);
   193   if ( preflow_test4.flowValue() == min_cut4_value &&
   206   if ( preflow_test4.flowValue() == min_cut4_value &&
   194        min_cut4_value == min_min_cut4_value &&
   207        min_cut4_value == min_min_cut4_value &&
   195        min_min_cut4_value == max_min_cut4_value )
   208        min_min_cut4_value == max_min_cut4_value )
   196     std::cout <<", which is equal to all three min cut values." 
   209     std::cout <<", which is equal to all three min cut values." 
   197 	      <<std::endl;  
   210 	      <<std::endl;  
       
   211   else {
       
   212     std::cout << "ERROR! It is not equal to all three min cut values! " 
       
   213 	      <<std::endl;  
       
   214     error=true;
       
   215   }
   198 
   216 
   199 
   217 
   200 
   218 
   201 
   219 
   202   Graph::EdgeMap<int> flow5(G,0);
   220   Graph::EdgeMap<int> flow5(G,0);
   231   if ( preflow_test4.flowValue() == min_cut5_value &&
   249   if ( preflow_test4.flowValue() == min_cut5_value &&
   232        min_cut5_value == min_min_cut5_value &&
   250        min_cut5_value == min_min_cut5_value &&
   233        min_min_cut5_value == max_min_cut5_value )
   251        min_min_cut5_value == max_min_cut5_value )
   234     std::cout <<", which is equal to all three min cut values." 
   252     std::cout <<", which is equal to all three min cut values." 
   235 	      <<std::endl<<std::endl;  
   253 	      <<std::endl<<std::endl;  
   236 
   254   else {
       
   255     std::cout << "ERROR! It is not equal to all three min cut values! " 
       
   256 	      <<std::endl;  
       
   257     error=true;
       
   258   }
       
   259   
       
   260   if (error) std::cout <<"\nThere was some error in the results!\n"<<std::endl; 
       
   261   else std::cout <<"\nThere was no error in the results.\n"<<std::endl; 
   237 
   262 
   238   return 0;
   263   return 0;
   239 }
   264 }