src/work/jacint/max_flow_test.cc
changeset 1365 c280de819a73
parent 1364 ee5959aa4410
child 1366 d00b85f8be45
     1.1 --- a/src/work/jacint/max_flow_test.cc	Sun Apr 17 18:57:22 2005 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,166 +0,0 @@
     1.4 -#include <iostream>
     1.5 -
     1.6 -#include <lemon/list_graph.h>
     1.7 -#include <lemon/dimacs.h>
     1.8 -#include <max_flow.h>
     1.9 -#include <max_flow_no_stack.h>
    1.10 -#include <lemon/time_measure.h>
    1.11 -
    1.12 -using namespace lemon;
    1.13 -
    1.14 -int main(int, char **) {
    1.15 - 
    1.16 -  typedef ListGraph Graph;
    1.17 -  
    1.18 -  typedef Graph::Node Node;
    1.19 -  typedef Graph::EdgeIt EdgeIt;
    1.20 -
    1.21 -  Graph G;
    1.22 -  Node s, t;
    1.23 -  Graph::EdgeMap<int> cap(G);
    1.24 -  readDimacs(std::cin, G, cap, s, t);
    1.25 -  Timer ts;
    1.26 -  
    1.27 -  std::cout <<
    1.28 -    "\n  Running max_flow.h on a graph with " << 
    1.29 -    G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
    1.30 -	   << std::endl<<std::endl;
    1.31 -
    1.32 -  Graph::EdgeMap<int> flowstack(G,0);
    1.33 -  MaxFlow<Graph, int> max_flow_test(G, s, t, cap, flowstack);
    1.34 -  ts.reset();
    1.35 -  max_flow_test.run();
    1.36 -  std::cout << "Elapsed time of run() with stl stack: " << std::endl 
    1.37 -	    <<ts << std::endl;
    1.38 -
    1.39 -  Graph::EdgeMap<int> flow(G,0);
    1.40 -  MaxFlowNoStack<Graph, int> max_flow_test_no_stack(G, s, t, cap, flow);
    1.41 -  ts.reset();
    1.42 -  max_flow_test_no_stack.run();
    1.43 -  std::cout << "Elapsed time of run() without stack: " << std::endl 
    1.44 -	    <<ts << std::endl;
    1.45 -  
    1.46 -  Graph::NodeMap<bool> mincut(G);
    1.47 -  max_flow_test_no_stack.minMinCut(mincut); 
    1.48 -  int min_min_cut_value=0;
    1.49 -  EdgeIt e;
    1.50 -  for(G.first(e); G.valid(e); G.next(e)) {
    1.51 -    if (mincut[G.source(e)] && !mincut[G.target(e)]) min_min_cut_value+=cap[e];
    1.52 -  }
    1.53 -
    1.54 -  Graph::NodeMap<bool> cut(G);
    1.55 -  max_flow_test_no_stack.minCut(cut); 
    1.56 -  int min_cut_value=0;
    1.57 -  for(G.first(e); G.valid(e); G.next(e)) {
    1.58 -    if (cut[G.source(e)] && !cut[G.target(e)]) 
    1.59 -      min_cut_value+=cap[e];
    1.60 -  }
    1.61 -
    1.62 -  Graph::NodeMap<bool> maxcut(G);
    1.63 -  max_flow_test_no_stack.maxMinCut(maxcut); 
    1.64 -  int max_min_cut_value=0;
    1.65 -  for(G.first(e); G.valid(e); G.next(e)) {
    1.66 -    if (maxcut[G.source(e)] && !maxcut[G.target(e)]) 
    1.67 -      max_min_cut_value+=cap[e];
    1.68 -      }
    1.69 -
    1.70 -  std::cout << "\n Checking the result without stack: " <<std::endl;  
    1.71 -  std::cout << "Flow value: "<< max_flow_test_no_stack.flowValue() << std::endl;
    1.72 -  std::cout << "Min cut value: "<< min_cut_value << std::endl;
    1.73 -  std::cout << "Min min cut value: "<< min_min_cut_value << std::endl;
    1.74 -  std::cout << "Max min cut value: "<< max_min_cut_value << 
    1.75 -    std::endl;
    1.76 -
    1.77 -  if ( max_flow_test_no_stack.flowValue() == min_cut_value &&
    1.78 -       min_cut_value == min_min_cut_value &&
    1.79 -       min_min_cut_value == max_min_cut_value )
    1.80 -    std::cout << "They are equal! " <<std::endl<< std::endl<<"\n";  
    1.81 -
    1.82 -  /*
    1.83 -
    1.84 -  Graph::EdgeMap<int> flow2(G,0);
    1.85 -  std::cout << "Calling resetFlow() " << std::endl 
    1.86 -	    << ts << std::endl;
    1.87 -  max_flow_test.setFlow(flow2);  
    1.88 -  ts.reset();
    1.89 -  max_flow_test.preflow(max_flow_test.PRE_FLOW);
    1.90 -  std::cout << "Elapsed time of preflow(PRE_FLOW) starting from the zero flow: " << std::endl 
    1.91 -	    << ts << std::endl;
    1.92 -  
    1.93 -  Graph::NodeMap<bool> mincut2(G);
    1.94 -  max_flow_test.minMinCut(mincut2); 
    1.95 -  int min_min_cut_value2=0;
    1.96 -    for(G.first(e); G.valid(e); G.next(e)) {
    1.97 -    if (mincut2[G.source(e)] && !mincut2[G.target(e)]) min_min_cut_value2+=cap[e];
    1.98 -  }
    1.99 -
   1.100 -  Graph::NodeMap<bool> cut2(G);
   1.101 -  max_flow_test.minCut(cut2); 
   1.102 -  int min_cut_value2=0;
   1.103 -  for(G.first(e); G.valid(e); G.next(e)) {
   1.104 -    if (cut2[G.source(e)] && !cut2[G.target(e)]) 
   1.105 -      min_cut_value2+=cap[e];
   1.106 -  }
   1.107 -
   1.108 -  Graph::NodeMap<bool> maxcut2(G);
   1.109 -  max_flow_test.maxMinCut(maxcut2); 
   1.110 -  int max_min_cut_value2=0;
   1.111 -  for(G.first(e); G.valid(e); G.next(e)) {
   1.112 -    if (maxcut2[G.source(e)] && !maxcut2[G.target(e)]) 
   1.113 -      max_min_cut_value2+=cap[e];
   1.114 -      }
   1.115 -  
   1.116 -  std::cout << "\n Checking the result: " <<std::endl;  
   1.117 -  std::cout << "Flow value: "<< max_flow_test.flowValue() << std::endl;
   1.118 -  std::cout << "Min cut value: "<< min_cut_value2 << std::endl;
   1.119 -  std::cout << "Min min cut value: "<< min_min_cut_value2 << std::endl;
   1.120 -  std::cout << "Max min cut value: "<< max_min_cut_value2 << 
   1.121 -    std::endl;  
   1.122 -  if ( max_flow_test.flowValue() == min_cut_value &&
   1.123 -       min_cut_value == min_min_cut_value &&
   1.124 -       min_min_cut_value == max_min_cut_value )
   1.125 -    std::cout << "They are equal! " <<std::endl;  
   1.126 -
   1.127 -
   1.128 -  MaxFlow<Graph, int> max_flow_test3(G, s, t, cap, flow2);
   1.129 -  max_flow_test3.run(max_flow_test3.GEN_FLOW);
   1.130 -  std::cout << "Calling run(GEN_FLOW) from the max flow found before. " <<std::endl;  
   1.131 -  
   1.132 -  Graph::NodeMap<bool> mincut3(G);
   1.133 -  max_flow_test3.minMinCut(mincut3); 
   1.134 -  int min_min_cut_value3=0;
   1.135 -  for(G.first(e); G.valid(e); G.next(e)) {
   1.136 -    if (mincut3[G.source(e)] && !mincut3[G.target(e)]) min_min_cut_value3+=cap[e];
   1.137 -  }
   1.138 -
   1.139 -  Graph::NodeMap<bool> cut3(G);
   1.140 -  max_flow_test3.minCut(cut3); 
   1.141 -  int min_cut_value3=0;
   1.142 -  for(G.first(e); G.valid(e); G.next(e)) {
   1.143 -    if (cut3[G.source(e)] && !cut3[G.target(e)]) 
   1.144 -      min_cut_value3+=cap[e];
   1.145 -  }
   1.146 -
   1.147 -  Graph::NodeMap<bool> maxcut3(G);
   1.148 -  max_flow_test3.maxMinCut(maxcut3); 
   1.149 -  int max_min_cut_value3=0;
   1.150 -  for(G.first(e); G.valid(e); G.next(e)) {
   1.151 -    if (maxcut3[G.source(e)] && !maxcut3[G.target(e)]) 
   1.152 -      max_min_cut_value3+=cap[e];
   1.153 -  }
   1.154 -
   1.155 -  std::cout << "\n Checking the result: " <<std::endl;  
   1.156 -  std::cout << "Flow value: "<< max_flow_test3.flowValue() << std::endl;
   1.157 -  std::cout << "Min cut value: "<< min_cut_value3 << std::endl;
   1.158 -  std::cout << "Min min cut value: "<< min_min_cut_value3 << std::endl;
   1.159 -  std::cout << "Max min cut value: "<< max_min_cut_value3 << 
   1.160 -    std::endl;
   1.161 -
   1.162 -  if ( max_flow_test3.flowValue() == min_cut_value3 &&
   1.163 -       min_cut_value3 == min_min_cut_value3 &&
   1.164 -       min_min_cut_value3 == max_min_cut_value3 )
   1.165 -    std::cout << "They are equal! " <<std::endl<< std::endl<<"\n";  
   1.166 -  */
   1.167 -  
   1.168 -  return 0;
   1.169 -}