dimod.ConstrainedQuadraticModel.add_variable

ConstrainedQuadraticModel.add_variable(vartype: Union[dimod.vartypes.Vartype, str, frozenset], v: Optional[Hashable] = None, *, lower_bound: float = 0, upper_bound: Optional[float] = None) Hashable[source]

Add a variable to the model.

Parameters
  • vartype

    Variable type. One of:

  • v – Label for the variable. Defaults to the length of the quadratic model, if that label is available. Otherwise defaults to the lowest available positive integer label.

  • lower_bound – Lower bound on the variable. Ignored when the variable is BINARY or SPIN.

  • upper_bound – Upper bound on the variable. Ignored when the variable is BINARY or SPIN.

Returns

Variable label.

Raises

ValueError – If v is already a variable in the model and the vartype, lower_bound, or upper_bound are inconsistent.

Examples

>>> from dimod import ConstrainedQuadraticModel, Integer
>>> cqm = ConstrainedQuadraticModel()
>>> cqm.add_variable('INTEGER', 'i')
'i'