COIN-OR::LEMON - Graph Library

Ticket #270: circ-inf-547e6b876ee1.patch

File circ-inf-547e6b876ee1.patch, 2.7 KB (added by Peter Kovacs, 10 years ago)
  • lemon/circulation.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1240589599 -7200
    # Node ID 547e6b876ee16dec1a965c114282dc5be05e75ba
    # Parent  b95898314e095d3b9f994b1a1068518f25016745
    Support infinite capacities in Circulation + fix in the doc (#270)
    
    diff --git a/lemon/circulation.h b/lemon/circulation.h
    a b  
    119119     at the nodes.
    120120
    121121     The exact formulation of this problem is the following.
    122      Let \f$G=(V,A)\f$ be a digraph,
    123      \f$lower, upper: A\rightarrow\mathbf{R}^+_0\f$ denote the lower and
    124      upper bounds on the arcs, for which \f$0 \leq lower(uv) \leq upper(uv)\f$
     122     Let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$
     123     \f$upper: A\rightarrow\mathbf{R}\cup\{\infty\}\f$ denote the lower and
     124     upper bounds on the arcs, for which \f$lower(uv) \leq upper(uv)\f$
    125125     holds for all \f$uv\in A\f$, and \f$sup: V\rightarrow\mathbf{R}\f$
    126126     denotes the signed supply values of the nodes.
    127127     If \f$sup(u)>0\f$, then \f$u\f$ is a supply node with \f$sup(u)\f$
    128128     supply, if \f$sup(u)<0\f$, then \f$u\f$ is a demand node with
    129129     \f$-sup(u)\f$ demand.
    130      A feasible circulation is an \f$f: A\rightarrow\mathbf{R}^+_0\f$
     130     A feasible circulation is an \f$f: A\rightarrow\mathbf{R}\f$
    131131     solution of the following problem.
    132132
    133133     \f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu)
     
    503503      }
    504504
    505505      for (ArcIt e(_g);e!=INVALID;++e) {
    506         if (!_tol.positive((*_excess)[_g.target(e)] + (*_up)[e])) {
     506        if (!_tol.less(-(*_excess)[_g.target(e)], (*_up)[e])) {
    507507          _flow->set(e, (*_up)[e]);
    508508          (*_excess)[_g.target(e)] += (*_up)[e];
    509509          (*_excess)[_g.source(e)] -= (*_up)[e];
    510         } else if (_tol.positive((*_excess)[_g.target(e)] + (*_lo)[e])) {
     510        } else if (_tol.less(-(*_excess)[_g.target(e)], (*_lo)[e])) {
    511511          _flow->set(e, (*_lo)[e]);
    512512          (*_excess)[_g.target(e)] += (*_lo)[e];
    513513          (*_excess)[_g.source(e)] -= (*_lo)[e];
     
    748748    bool checkBarrier() const
    749749    {
    750750      Flow delta=0;
     751      Flow inf_cap = std::numeric_limits<Flow>::has_infinity ?
     752        std::numeric_limits<Flow>::infinity() :
     753        std::numeric_limits<Flow>::max();
    751754      for(NodeIt n(_g);n!=INVALID;++n)
    752755        if(barrier(n))
    753756          delta-=(*_supply)[n];
     
    755758        {
    756759          Node s=_g.source(e);
    757760          Node t=_g.target(e);
    758           if(barrier(s)&&!barrier(t)) delta+=(*_up)[e];
     761          if(barrier(s)&&!barrier(t)) {
     762            if (_tol.less(inf_cap - (*_up)[e], delta)) return false;
     763            delta+=(*_up)[e];
     764          }
    759765          else if(barrier(t)&&!barrier(s)) delta-=(*_lo)[e];
    760766        }
    761767      return _tol.negative(delta);