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