dimod.ConstrainedQuadraticModel.add_variable#
- ConstrainedQuadraticModel.add_variable(vartype: Literal[Vartype.SPIN, 'SPIN', Vartype.BINARY, 'BINARY', Vartype.INTEGER, 'INTEGER', Vartype.REAL, 'REAL'], v: Hashable | None = None, *, lower_bound: float | None = None, upper_bound: float | None = 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
BINARYorSPIN.upper_bound – Upper bound on the variable. Ignored when the variable is
BINARYorSPIN.
- Returns:
Variable label.
- Raises:
ValueError – If
vis already a variable in the model and thevartype,lower_bound, orupper_boundare inconsistent.
Examples
>>> from dimod import ConstrainedQuadraticModel, Integer >>> cqm = ConstrainedQuadraticModel() >>> cqm.add_variable('INTEGER', 'i') 'i'