From 0a7de36807380249846036d449c61b0dc067c268 Mon Sep 17 00:00:00 2001 From: Jeremy Saklad Date: Tue, 15 Feb 2022 09:51:25 -0600 Subject: [PATCH] Create intermediate integer variables for non-constants Reusing an intermediate variable causes constraints on the intermediate to be applied to the original, which can have unintended consequences. --- bonemarketsolver/objects/bone_market_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bonemarketsolver/objects/bone_market_model.py b/bonemarketsolver/objects/bone_market_model.py index 761d025..20bcf37 100644 --- a/bonemarketsolver/objects/bone_market_model.py +++ b/bonemarketsolver/objects/bone_market_model.py @@ -104,8 +104,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: intermediate: Final[cp_model.IntVar] = super().NewIntVar(lb, ub, name)