Fix regression in intermediate variables

Reusing non-constant integer variables was causing constraints to
propagate in unintended ways, resulting in incorrect restrictions on the
solver's output.

This should not be an issue for constants, as they are already
restricted to one value.
This commit is contained in:
Jeremy Saklad 2022-02-15 09:55:55 -06:00
commit 497e052ad7
Signed by: Jeremy Saklad
GPG Key ID: 9CA2149583EDBF84

View File

@ -101,8 +101,8 @@ Each parameter is interpreted as a BoundedLinearExpression, and a layer of indir
`equality` must be either a LinearExp or a unary partialmethod that accepts a target integer variable and returns Constraints."""
# If expression is either an integer variable with the specified bounds or an integer constant, just pass it through
if isinstance(expression, cp_model.IntVar) and (lambda domain : domain == [lb, ub] or domain[0] == domain[1])(cp_model.IntVar.Proto(expression).domain):
# If expression is an integer constant, just pass it through
if isinstance(expression, cp_model.IntVar) and (lambda domain : domain[0] == domain[1])(cp_model.IntVar.Proto(expression).domain):
return (expression, ())
else:
return (lambda intermediate : (intermediate, self.Add(intermediate == expression)))(super().NewIntVar(lb, ub, name))