dimod.ConstrainedQuadraticModel.add_constraint_from_model

ConstrainedQuadraticModel.add_constraint_from_model(qm: Union[dimod.binary.binary_quadratic_model.BinaryQuadraticModel, dimod.quadratic.quadratic_model.QuadraticModel], sense: Union[dimod.sym.Sense, str], rhs: Union[int, float, numpy.number] = 0, label: Optional[Hashable] = None, copy: bool = True) Hashable[source]

Add a constraint from a quadratic model.

Parameters
  • qm – A quadratic model or binary quadratic model.

  • sense – One of `<=’, ‘>=’, ‘==’.

  • rhs – The right hand side of the constraint.

  • label – A label for the constraint. Must be unique. If no label is provided, then one is generated using uuid.

  • copy – If True, the BQM is copied. This can be set to False to improve performance, but subsequently mutating the bqm can cause issues.

Returns

The label of the added constraint.

Examples

>>> from dimod import ConstrainedQuadraticModel, Binary
>>> cqm = ConstrainedQuadraticModel()
>>> x = Binary('x')
>>> cqm.add_constraint_from_model(x, '>=', 0, 'Min x')
'Min x'