# HG changeset patch
# User Alpar Juttner <alpar@cs.elte.hu>
# Date 1323499932 -3600
# Node ID 23a4fa3a7e62e25da2995751932d62fc7fb8884e
# Parent 9a716871028e3ccf95f14b603956f1f7ff03892a
Remember the lastly evaluated arcs in Circulation (#431)
diff --git a/lemon/circulation.h b/lemon/circulation.h
a
|
b
|
|
236 | 236 | typedef typename Digraph::template NodeMap<Value> ExcessMap; |
237 | 237 | ExcessMap* _excess; |
238 | 238 | |
| 239 | typename Digraph::template NodeMap<Arc> _next_arc; |
| 240 | |
239 | 241 | Tolerance _tol; |
240 | 242 | int _el; |
241 | 243 | |
… |
… |
|
344 | 346 | const UpperMap &upper, const SupplyMap &supply) |
345 | 347 | : _g(graph), _lo(&lower), _up(&upper), _supply(&supply), |
346 | 348 | _flow(NULL), _local_flow(false), _level(NULL), _local_level(false), |
347 | | _excess(NULL) {} |
| 349 | _excess(NULL), _next_arc(graph) {} |
348 | 350 | |
349 | 351 | /// Destructor. |
350 | 352 | ~Circulation() { |
… |
… |
|
574 | 576 | Node act; |
575 | 577 | Node bact=INVALID; |
576 | 578 | Node last_activated=INVALID; |
| 579 | |
| 580 | for(NodeIt n(_g);n!=INVALID;++n) |
| 581 | if((_next_arc[n]=OutArcIt(_g,n))==INVALID) |
| 582 | _next_arc[n]=InArcIt(_g,n); |
| 583 | |
577 | 584 | while((act=_level->highestActive())!=INVALID) { |
578 | 585 | int actlevel=(*_level)[act]; |
579 | | int mlevel=_node_num; |
580 | 586 | Value exc=(*_excess)[act]; |
581 | 587 | |
582 | | for(OutArcIt e(_g,act);e!=INVALID; ++e) { |
| 588 | Arc next_a = _next_arc[act]; |
| 589 | if(next_a == INVALID) goto next_l; |
| 590 | if (_g.source(next_a)!=act) |
| 591 | goto next_in; |
| 592 | for(OutArcIt e(_g,next_a);e!=INVALID; ++e) { |
583 | 593 | Node v = _g.target(e); |
584 | 594 | Value fc=(*_up)[e]-(*_flow)[e]; |
585 | 595 | if(!_tol.positive(fc)) continue; |
… |
… |
|
591 | 601 | _level->activate(v); |
592 | 602 | (*_excess)[act] = 0; |
593 | 603 | _level->deactivate(act); |
| 604 | _next_arc[act]=e; |
594 | 605 | goto next_l; |
595 | 606 | } |
596 | 607 | else { |
… |
… |
|
601 | 612 | exc-=fc; |
602 | 613 | } |
603 | 614 | } |
604 | | else if((*_level)[v]<mlevel) mlevel=(*_level)[v]; |
605 | 615 | } |
606 | | for(InArcIt e(_g,act);e!=INVALID; ++e) { |
| 616 | next_a = InArcIt(_g,act); |
| 617 | next_in: |
| 618 | for(InArcIt e(_g,next_a);e!=INVALID; ++e) { |
607 | 619 | Node v = _g.source(e); |
608 | 620 | Value fc=(*_flow)[e]-(*_lo)[e]; |
609 | 621 | if(!_tol.positive(fc)) continue; |
… |
… |
|
615 | 627 | _level->activate(v); |
616 | 628 | (*_excess)[act] = 0; |
617 | 629 | _level->deactivate(act); |
| 630 | _next_arc[act]=e; |
618 | 631 | goto next_l; |
619 | 632 | } |
620 | 633 | else { |
… |
… |
|
625 | 638 | exc-=fc; |
626 | 639 | } |
627 | 640 | } |
628 | | else if((*_level)[v]<mlevel) mlevel=(*_level)[v]; |
629 | 641 | } |
630 | 642 | |
| 643 | if((_next_arc[act]=OutArcIt(_g,act))==INVALID) |
| 644 | _next_arc[act]=InArcIt(_g,act); |
| 645 | |
631 | 646 | (*_excess)[act] = exc; |
632 | 647 | if(!_tol.positive(exc)) _level->deactivate(act); |
633 | | else if(mlevel==_node_num) { |
634 | | _level->liftHighestActiveToTop(); |
635 | | _el = _node_num; |
636 | | return false; |
637 | | } |
638 | 648 | else { |
639 | | _level->liftHighestActive(mlevel+1); |
640 | | if(_level->onLevel(actlevel)==0) { |
641 | | _el = actlevel; |
| 649 | int mlevel=_node_num; |
| 650 | Node rn; |
| 651 | for(OutArcIt e(_g,act);e!=INVALID; ++e) |
| 652 | if(_tol.positive((*_up)[e]-(*_flow)[e]) && |
| 653 | (*_level)[rn = _g.runningNode(e)]<mlevel) |
| 654 | mlevel=(*_level)[rn]; |
| 655 | for(InArcIt e(_g,act);e!=INVALID; ++e) |
| 656 | if(_tol.positive((*_flow)[e]-(*_lo)[e]) && |
| 657 | (*_level)[rn = _g.runningNode(e)]<mlevel) |
| 658 | mlevel=(*_level)[rn]; |
| 659 | |
| 660 | if(mlevel==_node_num) { |
| 661 | _level->liftHighestActiveToTop(); |
| 662 | _el = _node_num; |
642 | 663 | return false; |
643 | 664 | } |
| 665 | else { |
| 666 | _level->liftHighestActive(mlevel+1); |
| 667 | if(_level->onLevel(actlevel)==0) { |
| 668 | _el = actlevel; |
| 669 | return false; |
| 670 | } |
| 671 | } |
644 | 672 | } |
645 | 673 | next_l: |
646 | 674 | ; |