5 #include <list_graph.h>
6 #include <smart_graph.h>
8 #include <edmonds_karp.h>
9 #include <time_measure.h>
10 #include <graph_wrapper.h>
14 // Use a DIMACS max flow file as stdin.
15 // read_dimacs_demo < dimacs_max_flow_file
25 // template <typename B>
33 int main(int, char **) {
35 typedef ListGraph MutableGraph;
37 typedef SmartGraph Graph;
38 //typedef ListGraph Graph;
39 typedef Graph::Node Node;
40 typedef Graph::EdgeIt EdgeIt;
46 // typedef Mize Tize[0];
48 // std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
49 // std::cout << sizeof(bize) << std::endl;
53 // std::cout << sizeof(k) << std::endl;
61 // std::cout << sizeof(Bumm) << std::endl;
66 Graph::EdgeMap<int> cap(G);
67 readDimacsMaxFlow(std::cin, G, s, t, cap);
69 // typedef TrivGraphWrapper<Graph> TGW;
72 // gw./*getF*/first(sw);
73 // std::cout << "p1:" << gw.nodeNum() << std::endl;
75 // std::cout << "p2:" << gw.nodeNum() << std::endl;
77 // typedef const Graph cLG;
78 // typedef TrivGraphWrapper<const cLG> CTGW;
81 // cgw./*getF*/first(csw);
82 // std::cout << "p1:" << cgw.nodeNum() << std::endl;
84 // std::cout << "p2:" << cgw.nodeNum() << std::endl;
88 std::cout << "SmartGraph..." << std::endl;
89 std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
90 Graph::EdgeMap<int> flow(G); //0 flow
95 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
96 //max_flow_test.augmentWithBlockingFlow<Graph>();
98 while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) {
99 // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
100 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
102 // std::cout<<std::endl;
106 // std::cout << "maximum flow: "<< std::endl;
107 // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
108 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
110 // std::cout<<std::endl;
111 std::cout << "elapsed time: " << ts << std::endl;
112 std::cout << "number of augmentation phases: " << i << std::endl;
113 std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
117 std::cout << "SmartGraph..." << std::endl;
118 std::cout << "edmonds karp demo (physical blocking flow 1 augmentation)..." << std::endl;
119 Graph::EdgeMap<int> flow(G); //0 flow
124 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
125 //max_flow_test.augmentWithBlockingFlow<Graph>();
127 while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
128 // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
129 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
131 // std::cout<<std::endl;
135 // std::cout << "maximum flow: "<< std::endl;
136 // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
137 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
139 // std::cout<<std::endl;
140 std::cout << "elapsed time: " << ts << std::endl;
141 std::cout << "number of augmentation phases: " << i << std::endl;
142 std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
146 std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
147 Graph::EdgeMap<int> flow(G); //0 flow
152 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
153 //max_flow_test.augmentWithBlockingFlow<Graph>();
155 while (max_flow_test.augmentOnBlockingFlow2()) {
156 // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
157 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
159 // std::cout<<std::endl;
163 // std::cout << "maximum flow: "<< std::endl;
164 // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
165 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
167 // std::cout<<std::endl;
168 std::cout << "elapsed time: " << ts << std::endl;
169 std::cout << "number of augmentation phases: " << i << std::endl;
170 std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
174 std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
175 Graph::EdgeMap<int> flow(G); //0 flow
180 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
181 //max_flow_test.augmentWithBlockingFlow<Graph>();
183 while (max_flow_test.augmentOnShortestPath()) {
184 // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
185 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
187 // std::cout<<std::endl;
191 // std::cout << "maximum flow: "<< std::endl;
192 // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
193 // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
195 // std::cout<<std::endl;
196 std::cout << "elapsed time: " << ts << std::endl;
197 std::cout << "number of augmentation phases: " << i << std::endl;
198 std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;