binary linear programming solver in Python

前端 未结 2 1915
天涯浪人
天涯浪人 2021-01-01 19:11

I have a Python script in which I need to solve a linear programming problem. The catch is that the solution must be binary. In other words, I need an equivalent of MATLAB\'

2条回答
  •  自闭症患者
    2021-01-01 19:27

    Just to be rigorous, if the problem is a binary programming problem, then it is not a linear program.

    You can try CVXOPT. It has a integer programming function (see this). To make your problem a binary program, you need to add the constrain 0 <= x <= 1.

    Edit: You can actually declare your variable as binary, so you don't need to add the constrain 0 <= x <= 1.

    cvxopt.glpk.ilp = ilp(...)
    Solves a mixed integer linear program using GLPK.
    
    (status, x) = ilp(c, G, h, A, b, I, B)
    
    PURPOSE
    Solves the mixed integer linear programming problem
    
        minimize    c'*x
        subject to  G*x <= h
                    A*x = b
                    x[I] are all integer
                    x[B] are all binary
    

提交回复
热议问题