Search code examples
pythonmathematical-optimizationlinear-programmingcvxopt

cvxopt.glpk.ilp Documentation


I've seen that CVXOPT supports GLPK and one can do:

from cvxopt.glpk import ilp

However, I cannot find the documentation for the glpk module in cvxopt's documentation. I am trying to solve an integer program and I want to understand the ilp interface.


Solution

  • cvxopt.glpk solves ilp by using GLPK.
    Consider the following LP:

    Min -3x1 -x2
     x1 + x2 <= 10
        - x2 <= -4.5
    

    This becomes (assuming first x1,x2 fractional, and then integers).

    >>> 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]
    

    For additional information you can refer to the documentation

    >>> 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