diff options
-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)) |