Cvxopt.glpk.ilp文档 [英] cvxopt.glpk.ilp Documentation

查看:0
本文介绍了Cvxopt.glpk.ilp文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到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

这篇关于Cvxopt.glpk.ilp文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