lemon/preflow.h
branch1.3
changeset 1133 85d6e26096ef
parent 1080 c5cd8960df74
child 1163 8db773f19586
equal deleted inserted replaced
31:344735a2ec7e 32:9896955d82d0
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     4  *
     5  * Copyright (C) 2003-2010
     5  * Copyright (C) 2003-2013
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
     9  * Permission to use, modify and distribute this software is granted
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    10  * provided that this copyright notice appears in all copies. For
   552           if ((*_level)[v] == _level->maxLevel()) continue;
   552           if ((*_level)[v] == _level->maxLevel()) continue;
   553           _flow->set(e, 0);
   553           _flow->set(e, 0);
   554           (*_excess)[v] += rem;
   554           (*_excess)[v] += rem;
   555         }
   555         }
   556       }
   556       }
   557       for (NodeIt n(_graph); n != INVALID; ++n) 
   557       for (NodeIt n(_graph); n != INVALID; ++n)
   558         if(n!=_source && n!=_target && _tolerance.positive((*_excess)[n]))
   558         if(n!=_source && n!=_target && _tolerance.positive((*_excess)[n]))
   559           _level->activate(n);
   559           _level->activate(n);
   560           
   560 
   561       return true;
   561       return true;
   562     }
   562     }
   563 
   563 
   564     /// \brief Starts the first phase of the preflow algorithm.
   564     /// \brief Starts the first phase of the preflow algorithm.
   565     ///
   565     ///
   583         while (num > 0) {
   583         while (num > 0) {
   584           n = _level->highestActive();
   584           n = _level->highestActive();
   585           if (n == INVALID) goto first_phase_done;
   585           if (n == INVALID) goto first_phase_done;
   586           level = _level->highestActiveLevel();
   586           level = _level->highestActiveLevel();
   587           --num;
   587           --num;
   588           
   588 
   589           Value excess = (*_excess)[n];
   589           Value excess = (*_excess)[n];
   590           int new_level = _level->maxLevel();
   590           int new_level = _level->maxLevel();
   591 
   591 
   592           for (OutArcIt e(_graph, n); e != INVALID; ++e) {
   592           for (OutArcIt e(_graph, n); e != INVALID; ++e) {
   593             Value rem = (*_capacity)[e] - (*_flow)[e];
   593             Value rem = (*_capacity)[e] - (*_flow)[e];