dimod.ConstrainedQuadraticModel.remove_constraint#
- ConstrainedQuadraticModel.remove_constraint(label: Hashable, *, cascade: bool = False)[source]#
Remove a constraint from the model.
- Parameters:
label – Label of the constraint to remove.
cascade – If set to True, also removes any variables found only in the removed constraint that contribute no energy to the objective.
Examples
This example also removes variable
kfrom the model when removing the constraint while keeping the variables used in the objective.>>> cqm = dimod.ConstrainedQuadraticModel() >>> i, j, k = dimod.Integers(["i", "j", "k"]) >>> cqm.set_objective(2 * i - 3 * i * j) >>> cqm.add_constraint_from_comparison(i * k - 2 * j <= 4, label="C1") 'C1' >>> cqm.remove_constraint("C1", cascade=True) >>> cqm.variables Variables(['i', 'j'])