dwavebinarycsp.Constraint.fix_variable#

Constraint.fix_variable(v, value)[source]#

Fix the value of a variable and remove it from the constraint.

Parameters:
  • v (variable) – Variable in the constraint to be set to a constant value.

  • val (int) – Value assigned to the variable. Values must match the Vartype of the constraint.

Examples

This example creates a constraint that \(a \ne b\) on binary variables, fixes variable a to 0, and tests two candidate solutions.

>>> const = dwavebinarycsp.Constraint.from_func(operator.ne,
...             ['a', 'b'], dwavebinarycsp.BINARY)
>>> const.fix_variable('a', 0)
>>> const.check({'b': 1})
True
>>> const.check({'b': 0})
False