Check restrictions in cvxpy with valid values

When solving optimization problems in cvxpy, is there a good way to verify that the constraints are valid by replacing the actual values ​​for the optimization variables?

I have a difficult optimization task (more than 100 restrictions), but I know what an optimal solution should be. However, cvxpy crashes with an error message. ValueError: Rank(A) < p or Rank([G; A]) < n I think this is because I have a typo in one of the limitations, which makes them inconsistent. Is there a good way to replace the actual values ​​for the variables to see which constraints are violated (since they probably have typos)?

My actual problem is complex, so I made a simple example:

from cvxpy import *

x = variable(name='x')
y = variable(name='y')

c1 = greater_equals(x, 1.)
c2 = greater_equals(y, 1.)
c3 = less_equals(x + y, -4.) # typo: -4 should be +4

p = program(maximize(2. * x + y), [c1, c2, c3])

p.solve()

-4 c3 +4. : Certificate of primal infeasibility found. p.show(), :

maximize 2.0*x + y
subject to
x >= 1.0
y >= 1.0
x + y <= -4.0

, (x == 3., y == 1.), , 3- ? x.value ..,

+1
1

, left , value:

x.value = 3.
y.value = 1.
for c in [c1, c2, c3]:
    constraint_text = '%s %s %s' % (c.left.value, c.type, c.right)
    print '%s becomes %s which is %s' % (c, constraint_text, eval(constraint_text))

:

x >= 1.0 becomes 3.0 >= 1.0 which is True 
y >= 1.0 becomes 1.0 >= 1.0 which is True
x + y <= -4.0 becomes 4.0 <= -4.0 which is False

- , .

+3

Source: https://habr.com/ru/post/1534694/


All Articles