src/work/jacint/preflow_excess_test.cc
changeset 437 9853b743d830
child 921 818510fa3d99
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/jacint/preflow_excess_test.cc	Tue Apr 27 10:27:34 2004 +0000
     1.3 @@ -0,0 +1,179 @@
     1.4 +/*
     1.5 +The only difference between preflow.h and preflow_res.h is that the latter
     1.6 +uses the ResGraphWrapper, while the first does not. (Bfs is implemented by
     1.7 +hand in both.) This test program runs Preflow and PreflowRes on the same
     1.8 +graph, tests the result of these implementations and writes the running time
     1.9 +of them.  */
    1.10 +#include <iostream>
    1.11 +
    1.12 +#include <smart_graph.h>
    1.13 +#include <dimacs.h>
    1.14 +#include <preflow_excess.h>
    1.15 +#include <time_measure.h>
    1.16 +
    1.17 +using namespace hugo;
    1.18 +
    1.19 +int main(int, char **) {
    1.20 + 
    1.21 +  typedef SmartGraph Graph;
    1.22 +  
    1.23 +  typedef Graph::Node Node;
    1.24 +  typedef Graph::EdgeIt EdgeIt;
    1.25 +
    1.26 +  Graph G;
    1.27 +  Node s, t;
    1.28 +  Graph::EdgeMap<int> cap(G);
    1.29 +  readDimacsMaxFlow(std::cin, G, s, t, cap);
    1.30 +  Timer ts;
    1.31 +  
    1.32 +  std::cout <<
    1.33 +    "\n  Are we slower?"
    1.34 +	    <<std::endl;
    1.35 +  std::cout <<
    1.36 +    "\n  Running preflow.h on a graph with " << 
    1.37 +    G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
    1.38 +	   << std::endl<<std::endl;
    1.39 +
    1.40 +
    1.41 +
    1.42 +
    1.43 +
    1.44 +
    1.45 +  
    1.46 +  Graph::EdgeMap<int> flow(G,0);
    1.47 +  Preflow<Graph, int> max_flow_test(G, s, t, cap, flow, 0 , 0);
    1.48 +  ts.reset();
    1.49 +  max_flow_test.run();
    1.50 +  std::cout << "Elapsed time from a preflow: " << std::endl 
    1.51 +	    <<ts << std::endl;
    1.52 +  
    1.53 +  Graph::NodeMap<bool> mincut(G);
    1.54 +  max_flow_test.minMinCut(mincut); 
    1.55 +  int min_min_cut_value=0;
    1.56 +  EdgeIt e;
    1.57 +  for(G.first(e); G.valid(e); G.next(e)) {
    1.58 +    if (mincut[G.tail(e)] && !mincut[G.head(e)]) min_min_cut_value+=cap[e];
    1.59 +  }
    1.60 +
    1.61 +  Graph::NodeMap<bool> cut(G);
    1.62 +  max_flow_test.minCut(cut); 
    1.63 +  int min_cut_value=0;
    1.64 +  for(G.first(e); G.valid(e); G.next(e)) {
    1.65 +    if (cut[G.tail(e)] && !cut[G.head(e)]) 
    1.66 +      min_cut_value+=cap[e];
    1.67 +  }
    1.68 +
    1.69 +  Graph::NodeMap<bool> maxcut(G);
    1.70 +  max_flow_test.maxMinCut(maxcut); 
    1.71 +  int max_min_cut_value=0;
    1.72 +  for(G.first(e); G.valid(e); G.next(e)) {
    1.73 +    if (maxcut[G.tail(e)] && !maxcut[G.head(e)]) 
    1.74 +      max_min_cut_value+=cap[e];
    1.75 +      }
    1.76 +
    1.77 +  std::cout << "\n Checking the result: " <<std::endl;  
    1.78 +  std::cout << "Flow value: "<< max_flow_test.flowValue() << std::endl;
    1.79 +  std::cout << "Min cut value: "<< min_cut_value << std::endl;
    1.80 +  std::cout << "Min min cut value: "<< min_min_cut_value << std::endl;
    1.81 +  std::cout << "Max min cut value: "<< max_min_cut_value << 
    1.82 +    std::endl;
    1.83 +
    1.84 +  if ( max_flow_test.flowValue() == min_cut_value &&
    1.85 +       min_cut_value == min_min_cut_value &&
    1.86 +       min_min_cut_value == max_min_cut_value )
    1.87 +    std::cout << "They are equal! " <<std::endl<< std::endl<<"\n";  
    1.88 +
    1.89 +
    1.90 +
    1.91 +
    1.92 +
    1.93 +  
    1.94 +  Graph::EdgeMap<int> flow2(G,0);
    1.95 +  Preflow<Graph, int> max_flow_test2(G, s, t, cap, flow2, 0 , 1);
    1.96 +  ts.reset();
    1.97 +  max_flow_test2.run();
    1.98 +  std::cout << "Elapsed time from a flow: " << std::endl 
    1.99 +	    << ts << std::endl;
   1.100 +  
   1.101 +  Graph::NodeMap<bool> mincut2(G);
   1.102 +  max_flow_test2.minMinCut(mincut2); 
   1.103 +  int min_min_cut_value2=0;
   1.104 +    for(G.first(e); G.valid(e); G.next(e)) {
   1.105 +    if (mincut2[G.tail(e)] && !mincut2[G.head(e)]) min_min_cut_value2+=cap[e];
   1.106 +  }
   1.107 +
   1.108 +  Graph::NodeMap<bool> cut2(G);
   1.109 +  max_flow_test2.minCut(cut2); 
   1.110 +  int min_cut_value2=0;
   1.111 +  for(G.first(e); G.valid(e); G.next(e)) {
   1.112 +    if (cut2[G.tail(e)] && !cut2[G.head(e)]) 
   1.113 +      min_cut_value2+=cap[e];
   1.114 +  }
   1.115 +
   1.116 +  Graph::NodeMap<bool> maxcut2(G);
   1.117 +  max_flow_test2.maxMinCut(maxcut2); 
   1.118 +  int max_min_cut_value2=0;
   1.119 +  for(G.first(e); G.valid(e); G.next(e)) {
   1.120 +    if (maxcut2[G.tail(e)] && !maxcut2[G.head(e)]) 
   1.121 +      max_min_cut_value2+=cap[e];
   1.122 +      }
   1.123 +  
   1.124 +  std::cout << "\n Checking the result: " <<std::endl;  
   1.125 +  std::cout << "Flow value: "<< max_flow_test2.flowValue() << std::endl;
   1.126 +  std::cout << "Min cut value: "<< min_cut_value2 << std::endl;
   1.127 +  std::cout << "Min min cut value: "<< min_min_cut_value2 << std::endl;
   1.128 +  std::cout << "Max min cut value: "<< max_min_cut_value2 << 
   1.129 +    std::endl;  
   1.130 +  if ( max_flow_test.flowValue() == min_cut_value &&
   1.131 +       min_cut_value == min_min_cut_value &&
   1.132 +       min_min_cut_value == max_min_cut_value )
   1.133 +    std::cout << "They are equal! " <<std::endl;  
   1.134 +
   1.135 +
   1.136 +
   1.137 +
   1.138 +
   1.139 +  Graph::EdgeMap<int> flow3(G,0);
   1.140 +  Preflow<Graph, int> max_flow_test3(G, s, t, cap, flow3, 1 , 1);
   1.141 +  ts.reset();
   1.142 +  max_flow_test3.run();
   1.143 +  std::cout << "Elapsed time from a const zero flow: " << std::endl 
   1.144 +	    <<ts << std::endl;
   1.145 +  
   1.146 +  Graph::NodeMap<bool> mincut3(G);
   1.147 +  max_flow_test3.minMinCut(mincut3); 
   1.148 +  int min_min_cut_value3=0;
   1.149 +  for(G.first(e); G.valid(e); G.next(e)) {
   1.150 +    if (mincut3[G.tail(e)] && !mincut3[G.head(e)]) min_min_cut_value3+=cap[e];
   1.151 +  }
   1.152 +
   1.153 +  Graph::NodeMap<bool> cut3(G);
   1.154 +  max_flow_test3.minCut(cut3); 
   1.155 +  int min_cut_value3=0;
   1.156 +  for(G.first(e); G.valid(e); G.next(e)) {
   1.157 +    if (cut3[G.tail(e)] && !cut3[G.head(e)]) 
   1.158 +      min_cut_value3+=cap[e];
   1.159 +  }
   1.160 +
   1.161 +  Graph::NodeMap<bool> maxcut3(G);
   1.162 +  max_flow_test3.maxMinCut(maxcut3); 
   1.163 +  int max_min_cut_value3=0;
   1.164 +  for(G.first(e); G.valid(e); G.next(e)) {
   1.165 +    if (maxcut3[G.tail(e)] && !maxcut3[G.head(e)]) 
   1.166 +      max_min_cut_value3+=cap[e];
   1.167 +      }
   1.168 +
   1.169 +  std::cout << "\n Checking the result: " <<std::endl;  
   1.170 +  std::cout << "Flow value: "<< max_flow_test3.flowValue() << std::endl;
   1.171 +  std::cout << "Min cut value: "<< min_cut_value3 << std::endl;
   1.172 +  std::cout << "Min min cut value: "<< min_min_cut_value3 << std::endl;
   1.173 +  std::cout << "Max min cut value: "<< max_min_cut_value3 << 
   1.174 +    std::endl;
   1.175 +
   1.176 +  if ( max_flow_test3.flowValue() == min_cut_value3 &&
   1.177 +       min_cut_value3 == min_min_cut_value3 &&
   1.178 +       min_min_cut_value3 == max_min_cut_value3 )
   1.179 +    std::cout << "They are equal! " <<std::endl<< std::endl<<"\n";  
   1.180 +  
   1.181 +  return 0;
   1.182 +}