jacint@109: #include <iostream>
jacint@109: #include <fstream>
jacint@109: 
jacint@220: #include <smart_graph.h>
jacint@211: #include <list_graph.h>
jacint@211: #include <dimacs.h>
jacint@109: #include <preflow.h>
jacint@109: #include <time_measure.h>
jacint@109: 
jacint@109: using namespace hugo;
jacint@109: 
jacint@109: // Use a DIMACS max flow file as stdin.
jacint@109: // read_dimacs_demo < dimacs_max_flow_file
jacint@109: int main(int, char **) {
jacint@220:   typedef SmartGraph::Node Node;
jacint@220:   typedef SmartGraph::EdgeIt EdgeIt;
jacint@109: 
jacint@220:   SmartGraph G;
jacint@211:   Node s, t;
jacint@220:   SmartGraph::EdgeMap<int> cap(G);
jacint@109:   readDimacsMaxFlow(std::cin, G, s, t, cap);
jacint@109: 
jacint@109:   std::cout << "preflow demo ..." << std::endl;
jacint@109:   
jacint@109:   double mintime=1000000;
jacint@109: 
jacint@109:   for ( int i=1; i!=11; ++i ) {
jacint@220:     SmartGraph::EdgeMap<int> flow(G);
jacint@109:     double pre_time=currTime();
jacint@220:     Preflow<SmartGraph, int> max_flow_test(G, s, t, cap, flow);
jacint@211:     max_flow_test.run();
jacint@109:     double post_time=currTime();
jacint@109:     if ( mintime > post_time-pre_time ) mintime = post_time-pre_time;
jacint@109:   }
jacint@109: 
jacint@220:   SmartGraph::EdgeMap<int> flow(G);
jacint@220:   Preflow<SmartGraph, int> max_flow_test(G, s, t, cap, flow);
jacint@211:   max_flow_test.run();
jacint@211:   
jacint@220:   SmartGraph::NodeMap<bool> cut(G);
jacint@109:   max_flow_test.minCut(cut); 
jacint@109:   int min_cut_value=0;
jacint@211:   EdgeIt e;
jacint@211:   for(G.first(e); G.valid(e); G.next(e)) {
jacint@220:     if (cut[G.tail(e)] && !cut[G.head(e)]) min_cut_value+=cap[e];
jacint@109:   }
jacint@109: 
jacint@220:   SmartGraph::NodeMap<bool> cut1(G);
jacint@109:   max_flow_test.minMinCut(cut1); 
jacint@109:   int min_min_cut_value=0;
jacint@211:   for(G.first(e); G.valid(e); G.next(e)) {
jacint@220:     if (cut[G.tail(e)] && !cut[G.head(e)]) 
jacint@220:       min_min_cut_value+=cap[e];
jacint@109:   }
jacint@109: 
jacint@220:   SmartGraph::NodeMap<bool> cut2(G);
jacint@109:   max_flow_test.maxMinCut(cut2); 
jacint@109:   int max_min_cut_value=0;
jacint@211:   for(G.first(e); G.valid(e); G.next(e)) {
jacint@220:     if (cut2[G.tail(e)] && !cut2[G.head(e)]) 
jacint@220:       max_min_cut_value+=cap[e];
jacint@109:       }
jacint@109:   
jacint@109:   std::cout << "min time of 10 runs: " << mintime << " sec"<< std::endl; 
jacint@211:   std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
jacint@109:   std::cout << "min cut value: "<< min_cut_value << std::endl;
jacint@109:   std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
jacint@109:   std::cout << "max min cut value: "<< max_min_cut_value << 
jacint@109:     std::endl<< std::endl;
jacint@109:   
jacint@109:   return 0;
jacint@109: }