marci@475: // -*- c++ -*- marci@777: marci@777: // Use a DIMACS max flow file as stdin. marci@777: // max_flow_demo < dimacs_max_flow_file marci@777: marci@475: #include marci@475: #include marci@475: alpar@921: #include alpar@921: #include alpar@921: #include alpar@921: #include alpar@921: #include marci@762: #include marci@651: #include marci@475: alpar@921: using namespace lemon; marci@475: marci@475: int main(int, char **) { marci@475: marci@854: typedef ListGraph MutableGraph; marci@854: typedef SmartGraph Graph; marci@475: typedef Graph::Node Node; marci@475: typedef Graph::EdgeIt EdgeIt; marci@475: marci@577: Graph g; marci@652: marci@475: Node s, t; marci@577: Graph::EdgeMap cap(g); marci@577: //readDimacsMaxFlow(std::cin, g, s, t, cap); marci@577: readDimacs(std::cin, g, cap, s, t); marci@475: Timer ts; marci@577: Graph::EdgeMap flow(g); //0 flow marci@849: Preflow, Graph::EdgeMap > marci@577: max_flow_test(g, s, t, cap, flow); marci@762: AugmentingFlow, Graph::EdgeMap > marci@762: augmenting_flow_test(g, s, t, cap, flow); marci@762: marci@646: Graph::NodeMap cut(g); marci@475: marci@475: { marci@475: std::cout << "preflow ..." << std::endl; marci@475: ts.reset(); marci@476: max_flow_test.run(); marci@475: std::cout << "elapsed time: " << ts << std::endl; marci@476: std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; marci@849: max_flow_test.minCut(cut); marci@646: marci@854: for(Graph::EdgeIt e(g); e!=INVALID; ++e) { marci@646: if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) marci@646: std::cout << "Slackness does not hold!" << std::endl; marci@646: if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) marci@646: std::cout << "Slackness does not hold!" << std::endl; marci@646: } marci@475: } marci@475: marci@475: { marci@475: std::cout << "preflow ..." << std::endl; marci@854: for(Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); marci@475: ts.reset(); marci@854: max_flow_test.run(Preflow, Graph::EdgeMap >::GEN_FLOW); marci@475: std::cout << "elapsed time: " << ts << std::endl; marci@476: std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; marci@646: marci@854: for(Graph::EdgeIt e(g); e!=INVALID; ++e) { marci@646: if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) marci@646: std::cout << "Slackness does not hold!" << std::endl; marci@646: if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) marci@646: std::cout << "Slackness does not hold!" << std::endl; marci@646: } marci@475: } marci@475: marci@475: // { marci@475: // std::cout << "wrapped preflow ..." << std::endl; marci@577: // FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); marci@475: // ts.reset(); marci@475: // pre_flow_res.run(); marci@475: // std::cout << "elapsed time: " << ts << std::endl; marci@475: // std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl; marci@475: // } marci@475: marci@475: { marci@475: std::cout << "physical blocking flow augmentation ..." << std::endl; marci@854: for(Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); marci@475: ts.reset(); marci@475: int i=0; marci@762: while (augmenting_flow_test.augmentOnBlockingFlow()) { ++i; } marci@475: std::cout << "elapsed time: " << ts << std::endl; marci@475: std::cout << "number of augmentation phases: " << i << std::endl; marci@762: std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl; marci@646: marci@854: for(Graph::EdgeIt e(g); e!=INVALID; ++e) { marci@646: if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) marci@646: std::cout << "Slackness does not hold!" << std::endl; marci@646: if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) marci@646: std::cout << "Slackness does not hold!" << std::endl; marci@646: } marci@475: } marci@475: marci@777: { marci@777: std::cout << "on-the-fly blocking flow augmentation ..." << std::endl; marci@854: for(Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); marci@777: ts.reset(); marci@777: int i=0; marci@777: while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; } marci@777: std::cout << "elapsed time: " << ts << std::endl; marci@777: std::cout << "number of augmentation phases: " << i << std::endl; marci@777: std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl; marci@775: marci@854: for(Graph::EdgeIt e(g); e!=INVALID; ++e) { marci@777: if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) marci@777: std::cout << "Slackness does not hold!" << std::endl; marci@777: if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) marci@777: std::cout << "Slackness does not hold!" << std::endl; marci@777: } marci@777: } marci@475: marci@475: { marci@475: std::cout << "on-the-fly shortest path augmentation ..." << std::endl; marci@854: for(Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); marci@475: ts.reset(); marci@475: int i=0; marci@762: while (augmenting_flow_test.augmentOnShortestPath()) { ++i; } marci@475: std::cout << "elapsed time: " << ts << std::endl; marci@475: std::cout << "number of augmentation phases: " << i << std::endl; marci@762: std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl; marci@646: marci@854: for(Graph::EdgeIt e(g); e!=INVALID; ++e) { marci@646: if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) marci@646: std::cout << "Slackness does not hold!" << std::endl; marci@646: if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) marci@646: std::cout << "Slackness does not hold!" << std::endl; marci@646: } marci@475: } marci@475: marci@646: { marci@646: std::cout << "on-the-fly shortest path augmentation ..." << std::endl; marci@854: for(Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); marci@646: ts.reset(); marci@646: int i=0; marci@762: while (augmenting_flow_test.augmentOnShortestPath2()) { ++i; } marci@646: std::cout << "elapsed time: " << ts << std::endl; marci@646: std::cout << "number of augmentation phases: " << i << std::endl; marci@762: std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl; marci@646: marci@854: for(Graph::EdgeIt e(g); e!=INVALID; ++e) { marci@646: if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) marci@646: std::cout << "Slackness does not hold!" << std::endl; marci@646: if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) marci@646: std::cout << "Slackness does not hold!" << std::endl; marci@646: } marci@646: } marci@475: marci@475: return 0; marci@475: }