Improve tree update procedure in NetworkSimplex
authorkpeter
Thu, 13 Nov 2008 10:54:42 +0000
changeset 262874520139e388
parent 2627 197e2ea11bad
child 2629 84354c78b068
Improve tree update procedure in NetworkSimplex
The new method updates a smaller subtree (fixing a bug) and shifting the
potentials with a costant value.
lemon/network_simplex.h
     1.1 --- a/lemon/network_simplex.h	Fri Nov 07 20:15:10 2008 +0000
     1.2 +++ b/lemon/network_simplex.h	Thu Nov 13 10:54:42 2008 +0000
     1.3 @@ -1133,20 +1133,14 @@
     1.4      /// Update \c depth and \c potential node maps.
     1.5      inline void updateDepthPotential() {
     1.6        _depth[u_in] = _depth[v_in] + 1;
     1.7 -      _potential[u_in] = _forward[u_in] ?
     1.8 -        _potential[v_in] - _cost[_pred_edge[u_in]] :
     1.9 -        _potential[v_in] + _cost[_pred_edge[u_in]];
    1.10 -
    1.11 -      Node u = _thread[u_in], v;
    1.12 -      while (true) {
    1.13 -        v = _parent[u];
    1.14 -        if (v == INVALID) break;
    1.15 -        _depth[u] = _depth[v] + 1;
    1.16 -        _potential[u] = _forward[u] ?
    1.17 -          _potential[v] - _cost[_pred_edge[u]] :
    1.18 -          _potential[v] + _cost[_pred_edge[u]];
    1.19 -        if (_depth[u] <= _depth[v_in]) break;
    1.20 -        u = _thread[u];
    1.21 +      Cost sigma = _forward[u_in] ?
    1.22 +        _potential[v_in] - _potential[u_in] - _cost[_pred_edge[u_in]] :
    1.23 +        _potential[v_in] - _potential[u_in] + _cost[_pred_edge[u_in]];
    1.24 +      _potential[u_in] += sigma;
    1.25 +      for(Node u = _thread[u_in]; _parent[u] != INVALID; u = _thread[u]) {
    1.26 +        _depth[u] = _depth[_parent[u]] + 1;
    1.27 +        if (_depth[u] <= _depth[u_in]) break;
    1.28 +        _potential[u] += sigma;
    1.29        }
    1.30      }
    1.31