[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; |
---|
[168] | 90 | while (max_flow_test.augmentOnBlockingFlow<ListGraph>()) { |
---|
| 91 | // for(EachEdgeIt e=G.template first<EachEdgeIt>(); e.valid(); ++e) { |
---|
| 92 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 93 | // } |
---|
| 94 | // std::cout<<std::endl; |
---|
| 95 | ++i; |
---|
| 96 | } |
---|
| 97 | //double post_time=currTime(); |
---|
| 98 | |
---|
| 99 | //std::cout << "maximum flow: "<< std::endl; |
---|
| 100 | //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { |
---|
| 101 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 102 | //} |
---|
| 103 | //std::cout<<std::endl; |
---|
| 104 | std::cout << "elapsed time: " << ts << std::endl; |
---|
| 105 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
| 106 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | { |
---|
| 110 | std::cout << "edmonds karp demo (blocking flow augmentation)..." << std::endl; |
---|
| 111 | ListGraph::EdgeMap<int> flow(G); //0 flow |
---|
| 112 | |
---|
| 113 | Timer ts; |
---|
| 114 | ts.reset(); |
---|
| 115 | //double pre_time=currTime(); |
---|
| 116 | MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap); |
---|
| 117 | //max_flow_test.augmentWithBlockingFlow<ListGraph>(); |
---|
| 118 | int i=0; |
---|
| 119 | while (max_flow_test.augmentOnBlockingFlow2()) { |
---|
| 120 | // for(EachEdgeIt e=G.template first<EachEdgeIt>(); e.valid(); ++e) { |
---|
| 121 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 122 | // } |
---|
| 123 | // std::cout<<std::endl; |
---|
| 124 | ++i; |
---|
| 125 | } |
---|
[144] | 126 | //double post_time=currTime(); |
---|
[133] | 127 | |
---|
[73] | 128 | //std::cout << "maximum flow: "<< std::endl; |
---|
| 129 | //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { |
---|
| 130 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 131 | //} |
---|
| 132 | //std::cout<<std::endl; |
---|
[144] | 133 | std::cout << "elapsed time: " << ts << std::endl; |
---|
[138] | 134 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
[73] | 135 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
[133] | 136 | } |
---|
| 137 | |
---|
| 138 | { |
---|
| 139 | std::cout << "edmonds karp demo (shortest path augmentation)..." << std::endl; |
---|
| 140 | ListGraph::EdgeMap<int> flow(G); //0 flow |
---|
| 141 | |
---|
[144] | 142 | Timer ts; |
---|
| 143 | ts.reset(); |
---|
| 144 | //double pre_time=currTime(); |
---|
[133] | 145 | MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap); |
---|
| 146 | //max_flow_test.augmentWithBlockingFlow<ListGraph>(); |
---|
[138] | 147 | int i=0; |
---|
[168] | 148 | while (max_flow_test.augmentOnShortestPath()) { |
---|
| 149 | // for(EachEdgeIt e=G.template first<EachEdgeIt>(); e.valid(); ++e) { |
---|
| 150 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 151 | // } |
---|
| 152 | // std::cout<<std::endl; |
---|
| 153 | ++i; |
---|
| 154 | } |
---|
[144] | 155 | //double post_time=currTime(); |
---|
[133] | 156 | |
---|
| 157 | //std::cout << "maximum flow: "<< std::endl; |
---|
| 158 | //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { |
---|
| 159 | // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; |
---|
| 160 | //} |
---|
| 161 | //std::cout<<std::endl; |
---|
[144] | 162 | std::cout << "elapsed time: " << ts << std::endl; |
---|
[138] | 163 | std::cout << "number of augmentation phases: " << i << std::endl; |
---|
[133] | 164 | std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; |
---|
| 165 | } |
---|
[73] | 166 | |
---|
| 167 | return 0; |
---|
| 168 | } |
---|