jacint@588: #include <iostream> jacint@588: jacint@715: #include <hugo/list_graph.h> jacint@715: #include <hugo/dimacs.h> jacint@588: #include <max_flow.h> jacint@715: #include <max_flow_no_stack.h> jacint@715: #include <hugo/time_measure.h> jacint@588: jacint@588: using namespace hugo; jacint@588: jacint@588: int main(int, char **) { jacint@588: jacint@588: typedef ListGraph Graph; jacint@588: jacint@588: typedef Graph::Node Node; jacint@588: typedef Graph::EdgeIt EdgeIt; jacint@588: jacint@588: Graph G; jacint@588: Node s, t; jacint@588: Graph::EdgeMap<int> cap(G); jacint@588: readDimacs(std::cin, G, cap, s, t); jacint@588: Timer ts; jacint@588: jacint@588: std::cout << jacint@588: "\n Running max_flow.h on a graph with " << jacint@588: G.nodeNum() << " nodes and " << G.edgeNum() << " edges..." jacint@588: << std::endl<<std::endl; jacint@588: jacint@715: Graph::EdgeMap<int> flowstack(G,0); jacint@715: MaxFlow<Graph, int> max_flow_test(G, s, t, cap, flowstack); jacint@588: ts.reset(); jacint@588: max_flow_test.run(); jacint@715: std::cout << "Elapsed time of run() with stl stack: " << std::endl jacint@715: <<ts << std::endl; jacint@715: jacint@715: Graph::EdgeMap<int> flow(G,0); jacint@715: MaxFlowNoStack<Graph, int> max_flow_test_no_stack(G, s, t, cap, flow); jacint@715: ts.reset(); jacint@715: max_flow_test_no_stack.run(); jacint@715: std::cout << "Elapsed time of run() without stack: " << std::endl jacint@588: <<ts << std::endl; jacint@588: jacint@588: Graph::NodeMap<bool> mincut(G); jacint@715: max_flow_test_no_stack.minMinCut(mincut); jacint@588: int min_min_cut_value=0; jacint@588: EdgeIt e; jacint@588: for(G.first(e); G.valid(e); G.next(e)) { jacint@588: if (mincut[G.tail(e)] && !mincut[G.head(e)]) min_min_cut_value+=cap[e]; jacint@588: } jacint@588: jacint@588: Graph::NodeMap<bool> cut(G); jacint@715: max_flow_test_no_stack.minCut(cut); jacint@588: int min_cut_value=0; jacint@588: for(G.first(e); G.valid(e); G.next(e)) { jacint@588: if (cut[G.tail(e)] && !cut[G.head(e)]) jacint@588: min_cut_value+=cap[e]; jacint@588: } jacint@588: jacint@588: Graph::NodeMap<bool> maxcut(G); jacint@715: max_flow_test_no_stack.maxMinCut(maxcut); jacint@588: int max_min_cut_value=0; jacint@588: for(G.first(e); G.valid(e); G.next(e)) { jacint@588: if (maxcut[G.tail(e)] && !maxcut[G.head(e)]) jacint@588: max_min_cut_value+=cap[e]; jacint@588: } jacint@588: jacint@715: std::cout << "\n Checking the result without stack: " <<std::endl; jacint@715: std::cout << "Flow value: "<< max_flow_test_no_stack.flowValue() << std::endl; jacint@588: std::cout << "Min cut value: "<< min_cut_value << std::endl; jacint@588: std::cout << "Min min cut value: "<< min_min_cut_value << std::endl; jacint@588: std::cout << "Max min cut value: "<< max_min_cut_value << jacint@588: std::endl; jacint@588: jacint@715: if ( max_flow_test_no_stack.flowValue() == min_cut_value && jacint@588: min_cut_value == min_min_cut_value && jacint@588: min_min_cut_value == max_min_cut_value ) jacint@588: std::cout << "They are equal! " <<std::endl<< std::endl<<"\n"; jacint@588: jacint@715: /* jacint@588: jacint@588: Graph::EdgeMap<int> flow2(G,0); jacint@588: std::cout << "Calling resetFlow() " << std::endl jacint@588: << ts << std::endl; alpar@757: max_flow_test.setFlow(flow2); jacint@588: ts.reset(); jacint@588: max_flow_test.preflow(max_flow_test.PRE_FLOW); jacint@588: std::cout << "Elapsed time of preflow(PRE_FLOW) starting from the zero flow: " << std::endl jacint@588: << ts << std::endl; jacint@588: jacint@588: Graph::NodeMap<bool> mincut2(G); jacint@588: max_flow_test.minMinCut(mincut2); jacint@588: int min_min_cut_value2=0; jacint@588: for(G.first(e); G.valid(e); G.next(e)) { jacint@588: if (mincut2[G.tail(e)] && !mincut2[G.head(e)]) min_min_cut_value2+=cap[e]; jacint@588: } jacint@588: jacint@588: Graph::NodeMap<bool> cut2(G); jacint@588: max_flow_test.minCut(cut2); jacint@588: int min_cut_value2=0; jacint@588: for(G.first(e); G.valid(e); G.next(e)) { jacint@588: if (cut2[G.tail(e)] && !cut2[G.head(e)]) jacint@588: min_cut_value2+=cap[e]; jacint@588: } jacint@588: jacint@588: Graph::NodeMap<bool> maxcut2(G); jacint@588: max_flow_test.maxMinCut(maxcut2); jacint@588: int max_min_cut_value2=0; jacint@588: for(G.first(e); G.valid(e); G.next(e)) { jacint@588: if (maxcut2[G.tail(e)] && !maxcut2[G.head(e)]) jacint@588: max_min_cut_value2+=cap[e]; jacint@588: } jacint@588: jacint@588: std::cout << "\n Checking the result: " <<std::endl; jacint@588: std::cout << "Flow value: "<< max_flow_test.flowValue() << std::endl; jacint@588: std::cout << "Min cut value: "<< min_cut_value2 << std::endl; jacint@588: std::cout << "Min min cut value: "<< min_min_cut_value2 << std::endl; jacint@588: std::cout << "Max min cut value: "<< max_min_cut_value2 << jacint@588: std::endl; jacint@588: if ( max_flow_test.flowValue() == min_cut_value && jacint@588: min_cut_value == min_min_cut_value && jacint@588: min_min_cut_value == max_min_cut_value ) jacint@588: std::cout << "They are equal! " <<std::endl; jacint@588: jacint@588: jacint@588: MaxFlow<Graph, int> max_flow_test3(G, s, t, cap, flow2); jacint@588: max_flow_test3.run(max_flow_test3.GEN_FLOW); jacint@588: std::cout << "Calling run(GEN_FLOW) from the max flow found before. " <<std::endl; jacint@588: jacint@588: Graph::NodeMap<bool> mincut3(G); jacint@588: max_flow_test3.minMinCut(mincut3); jacint@588: int min_min_cut_value3=0; jacint@588: for(G.first(e); G.valid(e); G.next(e)) { jacint@588: if (mincut3[G.tail(e)] && !mincut3[G.head(e)]) min_min_cut_value3+=cap[e]; jacint@588: } jacint@588: jacint@588: Graph::NodeMap<bool> cut3(G); jacint@588: max_flow_test3.minCut(cut3); jacint@588: int min_cut_value3=0; jacint@588: for(G.first(e); G.valid(e); G.next(e)) { jacint@588: if (cut3[G.tail(e)] && !cut3[G.head(e)]) jacint@588: min_cut_value3+=cap[e]; jacint@588: } jacint@588: jacint@588: Graph::NodeMap<bool> maxcut3(G); jacint@588: max_flow_test3.maxMinCut(maxcut3); jacint@588: int max_min_cut_value3=0; jacint@588: for(G.first(e); G.valid(e); G.next(e)) { jacint@588: if (maxcut3[G.tail(e)] && !maxcut3[G.head(e)]) jacint@588: max_min_cut_value3+=cap[e]; jacint@588: } jacint@588: jacint@588: std::cout << "\n Checking the result: " <<std::endl; jacint@588: std::cout << "Flow value: "<< max_flow_test3.flowValue() << std::endl; jacint@588: std::cout << "Min cut value: "<< min_cut_value3 << std::endl; jacint@588: std::cout << "Min min cut value: "<< min_min_cut_value3 << std::endl; jacint@588: std::cout << "Max min cut value: "<< max_min_cut_value3 << jacint@588: std::endl; jacint@588: jacint@588: if ( max_flow_test3.flowValue() == min_cut_value3 && jacint@588: min_cut_value3 == min_min_cut_value3 && jacint@588: min_min_cut_value3 == max_min_cut_value3 ) jacint@588: std::cout << "They are equal! " <<std::endl<< std::endl<<"\n"; jacint@715: */ jacint@588: jacint@588: return 0; jacint@588: }