BinaryQuadraticModel.add_linear_equality_constraint(terms: Iterable[Tuple[Hashable, Union[float, numpy.floating, numpy.integer]]], lagrange_multiplier: Union[float, numpy.floating, numpy.integer], constant: Union[float, numpy.floating, numpy.integer])[source]

Add a linear constraint as a quadratic objective.

Adds a linear constraint of the form \(\sum_{i} a_{i} x_{i} + C = 0\) to the binary quadratic model as a quadratic objective.

  • terms – Values of the \(\sum_{i} a_{i} x_{i}\) term as an \(i\)–length iterable of 2-tuples, (variable, bias), with each tuple constituting a term in the summation.

  • lagrange_multiplier – Weight or penalty strength. The linear constraint is multiplied by this value (which does not appear explicitly in the above equation) when added to the binary quadratic model.

  • constant – Value of the constant term, \(C\), of the linear constraint.


>>> bqm = dimod.BinaryQuadraticModel("BINARY")
>>> bqm.add_linear_equality_constraint([("x1", 5), ("x2", -2)], 10, -3)
>>> print(bqm)
BinaryQuadraticModel({'x1': -50.0, 'x2': 160.0}, {('x2', 'x1'): -200.0}, 90.0, 'BINARY')