COIN-OR::LEMON - Graph Library

Ticket #372: 59b68d0e4dbd.patch

File 59b68d0e4dbd.patch, 2.4 KB (added by Balazs Dezso, 15 years ago)

Fix in preflow

  • lemon/preflow.h

    # HG changeset patch
    # User Balazs Dezso <deba@inf.elte.hu>
    # Date 1277364473 -7200
    # Node ID 59b68d0e4dbd97f5edfc200582923219be9cc2d0
    # Parent  0bca98cbebbbc65ed7baecaf7a4f68ab881e28e9
    Fix critical bug in preflow (#372)
    
    The wrong transition between the bound decrease and highest active
    heuristics caused the bug. The last node chosen in bound decrease mode
    is used in the first iteration in highest active mode.
    
    diff -r 0bca98cbebbb -r 59b68d0e4dbd lemon/preflow.h
    a b  
    576576    void startFirstPhase() {
    577577      _phase = true;
    578578
    579       Node n = _level->highestActive();
    580       int level = _level->highestActiveLevel();
    581       while (n != INVALID) {
     579      while (true) {
    582580        int num = _node_num;
    583581
    584         while (num > 0 && n != INVALID) {
     582        Node n = INVALID;
     583        int level = -1;
     584
     585        while (num > 0) {
     586          n = _level->highestActive();
     587          if (n == INVALID) goto first_phase_done;
     588          level = _level->highestActiveLevel();
     589          --num;
     590         
    585591          Value excess = (*_excess)[n];
    586592          int new_level = _level->maxLevel();
    587593
     
    647653          } else {
    648654            _level->deactivate(n);
    649655          }
    650 
    651           n = _level->highestActive();
    652           level = _level->highestActiveLevel();
    653           --num;
    654656        }
    655657
    656658        num = _node_num * 20;
    657         while (num > 0 && n != INVALID) {
     659        while (num > 0) {
     660          while (level >= 0 && _level->activeFree(level)) {
     661            --level;
     662          }
     663          if (level == -1) {
     664            n = _level->highestActive();
     665            level = _level->highestActiveLevel();
     666            if (n == INVALID) goto first_phase_done;
     667          } else {
     668            n = _level->activeOn(level);
     669          }
     670          --num;
     671
    658672          Value excess = (*_excess)[n];
    659673          int new_level = _level->maxLevel();
    660674
     
    720734          } else {
    721735            _level->deactivate(n);
    722736          }
    723 
    724           while (level >= 0 && _level->activeFree(level)) {
    725             --level;
    726           }
    727           if (level == -1) {
    728             n = _level->highestActive();
    729             level = _level->highestActiveLevel();
    730           } else {
    731             n = _level->activeOn(level);
    732           }
    733           --num;
    734737        }
    735738      }
     739    first_phase_done:;
    736740    }
    737741
    738742    /// \brief Starts the second phase of the preflow algorithm.