I am trying to find an lp solution to the following problem and even though I can construct feasible points by hand , I seem to get a infeasible certificate from cvxopt. Below is the example and snippet of code
import numpy as np
from cvxopt import solvers, matrix
A = np.array([[0.221, -11.76, -1], [0.2017, -9.88, -1], [0.176, -8.045,
-1], [0.253, 1.72, 0.]])
print(A)
[[ 0.221 -11.76 -1. ]
[ 0.2017 -9.88 -1. ]
[ 0.176 -8.045 -1. ]
[ 0.253 1.72 0. ]]
b = np.array([-147459573, -139576175, -131383060, 20e6])
x0 = np.array([0.,0.,-np.min(b)])
x1 = np.array([20.e6,8.0e6,71e6])
y0 = np.dot(A,x0)
print(y0<=b)
[ True True True True]
y1 = np.dot(A,x1)
print(y1 <= b)
[ True True True True]
c = np.array([0.,0.,1.])
A = matrix(A)
b = matrix(b)
c = matrix(c)
res = solvers.lp(c,A,b)
pcost dcost gap pres dres k/t
0: 1.0031e+08 1.4805e+09 4e+06 2e-03 1e+02 1e+00
Certificate of primal infeasibility found.
As one can see from above x0, x1 clearly are in the feasible set but the solution seems to say that primal is infeasible. Am I looking at this wrong ?
Problem
Your problem is very badly scaled as there are very large and very small coefficients. As all those solvers are working with limited-precision floats, this introduces numerical-instabilities.
The usual approach then is problem scaling or reformulation. There are tons of books and probably papers too (mostly in some chapter about preprocessing), but i'm just citing Mosek's docs here as this is readily available:
Painless alternative (at least for this problem)
Although ecos (conic solver; open-source) is ready to solve much more complex problems, it seems to do much better preprocessing here and can solve your problem. The modelling-framework which is calling ecos is cvxpy:
Output:
Mosek should be able to solve this too!