jacint@437: /* jacint@437: The only difference between preflow.h and preflow_res.h is that the latter jacint@437: uses the ResGraphWrapper, while the first does not. (Bfs is implemented by jacint@437: hand in both.) This test program runs Preflow and PreflowRes on the same jacint@437: graph, tests the result of these implementations and writes the running time jacint@437: of them. */ jacint@437: #include jacint@437: jacint@437: #include jacint@437: #include jacint@437: #include jacint@437: #include jacint@437: jacint@437: using namespace hugo; jacint@437: jacint@437: int main(int, char **) { jacint@437: jacint@437: typedef SmartGraph Graph; jacint@437: jacint@437: typedef Graph::Node Node; jacint@437: typedef Graph::EdgeIt EdgeIt; jacint@437: jacint@437: Graph G; jacint@437: Node s, t; jacint@437: Graph::EdgeMap cap(G); jacint@437: readDimacsMaxFlow(std::cin, G, s, t, cap); jacint@437: Timer ts; jacint@437: jacint@437: std::cout << jacint@437: "\n Are we slower?" jacint@437: < flow(G,0); jacint@437: Preflow max_flow_test(G, s, t, cap, flow, 0 , 0); jacint@437: ts.reset(); jacint@437: max_flow_test.run(); jacint@437: std::cout << "Elapsed time from a preflow: " << std::endl jacint@437: < mincut(G); jacint@437: max_flow_test.minMinCut(mincut); jacint@437: int min_min_cut_value=0; jacint@437: EdgeIt e; jacint@437: for(G.first(e); G.valid(e); G.next(e)) { jacint@437: if (mincut[G.tail(e)] && !mincut[G.head(e)]) min_min_cut_value+=cap[e]; jacint@437: } jacint@437: jacint@437: Graph::NodeMap cut(G); jacint@437: max_flow_test.minCut(cut); jacint@437: int min_cut_value=0; jacint@437: for(G.first(e); G.valid(e); G.next(e)) { jacint@437: if (cut[G.tail(e)] && !cut[G.head(e)]) jacint@437: min_cut_value+=cap[e]; jacint@437: } jacint@437: jacint@437: Graph::NodeMap maxcut(G); jacint@437: max_flow_test.maxMinCut(maxcut); jacint@437: int max_min_cut_value=0; jacint@437: for(G.first(e); G.valid(e); G.next(e)) { jacint@437: if (maxcut[G.tail(e)] && !maxcut[G.head(e)]) jacint@437: max_min_cut_value+=cap[e]; jacint@437: } jacint@437: jacint@437: std::cout << "\n Checking the result: " < flow2(G,0); jacint@437: Preflow max_flow_test2(G, s, t, cap, flow2, 0 , 1); jacint@437: ts.reset(); jacint@437: max_flow_test2.run(); jacint@437: std::cout << "Elapsed time from a flow: " << std::endl jacint@437: << ts << std::endl; jacint@437: jacint@437: Graph::NodeMap mincut2(G); jacint@437: max_flow_test2.minMinCut(mincut2); jacint@437: int min_min_cut_value2=0; jacint@437: for(G.first(e); G.valid(e); G.next(e)) { jacint@437: if (mincut2[G.tail(e)] && !mincut2[G.head(e)]) min_min_cut_value2+=cap[e]; jacint@437: } jacint@437: jacint@437: Graph::NodeMap cut2(G); jacint@437: max_flow_test2.minCut(cut2); jacint@437: int min_cut_value2=0; jacint@437: for(G.first(e); G.valid(e); G.next(e)) { jacint@437: if (cut2[G.tail(e)] && !cut2[G.head(e)]) jacint@437: min_cut_value2+=cap[e]; jacint@437: } jacint@437: jacint@437: Graph::NodeMap maxcut2(G); jacint@437: max_flow_test2.maxMinCut(maxcut2); jacint@437: int max_min_cut_value2=0; jacint@437: for(G.first(e); G.valid(e); G.next(e)) { jacint@437: if (maxcut2[G.tail(e)] && !maxcut2[G.head(e)]) jacint@437: max_min_cut_value2+=cap[e]; jacint@437: } jacint@437: jacint@437: std::cout << "\n Checking the result: " < flow3(G,0); jacint@437: Preflow max_flow_test3(G, s, t, cap, flow3, 1 , 1); jacint@437: ts.reset(); jacint@437: max_flow_test3.run(); jacint@437: std::cout << "Elapsed time from a const zero flow: " << std::endl jacint@437: < mincut3(G); jacint@437: max_flow_test3.minMinCut(mincut3); jacint@437: int min_min_cut_value3=0; jacint@437: for(G.first(e); G.valid(e); G.next(e)) { jacint@437: if (mincut3[G.tail(e)] && !mincut3[G.head(e)]) min_min_cut_value3+=cap[e]; jacint@437: } jacint@437: jacint@437: Graph::NodeMap cut3(G); jacint@437: max_flow_test3.minCut(cut3); jacint@437: int min_cut_value3=0; jacint@437: for(G.first(e); G.valid(e); G.next(e)) { jacint@437: if (cut3[G.tail(e)] && !cut3[G.head(e)]) jacint@437: min_cut_value3+=cap[e]; jacint@437: } jacint@437: jacint@437: Graph::NodeMap maxcut3(G); jacint@437: max_flow_test3.maxMinCut(maxcut3); jacint@437: int max_min_cut_value3=0; jacint@437: for(G.first(e); G.valid(e); G.next(e)) { jacint@437: if (maxcut3[G.tail(e)] && !maxcut3[G.head(e)]) jacint@437: max_min_cut_value3+=cap[e]; jacint@437: } jacint@437: jacint@437: std::cout << "\n Checking the result: " <