| 297 | friend class MinCutNodeIt; |
| 298 | |
| 299 | class MinCutNodeIt |
| 300 | { |
| 301 | bool _side; |
| 302 | typename Graph::NodeIt _node_it; |
| 303 | typename Graph::template NodeMap<bool> _cut; |
| 304 | public: |
| 305 | MinCutNodeIt(GomoryHuTree const &gomory, |
| 306 | const Node& s, const Node& t, bool side=true) |
| 307 | : _side(side), _cut(gomory._graph) |
| 308 | { |
| 309 | gomory.minCutMap(s,t,_cut); |
| 310 | for(_node_it=typename Graph::NodeIt(gomory._graph); |
| 311 | _node_it!=INVALID && _cut[_node_it]!=_side; |
| 312 | ++_node_it) {} |
| 313 | } |
| 314 | operator typename Graph::Node() const |
| 315 | { |
| 316 | return _node_it; |
| 317 | } |
| 318 | bool operator==(Invalid) { return _node_it==INVALID; } |
| 319 | bool operator!=(Invalid) { return _node_it!=INVALID; } |
| 320 | ///Next node |
| 321 | MinCutNodeIt &operator++() |
| 322 | { |
| 323 | for(++_node_it;_node_it!=INVALID&&_cut[_node_it]!=_side;++_node_it) {} |
| 324 | return *this; |
| 325 | } |
| 326 | ///Postfix incrementation |
| 327 | |
| 328 | ///\warning This incrementation |
| 329 | ///returns a \c Node, not a \ref MinCutNodeIt, as one may |
| 330 | ///expect. |
| 331 | typename Graph::Node operator++(int) |
| 332 | { |
| 333 | typename Graph::Node n=*this; |
| 334 | ++(*this); |
| 335 | return n; |
| 336 | } |
| 337 | }; |
| 338 | |
| 339 | friend class MinCutArcIt; |
| 340 | |
| 341 | class MinCutArcIt |
| 342 | { |
| 343 | bool _side; |
| 344 | const Graph &_graph; |
| 345 | typename Graph::NodeIt _node_it; |
| 346 | typename Graph::OutArcIt _arc_it; |
| 347 | typename Graph::template NodeMap<bool> _cut; |
| 348 | void step() |
| 349 | { |
| 350 | ++_arc_it; |
| 351 | while(_node_it!=INVALID && _arc_it==INVALID) |
| 352 | { |
| 353 | for(++_node_it;_node_it!=INVALID&&!_cut[_node_it];++_node_it) {} |
| 354 | if(_node_it!=INVALID) |
| 355 | _arc_it=typename Graph::OutArcIt(_graph,_node_it); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | public: |
| 360 | MinCutArcIt(GomoryHuTree const &gomory, |
| 361 | const Node& s, const Node& t, bool side=true) |
| 362 | : _graph(gomory._graph), _cut(_graph) |
| 363 | { |
| 364 | gomory.minCutMap(s,t,_cut); |
| 365 | if(!side) |
| 366 | for(typename Graph::NodeIt n(_graph);n!=INVALID;++n) |
| 367 | _cut[n]=!_cut[n]; |
| 368 | |
| 369 | for(_node_it=typename Graph::NodeIt(_graph); |
| 370 | _node_it!=INVALID && !_cut[_node_it]; |
| 371 | ++_node_it) {} |
| 372 | _arc_it = _node_it!=INVALID ? |
| 373 | typename Graph::OutArcIt(_graph,_node_it) : INVALID; |
| 374 | while(_node_it!=INVALID && _arc_it == INVALID) |
| 375 | { |
| 376 | for(++_node_it; _node_it!=INVALID&&!_cut[_node_it]; ++_node_it) {} |
| 377 | if(_node_it!=INVALID) |
| 378 | _arc_it= typename Graph::OutArcIt(_graph,_node_it); |
| 379 | } |
| 380 | while(_arc_it!=INVALID && _cut[_graph.target(_arc_it)]) step(); |
| 381 | } |
| 382 | operator typename Graph::Arc() const |
| 383 | { |
| 384 | return _arc_it; |
| 385 | } |
| 386 | operator typename Graph::Edge() const |
| 387 | { |
| 388 | return _arc_it; |
| 389 | } |
| 390 | bool operator==(Invalid) { return _node_it==INVALID; } |
| 391 | bool operator!=(Invalid) { return _node_it!=INVALID; } |
| 392 | ///Next node |
| 393 | MinCutArcIt &operator++() |
| 394 | { |
| 395 | step(); |
| 396 | while(_arc_it!=INVALID && _cut[_graph.target(_arc_it)]) step(); |
| 397 | return *this; |
| 398 | } |
| 399 | ///Postfix incrementation |
| 400 | |
| 401 | ///\warning This incrementation |
| 402 | ///returns a \c Arc, not a \ref MinCutArcIt, as one may |
| 403 | ///expect. |
| 404 | typename Graph::Arc operator++(int) |
| 405 | { |
| 406 | typename Graph::Arc a=*this; |
| 407 | ++(*this); |
| 408 | return a; |
| 409 | } |
| 410 | }; |
| 411 | |