dimod.ConstrainedQuadraticModel.add_variable

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

Add a variable to the model.

Parameters
  • variable – A variable label.

  • vartype

    Variable type. One of:

    • Vartype.SPIN, 'SPIN', {-1, 1}

    • Vartype.BINARY, 'BINARY', {0, 1}

    • Vartype.INTEGER, 'INTEGER'

  • lower_bound – A lower bound on the variable. Ignored when the variable is not Vartype.INTEGER.

  • upper_bound – An upper bound on the variable. Ignored when the variable is not Vartype.INTEGER.

Examples

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