[73] | 1 | #include <iostream> |
---|
| 2 | #include <fstream> |
---|
| 3 | |
---|
| 4 | #include <list_graph.hh> |
---|
| 5 | #include <dimacs.hh> |
---|
| 6 | #include <edmonds_karp.hh> |
---|
| 7 | #include <time_measure.h> |
---|
| 8 | |
---|
[105] | 9 | using namespace hugo; |
---|
[73] | 10 | |
---|
| 11 | // Use a DIMACS max flow file as stdin. |
---|
| 12 | // read_dimacs_demo < dimacs_max_flow_file |
---|
[139] | 13 | |
---|
| 14 | /* |
---|
| 15 | struct Ize { |
---|
| 16 | }; |
---|
| 17 | |
---|
| 18 | struct Mize { |
---|
| 19 | Ize bumm; |
---|
| 20 | }; |
---|
| 21 | |
---|
| 22 | template <typename B> |
---|
| 23 | class Huha { |
---|
| 24 | public: |
---|
| 25 | int u; |
---|
| 26 | B brr; |
---|
| 27 | }; |
---|
| 28 | */ |
---|
| 29 | |
---|
[73] | 30 | int main(int, char **) { |
---|
| 31 | typedef ListGraph::NodeIt NodeIt; |
---|
| 32 | typedef ListGraph::EachEdgeIt EachEdgeIt; |
---|
| 33 | |
---|
[139] | 34 | /* |
---|
| 35 | Mize mize[10]; |
---|
| 36 | Mize bize[0]; |
---|
| 37 | Mize zize; |
---|
| 38 | typedef Mize Tize[0]; |
---|
| 39 | |
---|
| 40 | std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl; |
---|
| 41 | std::cout << sizeof(bize) << std::endl; |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | Huha<Tize> k; |
---|
| 45 | std::cout << sizeof(k) << std::endl; |
---|
[146] | 46 | |
---|
| 47 | |
---|
| 48 | struct Bumm { |
---|
| 49 | //int a; |
---|
| 50 | bool b; |
---|
| 51 | }; |
---|
| 52 | |
---|
| 53 | std::cout << sizeof(Bumm) << std::endl; |
---|
[139] | 54 | */ |
---|
| 55 | |
---|
[73] | 56 | ListGraph G; |
---|
| 57 | NodeIt s, t; |
---|
| 58 | ListGraph::EdgeMap<int> cap(G); |
---|
| 59 | readDimacsMaxFlow(std::cin, G, s, t, cap); |
---|
| 60 | |
---|
[133] | 61 | { |
---|
| 62 | std::cout << "edmonds karp demo (blocking flow augmentation)..." << std::endl; |
---|
[73] | 63 | ListGraph::EdgeMap<int> flow(G); //0 flow |
---|
| 64 | |
---|
[144] | 65 | Timer ts; |
---|
| 66 | ts.reset(); |
---|
| 67 | //double pre_time=currTime(); |
---|
[73] | 68 | MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap); |
---|
[133] | 69 | //max_flow_test.augmentWithBlockingFlow<ListGraph>(); |
---|
[138] | 70 | int i=0; |
---|
| 71 | while (max_flow_test.augmentOnBlockingFlow<ListGraph>()) { ++i; } |
---|
[144] | 72 | //double post_time=currTime(); |
---|
[133] | 73 | |
---|
[73] | 74 | //std::cout << "maximum flow: "<< std::endl; |
---|
| 75 | //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { |
---|
| 76 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 77 | //} |
---|
| 78 | //std::cout<<std::endl; |
---|
[144] | 79 | std::cout << "elapsed time: " << ts << std::endl; |
---|
[138] | 80 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
[73] | 81 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
[133] | 82 | } |
---|
| 83 | |
---|
| 84 | { |
---|
| 85 | std::cout << "edmonds karp demo (shortest path augmentation)..." << std::endl; |
---|
| 86 | ListGraph::EdgeMap<int> flow(G); //0 flow |
---|
| 87 | |
---|
[144] | 88 | Timer ts; |
---|
| 89 | ts.reset(); |
---|
| 90 | //double pre_time=currTime(); |
---|
[133] | 91 | MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap); |
---|
| 92 | //max_flow_test.augmentWithBlockingFlow<ListGraph>(); |
---|
[138] | 93 | int i=0; |
---|
| 94 | while (max_flow_test.augmentOnShortestPath()) { ++i; } |
---|
[144] | 95 | //double post_time=currTime(); |
---|
[133] | 96 | |
---|
| 97 | //std::cout << "maximum flow: "<< std::endl; |
---|
| 98 | //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { |
---|
| 99 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 100 | //} |
---|
| 101 | //std::cout<<std::endl; |
---|
[144] | 102 | std::cout << "elapsed time: " << ts << std::endl; |
---|
[138] | 103 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
[133] | 104 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 105 | } |
---|
[73] | 106 | |
---|
| 107 | return 0; |
---|
| 108 | } |
---|