简体   繁体   English

Python 混合整数线性规划

[英]Python Mixed Integer Linear Programming

Are there any Mixed Integer Linear Programming(MILP) solver for Python?是否有适用于 Python 的混合整数线性规划(MILP)求解器?

Can GLPK python solve MILP problem? GLPK python可以解决MILP问题吗? I read that it can solve Mixed integer problem.我读到它可以解决混合整数问题。
I am very new to linear programming problem.我对线性规划问题很陌生。 So i am rather confused and cant really differentiate if Mixed Integer Programming is different from Mixed Integer Linear programming(MILP).所以我很困惑,如果混合整数规划与混合整数线性规划(MILP)不同,我无法真正区分。

Pulp is a python modeling interface that hooks up to solvers like CBC (open source), CPLEX (commercial), Gurobi (commercial),XPRESS-MP (commercial) and YALMIP (open source). Pulp是一个 Python 建模接口,可连接到CBC (开源)、 CPLEX (商业)、 Gurobi (商业)、XPRESS-MP (商业)和YALMIP (开源)等求解器。

You can also use Pyomo to model the optimization problem and then call an external solver, namely CPLEX, Gurobi GLPK and the AMPL solver library.您还可以使用Pyomo对优化问题进行建模,然后调用外部求解器,即 CPLEX、Gurobi GLPK 和 AMPL 求解器库。

You can also call GLPK from GLPK/Python , PyGLPK or PyMathProg .您还可以从GLPK/PythonPyGLPKPyMathProg调用 GLPK。

Yet another modelling language is CMPL , which has a python interface for MIP solvers (for linear programs only).另一种建模语言是CMPL ,它有一个用于 MIP 求解器的 Python 接口(仅适用于线性程序)。

All the above solvers solve Mixed Integer Linear Programs , while some of them (CPLEX, GUROBI and XRESS-MP for sure) can solve Mixed Integer Quadratic Programs and Quadratically constrained quadratic programs (and also conic programs but this probably goes beyond the scope of this question).以上所有求解器都可以求解混合整数线性规划,而其中一些(肯定是 CPLEX、GUROBI 和 XRESS-MP)可以求解混合整数二次规划二次约束二次规划(以及圆锥规划,但这可能超出了本文的范围)问题)。

MIP refers to Mixed integer programs, but it is commonly used to refer to linear programs only. MIP 指的是混合整数程序,但它通常仅指线性程序。 To make the terminology more precise, one should always refer to MILP or MINLP (Mixed integer non-linear programming).为了使术语更准确,应始终参考 MILP 或 MINLP(混合整数非线性规划)。

Note that CPLEX and GUROBI have their own python APIs as well, but they (and also) XPRESS-MP are commercial products, but free for academic research.请注意,CPLEX 和 GUROBI 也有自己的 python API,但它们(以及)XPRESS-MP 是商业产品,但可免费用于学术研究。 CyLP is similar to Pulp above but interfaces with the COIN-OR solvers CBC and CGL and CLP. CyLP类似于上面的 Pulp,但与 COIN-OR 求解器 CBC 和 CGL 和 CLP 接口。

Note that there is a big difference in the performance of commercial and free solvers : the latter are falling behind the former by a large margin.请注意,商业求解器和免费求解器的性能存在很大差异:后者大大落后于前者。 SCIP is perhaps the best non-commercial solver (see below for an update). SCIP可能是最好的非商业求解器(见下文更新)。 Its python interface, PySCIPOpt, is here .它的 python 接口 PySCIPOpt在这里

Also, have a look at this SO question .另外,看看这个 SO question

Finally, if you are interested at a simple constraint solver (not optimization) then have a look at python-constraint .最后,如果您对简单的约束求解器(而不是优化)感兴趣,请查看python-constraint

I hope this helps!我希望这有帮助!

UPDATES更新

More solvers and python interfaces that fell into my radar:更多我关注的求解器和 python 接口:

Update: MIPCL links appear to be broken.更新:MIPCL 链接似乎已损坏。 MIPCL , which appears to be the fastest non-commercial MIP solver, has a python interface that has quite good documentation . MIPCL似乎是最快的非商业 MIP 求解器,它有一个python 接口文档非常好 Note, however, that the Python API does not include the advanced functionality that comes together with the native MIPCLShell .但是请注意,Python API 不包括与本机MIPCLShell一起提供的高级功能。 I particularly like the MIPCL-PY manual , which demonstrates an array of models used in Operations Management, on top of some small-scale implementations.我特别喜欢MIPCL-PY 手册,它展示了运营管理中使用的一系列模型,以及一些小规模的实现。 It is a very interesting introductory manual in its own right, regardless of which solver/API one may want to make use of.它本身就是一本非常有趣的介绍性手册,无论人们想要使用哪个求解器/API。

