marci@174: // -*- c++ -*-
marci@174: #include <iostream>
marci@174: #include <fstream>
marci@174: #include <string>
marci@174: 
marci@174: #include <list_graph.h>
marci@174: #include <smart_graph.h>
marci@174: #include <dimacs.h>
marci@174: #include <edmonds_karp.h>
marci@174: #include <time_measure.h>
marci@174: #include <graph_wrapper.h>
marci@174: 
marci@174: using namespace hugo;
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@174:   typedef ListGraph MutableGraph;
marci@174: 
marci@174:   {
marci@174:     typedef ListGraph Graph;
marci@174:     typedef Graph::Node Node;
marci@174:     typedef Graph::EdgeIt EdgeIt;
marci@174: 
marci@174:     Graph G;
marci@174:     Node s, t;
marci@174:     Graph::EdgeMap<int> cap(G);
marci@174:     std::ifstream ins(in.c_str());
marci@174:     readDimacsMaxFlow(ins, G, s, t, cap);
marci@174: 
marci@174:     {
marci@174:       std::cout << "ListGraph..." << std::endl;
marci@174:       std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
marci@174:       Graph::EdgeMap<int> flow(G); //0 flow
marci@174: 
marci@174:       Timer ts;
marci@174:       ts.reset();
marci@174: 
marci@174:       MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174:       int i=0;
marci@174:       while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174: 
marci@174:       std::cout << "elapsed time: " << ts << std::endl;
marci@174:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174:       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174:     }
marci@174: 
marci@174:     {
marci@174:       std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
marci@174:       Graph::EdgeMap<int> flow(G); //0 flow
marci@174: 
marci@174:       Timer ts;
marci@174:       ts.reset();
marci@174: 
marci@174:       MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174:       int i=0;
marci@174:       while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@174: 
marci@174:       std::cout << "elapsed time: " << ts << std::endl;
marci@174:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174:       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174:     }
marci@174: 
marci@174:     {
marci@174:       std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
marci@174:       Graph::EdgeMap<int> flow(G); //0 flow
marci@174: 
marci@174:       Timer ts;
marci@174:       ts.reset();
marci@174: 
marci@174:       MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174:       int i=0;
marci@174:       while (max_flow_test.augmentOnShortestPath()) { ++i; }
marci@174: 
marci@174:       std::cout << "elapsed time: " << ts << std::endl;
marci@174:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174:       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174:     }
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@174:     Graph G;
marci@174:     Node s, t;
marci@174:     Graph::EdgeMap<int> cap(G);
marci@174:     std::ifstream ins(in.c_str());
marci@174:     readDimacsMaxFlow(ins, G, s, t, cap);
marci@174: 
marci@174:     {
marci@174:       std::cout << "SmartGraph..." << std::endl;
marci@174:       std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
marci@174:       Graph::EdgeMap<int> flow(G); //0 flow
marci@174: 
marci@174:       Timer ts;
marci@174:       ts.reset();
marci@174: 
marci@174:       MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174:       int i=0;
marci@174:       while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
marci@174: 
marci@174:       std::cout << "elapsed time: " << ts << std::endl;
marci@174:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174:       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174:     }
marci@174: 
marci@174:     {
marci@174:       std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
marci@174:       Graph::EdgeMap<int> flow(G); //0 flow
marci@174: 
marci@174:       Timer ts;
marci@174:       ts.reset();
marci@174: 
marci@174:       MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174:       int i=0;
marci@174:       while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
marci@174: 
marci@174:       std::cout << "elapsed time: " << ts << std::endl;
marci@174:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174:       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174:     }
marci@174: 
marci@174:     {
marci@174:       std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
marci@174:       Graph::EdgeMap<int> flow(G); //0 flow
marci@174: 
marci@174:       Timer ts;
marci@174:       ts.reset();
marci@174: 
marci@174:       MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
marci@174:       int i=0;
marci@174:       while (max_flow_test.augmentOnShortestPath()) { ++i; }
marci@174: 
marci@174:       std::cout << "elapsed time: " << ts << std::endl;
marci@174:       std::cout << "number of augmentation phases: " << i << std::endl; 
marci@174:       std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@174:     }
marci@174:   }
marci@174: 
marci@174:   return 0;
marci@174: }