Changeset 1166:e2732b9da429 in lemon-main
- Timestamp:
- 03/22/18 18:55:31 (7 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
test/max_flow_test.cc
r1165 r1166 183 183 184 184 template <typename T> 185 T cutValue 186 187 188 189 T c =0;190 for (SmartDigraph::ArcIt e(g); e!=INVALID; ++e) {191 if (cut[g.source(e)] && !cut[g.target(e)]) c +=cap[e];185 T cutValue(const SmartDigraph& g, 186 const SmartDigraph::NodeMap<bool>& cut, 187 const SmartDigraph::ArcMap<T>& cap) { 188 189 T c = 0; 190 for (SmartDigraph::ArcIt e(g); e != INVALID; ++e) { 191 if (cut[g.source(e)] && !cut[g.target(e)]) c += cap[e]; 192 192 } 193 193 return c; … … 218 218 } 219 219 220 void initFlowTest()220 void checkInitPreflow() 221 221 { 222 222 DIGRAPH_TYPEDEFS(SmartDigraph); 223 223 224 224 SmartDigraph g; 225 SmartDigraph::ArcMap<int> cap(g), iflow(g);226 Node s =g.addNode(); Node t=g.addNode();227 Node n1 =g.addNode(); Node n2=g.addNode();225 SmartDigraph::ArcMap<int> cap(g), iflow(g); 226 Node s = g.addNode(); Node t = g.addNode(); 227 Node n1 = g.addNode(); Node n2 = g.addNode(); 228 228 Arc a; 229 a =g.addArc(s,n1); cap[a]=20; iflow[a]=20;230 a =g.addArc(n1,n2); cap[a]=10; iflow[a]=0;231 a =g.addArc(n2,t); cap[a]=20; iflow[a]=0;232 233 Preflow<SmartDigraph> pre(g, cap,s,t);229 a = g.addArc(s, n1); cap[a] = 20; iflow[a] = 20; 230 a = g.addArc(n1, n2); cap[a] = 10; iflow[a] = 0; 231 a = g.addArc(n2, t); cap[a] = 20; iflow[a] = 0; 232 233 Preflow<SmartDigraph> pre(g, cap, s, t); 234 234 pre.init(iflow); 235 235 pre.startFirstPhase(); 236 check(pre.flowValue() == 10, "The incorrect max flow value."); 236 237 check(pre.flowValue() == 10, "Incorrect max flow value."); 237 238 check(pre.minCut(s), "Wrong min cut (Node s)."); 238 239 check(pre.minCut(n1), "Wrong min cut (Node n1)."); … … 303 304 check(max_flow.flowValue() == min_cut_value && 304 305 min_cut_value == 2 * flow_value, 305 "The max flow value or the min cut value was not doubled"); 306 306 "The max flow value or the min cut value was not doubled."); 307 307 308 308 max_flow.flowMap(flow); … … 323 323 CutMap min_cut3(g); 324 324 max_flow.minCutMap(min_cut3); 325 min_cut_value =cutValue(g, min_cut3, cap);325 min_cut_value = cutValue(g, min_cut3, cap); 326 326 327 327 check(max_flow.flowValue() == min_cut_value, … … 380 380 checkMaxFlowAlg<PType1, PreflowStartFunctions<PType1> >(); 381 381 checkMaxFlowAlg<PType2, PreflowStartFunctions<PType2> >(); 382 initFlowTest(); 382 383 checkInitPreflow(); 383 384 384 385 // Check EdmondsKarp … … 388 389 checkMaxFlowAlg<EKType2, GeneralStartFunctions<EKType2> >(); 389 390 390 initFlowTest();391 392 391 return 0; 393 392 }
Note: See TracChangeset
for help on using the changeset viewer.