Google Optimization Tools , which include a multitude of functionalities, such as Google 优化工具,其中包括多种功能,例如

  • A constraint programming solver and a linear programming ( not MIP ) solver约束规划求解器和线性规划(不是 MIP )求解器
  • An interface for MIP solvers (supports CBC, CLP, GLOP, GLPK, Gurobi, CPLEX, and SCIP) MIP 求解器的接口(支持 CBC、CLP、GLOP、GLPK、Gurobi、CPLEX 和 SCIP)
  • Specialized algorithms for graphs, for the Travelling Salesman Problem, the Vehicle Routing problem and for Bin packing & Knapsack problems图的专用算法、旅行商问题、车辆路线问题和装箱和背包问题

It has extensive documentation of several traditional OR problems and simple implementations.它包含有关几个传统 OR 问题和简单实现的大量文档。 I could not find a complete Python API documentation, although there exist some examples here .尽管这里有一些示例,但我找不到完整的 Python API 文档。 It is somewhat unclear to me how other solvers hook up on the interface and whether methods of these solvers are available.我有点不清楚其他求解器如何连接到接口以及这些求解器的方法是否可用。

CVXOPT , an open-source package for convex optimization, which interfaces to GLPK (open source) and MOSEK (commercial). CVXOPT ,一个用于凸优化的开源包,它与 GLPK(开源)和MOSEK (商业)接口。 It is versatile, as it can tackle many problem classes (notably linear, second-order, semidefinite, convex nonlinear).它是通用的,因为它可以解决许多问题类别(特别是线性、二阶、半定、凸非线性)。 The only disadvantage is that it modeling complex problems may be cumbersome, as the user needs to pass the data in a "Matlab-y" fashion (ie, to specify the matrix, rhs vectors, etc).唯一的缺点是它对复杂问题的建模可能很麻烦,因为用户需要以“Matlab-y”方式传递数据(即指定矩阵、rhs 向量等)。 However, it can be called from the modeling interfaces PICOS and...但是,它可以从建模接口PICOS和...

CVXPY , a python-embedded optimization language for convex optimization problems, which contains CVXOPT as a default solver, but it can hook up to the usual MIP solvers . CVXPY ,一种用于凸优化问题的嵌入 python 的优化语言,它包含CVXOPT作为默认求解器,但它可以连接到通常的 MIP 求解器

Thanks to RedPanda for pointing out that CVXOPT/CVXPY support MIP solvers as well.感谢RedPanda指出CVXOPT/CVXPY支持 MIP 求解器。

For a very comprehensive article on optimization modeling capabilities of packages and object-oriented languages (not restricted to Python), check this article .有关包和面向对象语言(不限于 Python)的优化建模能力的非常全面的文章,请查看这篇文章

I have used Gekko Python Package to solve MILP problems.我使用 Gekko Python 包来解决 MILP 问题。 You can either solve your models locally or on their remote server.您可以在本地或在他们的远程服务器上解决您的模型。 Below is an example after installing with pip install gekko :以下是使用pip install gekko后的示例:

from gekko import GEKKO
m = GEKKO()
x,y = m.Array(m.Var,2,integer=True,lb=0) 
m.Maximize(y)
m.Equations([-x+y<=1,
             3*x+2*y<=12,
             2*x+3*y<=12])
m.options.SOLVER = 1
m.solve()
print('Objective: ', -m.options.OBJFCNVAL)
print('x: ', x.value[0])
print('y: ', y.value[0])

GEKKO is a Python package for machine learning and optimization of mixed-integer and differential algebraic equations. GEKKO是一个 Python 包,用于机器学习和优化混合整数和微分代数方程。 It is coupled with large-scale solvers for linear, quadratic, nonlinear, and mixed integer programming (LP, QP, NLP, MILP, MINLP) .它与用于线性、二次、非线性和混合整数规划(LP、QP、NLP、MILP、MINLP)的大规模求解器相结合。 Modes of operation include parameter regression, data reconciliation, real-time optimization, dynamic simulation, and nonlinear predictive control.操作模式包括参数回归、数据协调、实时优化、动态模拟和非线性预测控制。 GEKKO is an object-oriented Python library to facilitate local execution of APMonitor. GEKKO 是一个面向对象的 Python 库,用于促进 APMonitor 的本地执行。

Soon there will be another option: Starting from version 1.9.0, SciPy will support MILP.很快就会有另一种选择:从 1.9.0 版本开始, SciPy将支持 MILP。 See scipy.optimize.milp in the dev docs.请参阅开发文档中的scipy.optimize.milp The SciPy milp implementation is a wrapper of the HiGHS linear optimization software. SciPy milp实现是HiGHS线性优化软件的封装。 It was added in this PR on February 16th, 2022.它于 2022 年 2 月 16 日在此 PR中添加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM