marci@281: // -*- c++ -*-
marci@281: #include <iostream>
marci@281: #include <fstream>
marci@281: 
marci@281: #include <list_graph.h>
marci@281: #include <smart_graph.h>
marci@281: #include <dimacs.h>
marci@281: #include <edmonds_karp.h>
marci@281: #include <time_measure.h>
marci@281: #include <graph_wrapper.h>
marci@281: 
marci@281: class CM {
marci@281: public:
marci@281:   template<typename T> int get(T) const {return 1;}
marci@281: };
marci@281: 
marci@281: using namespace hugo;
marci@281: 
marci@281: // Use a DIMACS max flow file as stdin.
marci@281: // read_dimacs_demo < dimacs_max_flow_file
marci@281: 
marci@281: 
marci@281: //   struct Ize {
marci@281: //   };
marci@281:   
marci@281: //   struct Mize {
marci@281: //     Ize bumm;
marci@281: //   };
marci@281: 
marci@281: //   template <typename B>
marci@281: //     class Huha {
marci@281: //     public:
marci@281: //       int u;
marci@281: //       B brr;
marci@281: //     };
marci@281: 
marci@281: 
marci@281: int main(int, char **) {
marci@281: 
marci@281:   typedef ListGraph MutableGraph;
marci@281: 
marci@281:   //typedef SmartGraph Graph;
marci@281:   typedef ListGraph Graph;
marci@281:   typedef Graph::Node Node;
marci@281:   typedef Graph::EdgeIt EdgeIt;
marci@281: 
marci@281: 
marci@281: //   Mize mize[10];
marci@281: //   Mize bize[0];
marci@281: //   Mize zize;
marci@281: //   typedef Mize Tize[0];
marci@281: 
marci@281: //   std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
marci@281: //   std::cout << sizeof(bize) << std::endl;
marci@281: 
marci@281: 
marci@281: //   Huha<Tize> k;
marci@281: //   std::cout << sizeof(k) << std::endl;
marci@281: 
marci@281: 
marci@281: //   struct Bumm {
marci@281: //     //int a;
marci@281: //     bool b;
marci@281: //   };
marci@281: 
marci@281: //   std::cout << sizeof(Bumm) << std::endl;
marci@281: 
marci@281: 
marci@281:   Graph G;
marci@281:   Node s, t;
marci@281:   Graph::EdgeMap<int> cap(G);
marci@281:   readDimacsMaxFlow(std::cin, G, s, t, cap);
marci@281: 
marci@281: //   typedef TrivGraphWrapper<Graph> TGW;
marci@281: //   TGW gw(G);
marci@281: //   TGW::NodeIt sw;
marci@281: //   gw./*getF*/first(sw);
marci@281: //   std::cout << "p1:" << gw.nodeNum() << std::endl;
marci@281: //   gw.erase(sw);
marci@281: //   std::cout << "p2:" << gw.nodeNum() << std::endl;
marci@281: 
marci@281: //   typedef const Graph cLG;
marci@281: //   typedef TrivGraphWrapper<const cLG> CTGW;
marci@281: //   CTGW cgw(G);
marci@281: //   CTGW::NodeIt csw;
marci@281: //   cgw./*getF*/first(csw);
marci@281: //   std::cout << "p1:" << cgw.nodeNum() << std::endl;
marci@281: //   //cgw.erase(csw);
marci@281: //   std::cout << "p2:" << cgw.nodeNum() << std::endl;
marci@281: 
marci@281: 
marci@281:   {
marci@281:     typedef TrivGraphWrapper<const Graph> GW;
marci@281:     GW gw(G);
marci@281:     std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
marci@281:     GW::EdgeMap<int> flow(gw); //0 flow
marci@281: 
marci@281:     Timer ts;
marci@281:     ts.reset();
marci@281: 
marci@281:     typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
marci@281:     EMW cw(cap);
marci@281:     MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
marci@281:     int i=0;
marci@281:     while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { 
marci@281: //     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@281: //       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@281: //     }
marci@281: //     std::cout<<std::endl;
marci@281:       ++i; 
marci@281:     }
marci@281: 
marci@281: //   std::cout << "maximum flow: "<< std::endl;
marci@281: //   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@281: //     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@281: //   }
marci@281: //   std::cout<<std::endl;
marci@281:     std::cout << "elapsed time: " << ts << std::endl;
marci@281:     std::cout << "number of augmentation phases: " << i << std::endl; 
marci@281:     std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@281:   }
marci@281: 
marci@281:   {
marci@281:     typedef TrivGraphWrapper<const Graph> GW;
marci@281:     GW gw(G);
marci@281:     std::cout << "edmonds karp demo (physical blocking flow 1 augmentation)..." << std::endl;
marci@281:     GW::EdgeMap<int> flow(gw); //0 flow
marci@281: 
marci@281:     Timer ts;
marci@281:     ts.reset();
marci@281: 
marci@281:     typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
marci@281:     EMW cw(cap);
marci@281:     MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
marci@281:     int i=0;
marci@281:     while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { 
marci@281: //     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@281: //       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@281: //     }
marci@281: //     std::cout<<std::endl;
marci@281:       ++i; 
marci@281:     }
marci@281: 
marci@281: //   std::cout << "maximum flow: "<< std::endl;
marci@281: //   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@281: //     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@281: //   }
marci@281: //   std::cout<<std::endl;
marci@281:     std::cout << "elapsed time: " << ts << std::endl;
marci@281:     std::cout << "number of augmentation phases: " << i << std::endl; 
marci@281:     std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@281:   }
marci@281: 
marci@281:   {
marci@281:     typedef TrivGraphWrapper<const Graph> GW;
marci@281:     GW gw(G);
marci@281:     std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
marci@281:     GW::EdgeMap<int> flow(gw); //0 flow
marci@281: 
marci@281:     Timer ts;
marci@281:     ts.reset();
marci@281: 
marci@281:     typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
marci@281:     EMW cw(cap);
marci@281:     MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
marci@281:     int i=0;
marci@281:     while (max_flow_test.augmentOnBlockingFlow2()) { 
marci@281: //     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@281: //       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@281: //     }
marci@281: //     std::cout<<std::endl;
marci@281:       ++i; 
marci@281:     }
marci@281: 
marci@281: //   std::cout << "maximum flow: "<< std::endl;
marci@281: //   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@281: //     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@281: //   }
marci@281: //   std::cout<<std::endl;
marci@281:     std::cout << "elapsed time: " << ts << std::endl;
marci@281:     std::cout << "number of augmentation phases: " << i << std::endl; 
marci@281:     std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@281:   }
marci@281: 
marci@281:   {
marci@281:     typedef TrivGraphWrapper<const Graph> GW;
marci@281:     GW gw(G);
marci@281:     std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
marci@281:     GW::EdgeMap<int> flow(gw); //0 flow
marci@281: 
marci@281:     Timer ts;
marci@281:     ts.reset();
marci@281: 
marci@281:     typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
marci@281:     EMW cw(cap);
marci@281:     MaxFlow<GW, int, GW::EdgeMap<int>, EMW> max_flow_test(gw, s, t, flow, cw);
marci@281:     int i=0;
marci@281:     while (max_flow_test.augmentOnShortestPath()) { 
marci@281: //     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
marci@281: //       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@281: //     }
marci@281: //     std::cout<<std::endl;
marci@281:       ++i; 
marci@281:     }
marci@281: 
marci@281: //   std::cout << "maximum flow: "<< std::endl;
marci@281: //   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
marci@281: //     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
marci@281: //   }
marci@281: //   std::cout<<std::endl;
marci@281:     std::cout << "elapsed time: " << ts << std::endl;
marci@281:     std::cout << "number of augmentation phases: " << i << std::endl; 
marci@281:     std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@281:   }
marci@281: 
marci@281: 
marci@281:   return 0;
marci@281: }