dimod.CaseLabelDQM.add_variable#

CaseLabelDQM.add_variable(cases, label=None, shared_labels=False)[source]#

Add a discrete variable to the model.

Parameters:
  • cases (int or iterable) – The number of cases in the variable, or an iterable containing the labels that will identify the cases of the variable. Case labels can be any hashable.

  • label (hashable, optional) – A label for the variable. Can be any hashable except None. Defaults to the length of the discrete quadratic model, if that label is available. Otherwise defaults to the lowest available positive integer label.

  • shared_labels (bool, optional, default=False) – If True and cases is an iterable, shared case labels are created. If False and cases is an iterable, unique case labels are created. If cases is not an iterable, ignored.

Returns:

The label of the new variable.

Raises:
  • ValueError – If label already exists as a variable label, or if any of the case labels is not unique.

  • TypeError – If label is not hashable, or if any of the case labels is not hashable.