When solving optimisation problems in cvxpy, is there a nice way to check that the constraints are valid by substituing in actual values for the optimisation variables?
I have a complicated optimisation problem (100+ constraints), but I know what the optimal solution should be. However, cvxpy fails with error message ValueError: Rank(A) < p or Rank([G; A]) < n
I think this is because I have a typo in one of the constraints, making them inconsistent. Is there a nice way to substitute actual values for the variables, to see which constraints are violated (since they probably have typos)?
My actual problem is complicated, so I've 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()
The -4
in constraint c3
should be +4
.
This fails with error message: Certificate of primal infeasibility found.
If I enter p.show()
I get:
maximize 2.0*x + y
subject to
x >= 1.0
y >= 1.0
x + y <= -4.0
Is there a value to substitue the correct solution (x == 3., y == 1.
) so see that 3rd constraint is violated? I've tried messing around with x.value
etc. but haven't found a way