dimod.ConstrainedQuadraticModel.add_constraint_from_iterable

ConstrainedQuadraticModel.add_constraint_from_iterable(iterable: Iterable, sense: Union[dimod.sym.Sense, str], rhs: Union[int, float, numpy.number] = 0, label: Optional[Hashable] = None) Hashable[source]

Add a constraint from an iterable of tuples.

Parameters
  • iterable – An iterable of terms as tuples. The variables must have already been added to the object.

  • 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.

Returns

The label of the added constraint.

Examples

>>> from dimod import ConstrainedQuadraticModel, Integer, Binary
>>> cqm = ConstrainedQuadraticModel()
>>> cqm.add_variable('i', 'INTEGER')   
>>> cqm.add_variable('j', 'INTEGER')   
>>> cqm.add_variable('x', 'BINARY')    
>>> cqm.add_variable('y', 'BINARY')    
>>> label1 = cqm.add_constraint_from_iterable([('x', 'y', 1), ('i', 2), ('j', 3),
...                                           ('i', 'j', 1)], '<=', rhs=1)