Fixed bounds computation in get_or_make_var for wsum
@@ -330,8 +330,9 @@ def get_or_make_var(expr):
elif isinstance(expr, Operator) and expr.name == "wsum":
weights, sub_exprs = expr.args
flatvars, flatcons = zip(*[get_or_make_var(arg) for arg in sub_exprs]) # also bool, reified...
- lb = sum(weight * fvar.lb for fvar, weight in zip(flatvars, weights))
- ub = sum(weight * fvar.ub for fvar, weight in zip(flatvars, weights))
+ bounds = np.array([[w * fvar.lb for w, fvar in zip(weights, flatvars)],
+ [w * fvar.ub for w, fvar in zip(weights, flatvars)]])
+ lb, ub = bounds.min(axis=1).sum(), bounds.max(axis=1).sum()
ivar = _IntVarImpl(lb, ub)
newexpr = (Operator(expr.name, (weights, flatvars)) == ivar)
return (ivar, [newexpr]+[c for con in flatcons for c in con])
