Python - CVXOPT中的整数线性编程(ILP)函数未生成正确的结果

时间:2015-11-18 16:33:02

标签: python-2.7 optimization binary integer-programming

我试图使用Python 2.7上的CVXOPT库来解决https://en.wikipedia.org/wiki/Integer_programming#Example中的简单示例;最佳答案是(1,2)或(2,2)。我得到了(0.0,0.0)。我在下面的代码中做错了什么?谢谢!

import numpy as np
import cvxopt
from cvxopt import glpk

c=cvxopt.matrix([0,-1]) #-1 since we're maximising the 2nd variable
G=cvxopt.matrix([[-1,1],[3,2],[2,3],[-1,0],[0,-1]],tc='d')
h=cvxopt.matrix([1,12,12,0,0],tc='d')
(status, x)=glpk.ilp(c,G.T,h,B=set([0,1]))
print status
print x[0],x[1]    #should be (1,2) or (2,2)
print sum(c.T*x)

0 个答案:

没有答案