diff options
author | Nao Pross <np@0hm.ch> | 2024-06-07 16:30:21 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-06-07 16:30:21 +0200 |
commit | 100714f857bc22e21243284373172bf7b81245d2 (patch) | |
tree | a833da8f544602d70fc3f86cc28bb052b11133bf | |
parent | Add ExpCone support in solver.scs (diff) | |
download | sumofsquares-100714f857bc22e21243284373172bf7b81245d2.tar.gz sumofsquares-100714f857bc22e21243284373172bf7b81245d2.zip |
Fix bug in elimination of constraints that disappear
-rw-r--r-- | sumofsquares/problems.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/sumofsquares/problems.py b/sumofsquares/problems.py index fb25fd9..e6ca747 100644 --- a/sumofsquares/problems.py +++ b/sumofsquares/problems.py @@ -376,6 +376,17 @@ class InternalSOSProblem(Problem): constr = poly.to_affine(c.expression) nrows, ncols = constr.shape + # There is only one "variable" in the affine expression + if len(constr.slices.keys()) == 1: + # That variable is actually not a variable + if MonomialIndex.constant() in constr.slices.keys(): + # constraint has disappeared + continue + # FIXME: need to check for each type of constraint + # that it is ok to remove constant value. Example of + # a problematic edge case is NonNegative(a - a - 5) + # where a is an optimization variable. + if constr.degree > 1: # If this error occurs an it is not the user's fault, there is # a bug in SOSProblem.apply @@ -385,12 +396,7 @@ class InternalSOSProblem(Problem): # Get constant and linear terms constant = constr.affine_coefficient(MonomialIndex.constant()) linear = tuple(constr.affine_coefficient(v) for v in variable_indices) - - # constraint has disappeared - if not (np.any(constant) or np.any(linear)): - # print("Constraint disappeared!") - continue - + if isinstance(c, EqualToZero): dims["z"].append(nrows) constraints["z"].append((linear, constant)) |