# HG changeset patch # User Peter Kovacs # Date 1521741386 -3600 # Node ID 259e3a90ad9762ec1d5adfe8f259aeb59acc79f1 # Parent e018899c2926e73e5f825f893cd3cea8edc1d54b Improve max flow test method: set expected flow value (#608) diff -r e018899c2926 -r 259e3a90ad97 test/max_flow_test.cc --- a/test/max_flow_test.cc Thu Mar 22 18:55:59 2018 +0100 +++ b/test/max_flow_test.cc Thu Mar 22 18:56:26 2018 +0100 @@ -243,7 +243,7 @@ } template -void checkMaxFlowAlg() { +void checkMaxFlowAlg(const char *input_lgf, typename MF::Value expected) { typedef SmartDigraph Digraph; DIGRAPH_TYPEDEFS(Digraph); @@ -257,7 +257,7 @@ Digraph g; Node s, t; CapMap cap(g); - std::istringstream input(test_lgf); + std::istringstream input(input_lgf); DigraphReader(g,input) .arcMap("capacity", cap) .node("source",s) @@ -267,6 +267,8 @@ MF max_flow(g, cap, s, t); max_flow.run(); + check(!tol.different(expected, max_flow.flowValue()), + "Incorrect max flow value."); check(checkFlow(g, max_flow.flowMap(), cap, s, t, tol), "The flow is not feasible."); @@ -274,14 +276,11 @@ max_flow.minCutMap(min_cut); Value min_cut_value = cutValue(g, min_cut, cap); - check(!tol.different(max_flow.flowValue(), min_cut_value), - "The max flow value is not equal to the min cut value."); + check(!tol.different(expected, min_cut_value), + "Incorrect min cut value."); FlowMap flow(g); for (ArcIt e(g); e != INVALID; ++e) flow[e] = max_flow.flowMap()[e]; - - Value flow_value = max_flow.flowValue(); - for (ArcIt e(g); e != INVALID; ++e) cap[e] = 2 * cap[e]; max_flow.init(flow); @@ -291,9 +290,10 @@ max_flow.minCutMap(min_cut1); min_cut_value = cutValue(g, min_cut1, cap); - check(!tol.different(max_flow.flowValue(), min_cut_value) && - !tol.different(min_cut_value, 2 * flow_value), - "The max flow value or the min cut value is wrong."); + check(!tol.different(2 * expected, max_flow.flowValue()), + "Incorrect max flow value."); + check(!tol.different(2 * expected, min_cut_value), + "Incorrect min cut value."); SF::startSecondPhase(max_flow); // start second phase of the algorithm @@ -304,9 +304,10 @@ max_flow.minCutMap(min_cut2); min_cut_value = cutValue(g, min_cut2, cap); - check(!tol.different(max_flow.flowValue(), min_cut_value) && - !tol.different(min_cut_value, 2 * flow_value), - "The max flow value or the min cut value was not doubled."); + check(!tol.different(2 * expected, max_flow.flowValue()), + "Incorrect max flow value."); + check(!tol.different(2 * expected, min_cut_value), + "Incorrect min cut value."); max_flow.flowMap(flow); @@ -380,16 +381,20 @@ // Check Preflow typedef Preflow > PType1; typedef Preflow > PType2; - checkMaxFlowAlg >(); - checkMaxFlowAlg >(); + typedef Preflow > PType3; + checkMaxFlowAlg >(test_lgf, 13); + checkMaxFlowAlg >(test_lgf, 13); + checkMaxFlowAlg >(test_lgf, 13); checkInitPreflow(); // Check EdmondsKarp typedef EdmondsKarp > EKType1; typedef EdmondsKarp > EKType2; - checkMaxFlowAlg >(); - checkMaxFlowAlg >(); + typedef EdmondsKarp > EKType3; + checkMaxFlowAlg >(test_lgf, 13); + checkMaxFlowAlg >(test_lgf, 13); + checkMaxFlowAlg >(test_lgf, 13); return 0; }