diff --git a/constraint/constraints.py b/constraint/constraints.py index 9a2ce80..2b669c6 100644 --- a/constraint/constraints.py +++ b/constraint/constraints.py @@ -496,8 +496,12 @@ def __call__(self, variables: Sequence, domains: dict, assignments: dict, forwar if temp_sum > target_value: domain.hideValue(value) else: + # sum_value already includes min(domain) as a placeholder for this + # unassigned variable; subtract it before adding the candidate value + # to avoid double-counting. + var_placeholder = min(domain) for value in domain[:]: - temp_sum = sum_value + value + temp_sum = sum_value - var_placeholder + value if temp_sum > target_value: domain.hideValue(value) if not domain: