我已经看到CVXOPT支持GLPK,可以这样做:
from cvxopt.glpk import ilp但是,我在cvxopt的文档中找不到glpk模块的文档。我试图解决一个整数程序,我想了解ilp接口。
发布于 2020-02-15 22:34:49
cvxopt.glpk使用GLPK解决了ilp问题。
考虑以下LP:
Min -3x1 -x2
x1 + x2 <= 10
- x2 <= -4.5这变成(假设首先是x1,x2小数,然后是整数)。
>>> c = matrix(np.array([-3,-1],dtype=float))
>>> h = matrix(np.array([10,-4.5],dtype=float))
>>> G = matrix(np.array([[1,1],[0,-1]],dtype=float))
>>> (status,x) = ilp(c=c,G=G,h=h)
>>> print(x)
[ 5.50e+00]
[ 4.50e+00]
>>> (status,x) = ilp(c=c,G=G,h=h,I=set(range(2)))
>>> print(x)
[ 5.00e+00]
[ 5.00e+00]有关其他信息,请参阅文档
>>> help(ilp)
PURPOSE
Solves the mixed integer linear programming problem
minimize c'*x
subject to G*x <= h
A*x = b
x[k] is integer for k in I
x[k] is binary for k in B
ARGUMENTS
c nx1 dense 'd' matrix with n>=1
G mxn dense or sparse 'd' matrix with m>=1
h mx1 dense 'd' matrix
A pxn dense or sparse 'd' matrix with p>=0
b px1 dense 'd' matrix
I set of indices of integer variables
B set of indices of binary variableshttps://stackoverflow.com/questions/60243511
复制相似问题