marci@174: // -*- c++ -*-
marci@174: #include <iostream>
marci@174: #include <fstream>
marci@174: #include <string>
marci@174: 
marci@642: #include <sage_graph.h>
alpar@921: #include <lemon/list_graph.h>
alpar@921: #include <lemon/smart_graph.h>
alpar@921: #include <lemon/dimacs.h>
alpar@921: #include <lemon/max_flow.h>
marci@762: #include <augmenting_flow.h>
alpar@921: #include <lemon/time_measure.h>
marci@762: #include <for_each_macros.h>
marci@174: 
alpar@921: using namespace lemon;
marci@174: 
marci@174: // Use a DIMACS max flow file as stdin.
marci@174: // read_dimacs_demo dimacs_max_flow_file
marci@174: 
marci@174: int main(int, char** argv) {
marci@174: 
marci@174:   std::string in=argv[1];
marci@642:   typedef SageGraph MutableGraph;
marci@174: 
marci@174:   {
marci@642:     typedef SageGraph Graph;
marci@174:     typedef Graph::Node Node;
marci@174:     typedef Graph::EdgeIt EdgeIt;
marci@174: 
marci@577:     Graph g;
marci@174:     Node s, t;
marci@577:     Graph::EdgeMap<int> cap(g);
marci@174:     std::ifstream ins(in.c_str());
marci@577:     //readDimacsMaxFlow(ins, g, s, t, cap);
marci@577:     readDimacs(ins, g, cap, s, t);
marci@174: 
marci@334:     Timer ts;
marci@577:     Graph::EdgeMap<int> flow(g); //0 flow
marci@334:     MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@577:       max_flow_test(g, s, t, cap, flow/*, true*/);
marci@762:     AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@762:       augmenting_flow_test(g, s, t, cap, flow/*, true*/);
marci@334: 
marci@642:     std::cout << "SageGraph ..." << std::endl;
marci@334: 
marci@174:     {
marci@334:       std::cout << "preflow ..." << std::endl;
marci@334:       ts.reset();
marci@476:       max_flow_test.run();
marci@334:       std::cout << "elapsed time: " << ts << std::endl;
marci@476:       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@334:     }
marci@174: 
marci@334:     {
marci@334:       std::cout << "physical blocking flow augmentation ..." << std::endl;
marci@777:       for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@174:       ts.reset();
marci@174:       int i=0;
marci@762:       while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174:       std::cout << "elapsed time: " << ts << std::endl;
marci@174:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762:       std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@174:     }
marci@174: 
marci@476: //     {
marci@476: //       std::cout << "faster physical blocking flow augmentation ..." << std::endl;
marci@577: //       FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
marci@476: //       ts.reset();
marci@476: //       int i=0;
marci@476: //       while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
marci@476: //       std::cout << "elapsed time: " << ts << std::endl;
marci@476: //       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@476: //       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@476: //     }
marci@174: 
marci@174:     {
marci@334:       std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
marci@777:       for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@334:       ts.reset();
marci@334:       int i=0;
marci@762:       while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@334:       std::cout << "elapsed time: " << ts << std::endl;
marci@334:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762:       std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@334:     }
marci@174: 
marci@334:     {
marci@334:       std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
marci@777:       for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@174:       ts.reset();
marci@174:       int i=0;
marci@762:       while (augmenting_flow_test.augmentOnShortestPath()) { ++i; }
marci@174:       std::cout << "elapsed time: " << ts << std::endl;
marci@174:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762:       std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@174:     }
marci@174:   }
marci@174: 
marci@174:   {
marci@174:     typedef SmartGraph Graph;
marci@174:     typedef Graph::Node Node;
marci@174:     typedef Graph::EdgeIt EdgeIt;
marci@174: 
marci@577:     Graph g;
marci@174:     Node s, t;
marci@577:     Graph::EdgeMap<int> cap(g);
marci@174:     std::ifstream ins(in.c_str());
marci@577:     //readDimacsMaxFlow(ins, g, s, t, cap);
marci@577:     readDimacs(ins, g, cap, s, t);
marci@174: 
marci@334:     Timer ts;
marci@577:     Graph::EdgeMap<int> flow(g); //0 flow
marci@334:     MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@577:       max_flow_test(g, s, t, cap, flow/*, true*/);
marci@762:     AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@762:       augmenting_flow_test(g, s, t, cap, flow/*, true*/);
marci@476:     //    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@577:     //  max_flow_test(g, s, t, cap, flow);
marci@334: 
marci@642:     std::cout << "SmartGraph ..." << std::endl;
marci@334: 
marci@174:     {
marci@334:       std::cout << "preflow ..." << std::endl;
marci@777:       for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@334:       ts.reset();
marci@476:       max_flow_test.run();
marci@334:       std::cout << "elapsed time: " << ts << std::endl;
marci@476:       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@334:     }
marci@174: 
marci@334:     {
marci@334:       std::cout << "physical blocking flow augmentation ..." << std::endl;
marci@777:       for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@174:       ts.reset();
marci@174:       int i=0;
marci@762:       while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174:       std::cout << "elapsed time: " << ts << std::endl;
marci@174:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762:       std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@174:     }
marci@174: 
marci@476: //     {
marci@476: //       std::cout << "faster physical blocking flow augmentation ..." << std::endl;
marci@577: //       FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
marci@476: //       ts.reset();
marci@476: //       int i=0;
marci@476: //       while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
marci@476: //       std::cout << "elapsed time: " << ts << std::endl;
marci@476: //       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@476: //       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@476: //     }
marci@174: 
marci@174:     {
marci@334:       std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
marci@777:       for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@334:       ts.reset();
marci@334:       int i=0;
marci@762:       while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@334:       std::cout << "elapsed time: " << ts << std::endl;
marci@334:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762:       std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@334:     }
marci@174: 
marci@334:     {
marci@334:       std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
marci@777:       for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@174:       ts.reset();
marci@174:       int i=0;
marci@762:       while (augmenting_flow_test.augmentOnShortestPath()) { ++i; }
marci@174:       std::cout << "elapsed time: " << ts << std::endl;
marci@174:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762:       std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@174:     }
marci@174:   }
marci@174: 
marci@642:   {
marci@642:     typedef ListGraph Graph;
marci@642:     typedef Graph::Node Node;
marci@642:     typedef Graph::EdgeIt EdgeIt;
marci@642: 
marci@642:     Graph g;
marci@642:     Node s, t;
marci@642:     Graph::EdgeMap<int> cap(g);
marci@642:     std::ifstream ins(in.c_str());
marci@642:     //readDimacsMaxFlow(ins, g, s, t, cap);
marci@642:     readDimacs(ins, g, cap, s, t);
marci@642: 
marci@642:     Timer ts;
marci@642:     Graph::EdgeMap<int> flow(g); //0 flow
marci@642:     MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@642:       max_flow_test(g, s, t, cap, flow/*, true*/);
marci@762:     AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@762:       augmenting_flow_test(g, s, t, cap, flow/*, true*/);
marci@642:     //    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@642:     //  max_flow_test(g, s, t, cap, flow);
marci@642: 
marci@642:     std::cout << "ListGraph ..." << std::endl;
marci@642: 
marci@642:     {
marci@642:       std::cout << "preflow ..." << std::endl;
marci@777:       for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@642:       ts.reset();
marci@642:       max_flow_test.run();
marci@642:       std::cout << "elapsed time: " << ts << std::endl;
marci@642:       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@642:     }
marci@642: 
marci@642:     {
marci@642:       std::cout << "physical blocking flow augmentation ..." << std::endl;
marci@777:       for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@642:       ts.reset();
marci@642:       int i=0;
marci@762:       while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@642:       std::cout << "elapsed time: " << ts << std::endl;
marci@642:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762:       std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@642:     }
marci@642: 
marci@642: //     {
marci@642: //       std::cout << "faster physical blocking flow augmentation ..." << std::endl;
marci@642: //       FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
marci@642: //       ts.reset();
marci@642: //       int i=0;
marci@642: //       while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
marci@642: //       std::cout << "elapsed time: " << ts << std::endl;
marci@642: //       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@642: //       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@642: //     }
marci@642: 
marci@642:     {
marci@642:       std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
marci@777:       for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@642:       ts.reset();
marci@642:       int i=0;
marci@762:       while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@642:       std::cout << "elapsed time: " << ts << std::endl;
marci@642:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762:       std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@642:     }
marci@642: 
marci@642:     {
marci@642:       std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
marci@777:       for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
marci@642:       ts.reset();
marci@642:       int i=0;
marci@762:       while (augmenting_flow_test.augmentOnShortestPath()) { ++i; }
marci@642:       std::cout << "elapsed time: " << ts << std::endl;
marci@642:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@762:       std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
marci@642:     }
marci@642:   }
marci@642: 
marci@174:   return 0;
marci@174: }