dimod.ConstrainedQuadraticModel.fix_variables¶
- ConstrainedQuadraticModel.fix_variables(fixed: Union[Mapping[Hashable, float], Iterable[Tuple[Hashable, float]]], *, cascade: bool = False) Dict[Hashable, float] [source]¶
Fix the value of the variables and remove them.
- Parameters
fixed – Dictionary or iterable of 2-tuples of variable assignments.
cascade – See
fix_variable()
.
- Returns
Assignments of any additional variables fixed. For
cascade==False
, this is always{}
. If you setcascade==True
, additional variables may be fixed. Seefix_variable()
.- Raises
ValueError – If given a label for a variable not in the model.
InfeasibileModelError – If fixing the given variables results in an infeasible model. Raising this exception is currently supported for only some simple cases; variable fixes may create an infeasible model without raising this error.
Examples
>>> cqm = dimod.ConstrainedQuadraticModel() >>> r, b, g = dimod.Binaries(["red", "blue", "green"]) >>> cqm.add_discrete_from_comparison(r + b + g == 1, label="One color") 'One color' >>> cqm.fix_variables({"red": 0, "green": 0}, cascade=True) {'blue': 1}