dimod.BinaryQuadraticModel.flip_variable

BinaryQuadraticModel.flip_variable(v)[source]

Flip variable v in a binary quadratic model.

Parameters:v (variable) – Variable in the binary quadratic model. If v is not in the binary quadratic model, it is ignored.

Examples

This example creates a binary quadratic model with two variables and inverts the value of one.

>>> import dimod
...
>>> bqm = dimod.BinaryQuadraticModel({1: 1, 2: 2}, {(1, 2): 0.5}, 0.5, dimod.SPIN)
>>> bqm.flip_variable(1)
>>> bqm.linear[1], bqm.linear[2], bqm.quadratic[(1, 2)]
(-1.0, 2, -0.5)