Search code examples
pythonglpkcvxopt

cvxopt custom installation with non default Visual studio


I'm trying to install glpk support for cvxopt, but ran into problem that cvxopt is using VS 2017, while my glpk is build on VS 2015. I'm installing cvxopt from source using command 'python setup.py install'. In setup.py I've added parameter 'BUILD_GLPK = 1' to install package with gltk support. GLTK is already installed on my machine and path to it is specified in setup.py of cvxopt. One more thing, I have several VS installed on my computer. Now what I'm encountering is that during cvxopt installation python uses Built Tools 2017 what lead to an error. I think this is because it is using VS 2017 as default. Is there any way to change it and try setup.py again?

Many thanks for help and advices


Solution

  • GLPK can only be build with VS 15 (Visual Studio 2015). But there is one more issue. If trying to ran the following code the program will fail to find glpk

       import cvxopt
    
    c=cvxopt.matrix([0,-1],tc='d')
    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)=cvxopt.glpk.ilp(c,G.T,h,I=set([0,1]))
    

    But if you first use cvxopt solver everything will run smoothly:

    from cvxopt import matrix, solvers
    A = matrix([ [-1.0, -1.0, 0.0, 1.0], [1.0, -1.0, -1.0, -2.0] ])
    b = matrix([ 1.0, -2.0, 0.0, 4.0 ])
    c = matrix([ 2.0, 1.0 ])
    sol=solvers.lp(c,A,b,solver='glpk')
    print(list(sol['x']))
    
    sol=solvers.lp(c,A,b)
    print(list(sol['x']))
    
    (status, x)=cvxopt.glpk.ilp(c,A,b,I=set([0,1]))
    

    So I would say that there is some bug when loading glpk for cvxopt.