# 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 at the nodes. The exact formulation of this problem is the following. Let \f$G=(V,A)\f$ be a digraph, \f$lower, upper: A\rightarrow\mathbf{R}^+_0\f$ denote the lower and upper bounds on the arcs, for which \f$0 \leq lower(uv) \leq upper(uv)\f$ Let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$ \f$upper: A\rightarrow\mathbf{R}\cup\{\infty\}\f$ denote the lower and upper bounds on the arcs, for which \f$lower(uv) \leq upper(uv)\f$ holds for all \f$uv\in A\f$, and \f$sup: V\rightarrow\mathbf{R}\f$ denotes the signed supply values of the nodes. If \f$sup(u)>0\f$, then \f$u\f$ is a supply node with \f$sup(u)\f$ supply, if \f$sup(u)<0\f$, then \f$u\f$ is a demand node with \f$-sup(u)\f$ demand. A feasible circulation is an \f$f: A\rightarrow\mathbf{R}^+_0\f$ A feasible circulation is an \f$f: A\rightarrow\mathbf{R}\f$ solution of the following problem. \f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) } for (ArcIt e(_g);e!=INVALID;++e) { if (!_tol.positive((*_excess)[_g.target(e)] + (*_up)[e])) { if (!_tol.less(-(*_excess)[_g.target(e)], (*_up)[e])) { _flow->set(e, (*_up)[e]); (*_excess)[_g.target(e)] += (*_up)[e]; (*_excess)[_g.source(e)] -= (*_up)[e]; } else if (_tol.positive((*_excess)[_g.target(e)] + (*_lo)[e])) { } else if (_tol.less(-(*_excess)[_g.target(e)], (*_lo)[e])) { _flow->set(e, (*_lo)[e]); (*_excess)[_g.target(e)] += (*_lo)[e]; (*_excess)[_g.source(e)] -= (*_lo)[e]; bool checkBarrier() const { Flow delta=0; Flow inf_cap = std::numeric_limits::has_infinity ? std::numeric_limits::infinity() : std::numeric_limits::max(); for(NodeIt n(_g);n!=INVALID;++n) if(barrier(n)) delta-=(*_supply)[n]; { Node s=_g.source(e); Node t=_g.target(e); if(barrier(s)&&!barrier(t)) delta+=(*_up)[e]; if(barrier(s)&&!barrier(t)) { if (_tol.less(inf_cap - (*_up)[e], delta)) return false; delta+=(*_up)[e]; } else if(barrier(t)&&!barrier(s)) delta-=(*_lo)[e]; } return _tol.negative(delta);