dimod.DiscreteQuadraticModel.add_variable

DiscreteQuadraticModel.add_variable(num_cases, label=None)[source]

Add a discrete variable.

Parameters
  • num_cases (int) – The number of cases in the variable. Must be a positive integer.

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

Returns

The label of the new variable.

Raises
  • ValueError – If label already exists as a variable label.

  • TypeError – If label is not hashable.