dimod.BinaryQuadraticModel.fix_variable

BinaryQuadraticModel.fix_variable(v, value)[source]

Fix the value of a variable and remove it from a binary quadratic model.

Parameters:
  • v (variable) – Variable in the binary quadratic model to be fixed.
  • value (int) – Value assigned to the variable. Values must match the Vartype of the binary quadratic model.

Examples

This example creates a binary quadratic model with one variable and fixes its value.

>>> import dimod
...
>>> bqm = dimod.BinaryQuadraticModel({'a': -.5, 'b': 0.}, {('a', 'b'): -1}, 0.0, dimod.SPIN)
>>> bqm.fix_variable('a', -1)
>>> bqm.offset
0.5
>>> bqm.linear['b']
1.0
>>> 'a' in bqm
False