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