整数线性规划:示例和好的工具?
找到一个使 c 最小化的向量 x 。 x 受约束 m 。 x>=b,x整数。
这是一个示例输入集:
c : {1,2,3}
m : {{1,0,0},
{0,1,0},
{1,0,1}}
b : {1,1,1}
带输出:
x = {1,1,0}
解决此类问题的好工具是什么,以及如何使用它们的示例?
Find a vector x which minimizes c . x subject to the constraint m . x >= b, x integer.
Here's a sample input set:
c : {1,2,3}
m : {{1,0,0},
{0,1,0},
{1,0,1}}
b : {1,1,1}
With output:
x = {1,1,0}
What are good tools for solving this sort of problem, and examples of how to use them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您指定了一个纯整数规划问题。大多数实际应用通常涉及所谓的混合整数规划,其中只有一些变量是整数。一个相当简洁的教程和有关该主题的论文可以在这里找到:
http://mat.gsia.cmu .edu/orclass/integer/integer.html
IP 问题的典型解决技术是动态规划或分支定界。搜索这些术语应该可以帮助您找到一些免费软件、共享软件或学术代码。
祝你好运
You've specified a pure integer programming problem. Most practical applications usually involve what is called mixed integer programming where only some of the variables are integer. A reasonably concise tutorial & essay on the subject can be found here:
http://mat.gsia.cmu.edu/orclass/integer/integer.html
Typical solution techniques for IP problems are dynamic programming or branch and bound. Searching on these terms should help you find some freeware, shareware, or academic code.
Good luck
Mathematica
Mathematica 内置了这个功能。(注意:Mathematica 不是免费软件。)
输出:
Mathematica
Mathematica has this built in. (NB: Mathematica is not free software.)
outputs:
Python:PULP
Python: PULP
这些类型的简单问题也可以使用称为约束规划的技术来解决。您可以从相应的维基百科条目<中找到有关该技术以及可用于解决这些问题的免费和商业求解器的更多详细信息/a>.
如果涉及整数变量的问题比您提到的更复杂,最好考虑通用线性规划/整数规划求解器(如 GLPK)。它们有很多,一些名称是:LPSOLVE(免费)、IBM ILOG CPLEX(商业)。
These type of simple problems can also be solved using a technique called constraint programming. You can find more details about the technique and free and commercial solvers available to solve these problems from the corresponding wikipedia entry.
If the problems involving integer variables are more complex than what you mention, it is better to consider general purpose Linear Programming/Integer Programming solvers (like GLPK). There are a bunch of them, some names are: LPSOLVE (free), IBM ILOG CPLEX (Commercial).
我正在使用 Python &皮莫。项目网站上有一个很好的优势概述:http://www.pyomo.org
I am using Python & Pyomo. There is a good overview of the advantages on the project website: http://www.pyomo.org
scicomp.stackexchange.com 上有类似的问题并且列出了一些库的答案。
There is a similar question on scicomp.stackexchange.com and an answer which lists a few libraries.
GLPK
我使用 GLPK 的 glpsol 提供答案,但是我希望有更好的方法来做到这一点(对于线性编程问题的这种简单特殊情况,GLPK 似乎过于强大/通用):
为了生成下面给出的 .mps 文件,你必须拆分将矩阵逐行转换为方程组,因此问题描述变为:
GLPK 文档 包含有关 .mps 格式的详细信息,但您可以指定行、列、rhs 和边界。在 ROWS 部分中,“N”和“G”指定约束类型(分别为数字和大于)。在 BOUNDS 部分中,“UI”指定边界为上限整数类型,强制解为整数。
要在问题规范上运行求解器:
example.mps 文件:
输出:
另外,我不清楚如何直接获取解决问题的 x 向量,尽管它在本节上面的输出中进行了编码:
GLPK
I'm offering an answer using GLPK's glpsol, but I hope there are much better ways to do this (it seems like GLPK is overly powerful/general for this kind of simple special case of a linear programming problem):
In order to generate the .mps file given below you've got to split up your matrices row-wise into a system of equations, so the problem description becomes:
GLPK documentation has detailed info on the .mps format, but you specify the rows, columns, rhs, and bounds. In the ROWS section the 'N' and 'G' specify the type of constraint (number, and greater than respectively). In the BOUNDS section the 'UI' specifies that the bounds are upper integer type, forcing the solution to be integer.
To run the solver on the problem specification:
example.mps file:
outputs:
Also, I'm not clear on how to directly get the x vector that solves the problem, though it is encoded in the output above in this section: