Python中的二进制线性规划求解器 [英] binary linear programming solver in Python
问题描述
我有一个Python脚本,需要在其中解决线性编程问题.问题是解决方案必须是二进制的.换句话说,我需要等效于MATLAB的 bintprog 函数. NumPy和SciPy似乎没有这样的过程.有人对我如何做以下三件事之一有建议吗?
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's bintprog function. NumPy and SciPy do not seem to have such a procedure. Does anyone have suggestions on how I could do one of these three things:
-
找到一个包含此类功能的Python库.
Find a Python library which includes such a function.
约束该问题,以便可以使用更通用的线性规划求解器解决该问题.
Constrain the problem such that it can be solved by a more general linear programming solver.
Python与MATLAB接口,以便直接使用 bintprog .
Interface Python with MATLAB so as to make direct use of bintprog.
推荐答案
严格来说,如果问题是二进制编程问题,那么它不是线性程序.
Just to be rigorous, if the problem is a binary programming problem, then it is not a linear program.
您可以尝试 CVXOPT .它具有整数编程功能(请参见此).要使您的问题成为二进制程序,您需要添加约束0< = x< = 1.
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.
编辑:您实际上可以将变量声明为二进制,因此无需添加约束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
这篇关于Python中的二进制线性规划求解器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!