dwavebinarycsp.ConstraintSatisfactionProblem.fix_variable

ConstraintSatisfactionProblem.fix_variable(v, value)[source]

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

Parameters:
  • v (variable) – Variable to be fixed in the constraint satisfaction problem.
  • value (int) – Value assigned to the variable. Values must match the vartype of the constraint satisfaction problem.

Examples

This example creates a spin-valued constraint satisfaction problem, adds two constraints, \(a = b\) and \(b \ne c\), and fixes variable b to +1.

>>> import operator
>>> csp = dwavebinarycsp.ConstraintSatisfactionProblem(dwavebinarycsp.SPIN)
>>> csp.add_constraint(operator.eq, ['a', 'b'])
>>> csp.add_constraint(operator.ne, ['b', 'c'])
>>> csp.check({'a': +1, 'b': +1, 'c': -1})
True
>>> csp.check({'a': -1, 'b': -1, 'c': +1})
True
>>> csp.fix_variable('b', +1)
>>> csp.check({'a': +1, 'b': +1, 'c': -1})  # 'b' is ignored
True
>>> csp.check({'a': -1, 'b': -1, 'c': +1})
False
>>> csp.check({'a': +1, 'c': -1})
True
>>> csp.check({'a': -1, 'c': +1})
False