dimod.ConstrainedQuadraticModel.add_discrete

ConstrainedQuadraticModel.add_discrete(variables: Collection[Hashable], label: Optional[Hashable] = None) Hashable[source]

Add an iterable of binary variables as a disjoint one-hot constraint.

Adds a special kind of one-hot constraint. These one-hot constraints must be disjoint, that is they must not have any overlapping variables.

Parameters
  • variables – An iterable of variables.

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

Returns

Label of the added constraint.

Raises
  • ValueError – If any of the given variables have already been added to the model with any vartype other than BINARY.

  • ValueError – If any of the given variables are already used in another discrete variable.