COIN-OR::LEMON - Graph Library

Changeset 1384:259e3a90ad97 in lemon


Ignore:
Timestamp:
03/22/18 18:56:26 (5 months ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Message:

Improve max flow test method: set expected flow value (#608)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/max_flow_test.cc

    r1383 r1384  
    244244 
    245245template <typename MF, typename SF> 
    246 void checkMaxFlowAlg() { 
     246void checkMaxFlowAlg(const char *input_lgf,  typename MF::Value expected) { 
    247247  typedef SmartDigraph Digraph; 
    248248  DIGRAPH_TYPEDEFS(Digraph); 
     
    258258  Node s, t; 
    259259  CapMap cap(g); 
    260   std::istringstream input(test_lgf); 
     260  std::istringstream input(input_lgf); 
    261261  DigraphReader<Digraph>(g,input) 
    262262      .arcMap("capacity", cap) 
     
    268268  max_flow.run(); 
    269269 
     270  check(!tol.different(expected, max_flow.flowValue()), 
     271        "Incorrect max flow value."); 
    270272  check(checkFlow(g, max_flow.flowMap(), cap, s, t, tol), 
    271273        "The flow is not feasible."); 
     
    275277  Value min_cut_value = cutValue(g, min_cut, cap); 
    276278 
    277   check(!tol.different(max_flow.flowValue(), min_cut_value), 
    278         "The max flow value is not equal to the min cut value."); 
     279  check(!tol.different(expected, min_cut_value), 
     280        "Incorrect min cut value."); 
    279281 
    280282  FlowMap flow(g); 
    281283  for (ArcIt e(g); e != INVALID; ++e) flow[e] = max_flow.flowMap()[e]; 
    282  
    283   Value flow_value = max_flow.flowValue(); 
    284  
    285284  for (ArcIt e(g); e != INVALID; ++e) cap[e] = 2 * cap[e]; 
    286285  max_flow.init(flow); 
     
    292291  min_cut_value = cutValue(g, min_cut1, cap); 
    293292 
    294   check(!tol.different(max_flow.flowValue(), min_cut_value) && 
    295         !tol.different(min_cut_value, 2 * flow_value), 
    296         "The max flow value or the min cut value is wrong."); 
     293  check(!tol.different(2 * expected, max_flow.flowValue()), 
     294        "Incorrect max flow value."); 
     295  check(!tol.different(2 * expected, min_cut_value), 
     296        "Incorrect min cut value."); 
    297297 
    298298  SF::startSecondPhase(max_flow);       // start second phase of the algorithm 
     
    305305  min_cut_value = cutValue(g, min_cut2, cap); 
    306306 
    307   check(!tol.different(max_flow.flowValue(), min_cut_value) && 
    308         !tol.different(min_cut_value, 2 * flow_value), 
    309         "The max flow value or the min cut value was not doubled."); 
     307  check(!tol.different(2 * expected, max_flow.flowValue()), 
     308        "Incorrect max flow value."); 
     309  check(!tol.different(2 * expected, min_cut_value), 
     310        "Incorrect min cut value."); 
    310311 
    311312  max_flow.flowMap(flow); 
     
    381382  typedef Preflow<SmartDigraph, SmartDigraph::ArcMap<int> > PType1; 
    382383  typedef Preflow<SmartDigraph, SmartDigraph::ArcMap<float> > PType2; 
    383   checkMaxFlowAlg<PType1, PreflowStartFunctions<PType1> >(); 
    384   checkMaxFlowAlg<PType2, PreflowStartFunctions<PType2> >(); 
     384  typedef Preflow<SmartDigraph, SmartDigraph::ArcMap<double> > PType3; 
     385  checkMaxFlowAlg<PType1, PreflowStartFunctions<PType1> >(test_lgf, 13); 
     386  checkMaxFlowAlg<PType2, PreflowStartFunctions<PType2> >(test_lgf, 13); 
     387  checkMaxFlowAlg<PType3, PreflowStartFunctions<PType3> >(test_lgf, 13); 
    385388 
    386389  checkInitPreflow(); 
     
    389392  typedef EdmondsKarp<SmartDigraph, SmartDigraph::ArcMap<int> > EKType1; 
    390393  typedef EdmondsKarp<SmartDigraph, SmartDigraph::ArcMap<float> > EKType2; 
    391   checkMaxFlowAlg<EKType1, GeneralStartFunctions<EKType1> >(); 
    392   checkMaxFlowAlg<EKType2, GeneralStartFunctions<EKType2> >(); 
     394  typedef EdmondsKarp<SmartDigraph, SmartDigraph::ArcMap<double> > EKType3; 
     395  checkMaxFlowAlg<EKType1, GeneralStartFunctions<EKType1> >(test_lgf, 13); 
     396  checkMaxFlowAlg<EKType2, GeneralStartFunctions<EKType2> >(test_lgf, 13); 
     397  checkMaxFlowAlg<EKType3, GeneralStartFunctions<EKType3> >(test_lgf, 13); 
    393398 
    394399  return 0; 
Note: See TracChangeset for help on using the changeset viewer.