我有这个模型
min c' x
s.t.
G x <= h
x are integers or binary variables
其中c
是 16x1 numpy 系数数组,G
是12 x 16
表示模型约束的矩阵,h
是 12x1 数组。
::::::::::::::
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
从 cvxopt 文档中,我认为该模型应该实现为线性程序并使用 lp 求解器求解
cvxopt.solvers.lp(c=cvxopt.matrix(c), G=cvxopt.matrix(G), h=cvxopt.matrix(h) )
但我收到此错误:
/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
虽然使用 cvxopt 的 glpk 接口实际上工作顺利,它给了我很好的解决方案:
(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)))
)
我怎样才能让 lp 求解器在 cvxopt 中解决这个问题?