Reputation: 8694
I have this model
min c' x
s.t.
G x <= h
x are integers or binary variables
where c
is a 16x1 numpy array of coefficients, G
is a 12 x 16
matrix that represents the constraints of the model and h
is 12x1 array of ones.
::::::::::::::
c
::::::::::::::
-0.00
-0.38
0.12
0.12
-0.38
-0.00
0.12
0.12
0.12
0.12
-0.00
-0.38
0.12
0.12
-0.38
-0.00
::::::::::::::
G
::::::::::::::
0 1 -1 0 0 0 1 0 0 0 0 0 0 0 0 0
0 1 1 0 0 0 -1 0 0 0 0 0 0 0 0 0
0 -1 1 0 0 0 1 0 0 0 0 0 0 0 0 0
0 1 0 -1 0 0 0 1 0 0 0 0 0 0 0 0
0 1 0 1 0 0 0 -1 0 0 0 0 0 0 0 0
0 -1 0 1 0 0 0 1 0 0 0 0 0 0 0 0
0 0 1 -1 0 0 0 0 0 0 0 1 0 0 0 0
0 0 1 1 0 0 0 0 0 0 0 -1 0 0 0 0
0 0 -1 1 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 1 -1 0 0 0 1 0 0 0 0
0 0 0 0 0 0 1 1 0 0 0 -1 0 0 0 0
0 0 0 0 0 0 -1 1 0 0 0 1 0 0 0 0
::::::::::::::
h
::::::::::::::
1
1
1
1
1
1
1
1
1
1
1
1
From the cvxopt documentation I'd think that the model should be implemented as a linear program and be solved with lp solver
cvxopt.solvers.lp(c=cvxopt.matrix(c), G=cvxopt.matrix(G), h=cvxopt.matrix(h) )
but I get this error:
/usr/local/lib/python2.7/dist-packages/cvxopt/coneprog.pyc in lp(c, G, h, A, b, solver, primalstart, dualstart)
3006
3007 return conelp(c, G, h, {'l': m, 'q': [], 's': []}, A, b, primalstart,
-> 3008 dualstart)
3009
3010
/usr/local/lib/python2.7/dist-packages/cvxopt/coneprog.pyc in conelp(c, G, h, dims, A, b, primalstart, dualstart, kktsolver, xnewcopy, xdot, xaxpy, xscal, ynewcopy, ydot, yaxpy, yscal)
572 if kktsolver in defaultsolvers:
573 if b.size[0] > c.size[0] or b.size[0] + cdim_pckd < c.size[0]:
--> 574 raise ValueError("Rank(A) < p or Rank([G; A]) < n")
575 if kktsolver == 'ldl':
576 factor = misc.kkt_ldl(G, dims, A, kktreg = KKTREG)
ValueError: Rank(A) < p or Rank([G; A]) < n
while using the glpk interface of cvxopt actually works smoothly and it gives me good solutions:
(status, sol) = cvxopt.glpk.ilp(c=cvxopt.matrix(c), # c parameter
G=cvxopt.matrix(G), # G parameter
h=cvxopt.matrix(h), # h parameter
I=set(range(0, len(c))),
B=set(range(0, len(c)))
)
How can I make lp solver work in cvxopt for this problem?
Upvotes: 0
Views: 5423
Reputation: 53
I am not entirely sure, but I think, the problem is more a mathematical problem than based on the code.
The dimensions of your matrices are c
is 16 x 1
, G
is 16 x 12
and h
is 12 x 1
. But the rank of matrix G
is much lower. In fact, on ten of the 16 entries of x
there are no constraints. To the program, it is an infeasible solution as the minimum would be minus infinity.
E.g. for x[14]
are no constraints in G
and h
, it could be any value. In the minimizing function c[14] = -0.38
, therefore a minimizing value would be x[14] = +inf
which gives the solution -inf = min c'x
This is the explanation of the error as you described it:
ValueError: Rank(A) < p or Rank([G; A]) < n
This part of code appears at different parts and usually checks the dimension of the problem and determines, whether there are enough constraints to solve the problem.
I solved the problem but omitted any unconstrained values of x. The result is still unfeasible, but that might be due to the constraints or some other error...
[Previous definition of the matrices]
>>> index = [1,2,3,6,7,11]
>>> c = c[index]
>>> G = G[::,index]
>>> cv.solvers.lp(c=c, G=G, h=h )
pcost dcost gap pres dres k/t
0: -2.8000e-01 -1.3000e+01 1e+01 1e+00 5e+00 1e+00
1: -1.7954e-01 -1.6503e+00 1e+00 1e-01 6e-01 7e-03
2: 1.0328e-01 -1.5888e+01 1e+03 1e+00 6e+00 8e-01
3: -1.1620e+01 -3.8498e+00 5e+03 3e-01 1e+00 1e+01
4: -1.1605e+03 -3.8498e+00 5e+05 3e-01 1e+00 1e+03
5: -1.1604e+05 -3.8498e+00 5e+07 3e-01 1e+00 1e+05
6: -1.1604e+07 -3.8498e+00 5e+09 3e-01 1e+00 1e+07
7: -1.1604e+09 -3.8498e+00 5e+11 3e-01 1e+00 1e+09
Certificate of dual infeasibility found.
{'status': 'dual infeasible', 'dual slack': None, 'iterations': 7, 'residual as primal
infeasibility certificate': None, 'relative gap': None, 'dual objective': None,
'residual as dual infeasibility certificate': 1.1035651154462114e-09, 'gap': None,
's': <12x1 matrix, tc='d'>, 'primal infeasibility': None, 'dual infeasibility': None,
'primal objective': -1.0, 'primal slack': 94.0289560690342, 'y': None, 'x': <6x1
matrix, tc='d'>, 'z': None}
Feel free to correct me, if I'm wrong.
Upvotes: 0