cvxopt.glpk.ilp 文档

cvxopt.glpk.ilp Documentation

我看到 CVXOPT 支持 GLPK,可以这样做:

from cvxopt.glpk import ilp

但是,我在 cvxopt 的文档中找不到 glpk 模块的文档。我正在尝试解决一个整数程序,我想了解 ilp 接口。

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 variables