整数线性规划:示例和好的工具?

发布于 2024-08-16 22:57:00 字数 245 浏览 3 评论 0原文

找到一个使 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

寻找一个思念的角度 2024-08-23 22:57:01

您指定了一个纯整数规划问题。大多数实际应用通常涉及所谓的混合整数规划,其中只有一些变量是整数。一个相当简洁的教程和有关该主题的论文可以在这里找到:

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

七度光 2024-08-23 22:57:01

Mathematica

Mathematica 内置了这个功能。(注意:Mathematica 不是免费软件。)

LinearProgramming[c, m, b, Automatic, Integers]

输出:

{1, 1, 0}

Mathematica

Mathematica has this built in. (NB: Mathematica is not free software.)

LinearProgramming[c, m, b, Automatic, Integers]

outputs:

{1, 1, 0}
淡忘如思 2024-08-23 22:57:01

Python:PULP

Python: PULP

遥远的绿洲 2024-08-23 22:57:01

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).

捂风挽笑 2024-08-23 22:57:01

我正在使用 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

神经暖 2024-08-23 22:57:01

scicomp.stackexchange.com 上有类似的问题并且列出了一些库的答案。

There is a similar question on scicomp.stackexchange.com and an answer which lists a few libraries.

野鹿林 2024-08-23 22:57:00

GLPK

我使用 GLPK 的 glpsol 提供答案,但是我希望有更好的方法来做到这一点(对于线性编程问题的这种简单特殊情况,GLPK 似乎过于强大/通用):

为了生成下面给出的 .mps 文件,你必须拆分将矩阵逐行转换为方程组,因此问题描述变为:

minimize

cost = 1 x_1 + 2 x_2 + 3 x_3

s.t. constraints:

S1 = 1 x_1 + 0 x_2 + 0 x_3
S2 = 0 x_1 + 1 x_2 + 0 x_3
S3 = 1 x_1 + 0 x_2 + 1 x_3

S1 >= 1
S2 >= 1
S3 >= 1

0 <= x1 <= 1
0 <= x2 <= 1
0 <= x3 <= 1

GLPK 文档 包含有关 .mps 格式的详细信息,但您可以指定行、列、rhs 和边界。在 ROWS 部分中,“N”和“G”指定约束类型(分别为数字和大于)。在 BOUNDS 部分中,“UI”指定边界为上限整数类型,强制解为整数。

要在问题规范上运行求解器:

> glpsol --freemps example.mps -o example.out

example.mps 文件:

NAME          VM
ROWS
 N cost
 G S1
 G S2
 G S3
COLUMNS
 x_1    cost    1.0
 x_1    S1      1.0
 x_1    S3      1.0
 x_2    cost    2.0
 x_2    S2      1.0
 x_3    cost    3.0
 x_3    S3      1.0
RHS 
 RHS1 cost   0.0
 RHS1 S1     1.0
 RHS1 S2     1.0
 RHS1 S3     1.0
BOUNDS
 UI BND1 x_1 1.0
 UI BND1 x_2 1.0
 UI BND1 x_3 1.0
ENDATA

输出:

Problem:    VM
Rows:       4
Columns:    3 (3 integer, 3 binary)
Non-zeros:  7
Status:     INTEGER OPTIMAL
Objective:  cost = 3 (MINimum)

   No.   Row name        Activity     Lower bound   Upper bound
------ ------------    ------------- ------------- -------------
     1 cost                        3
     2 S1                          1             1
     3 S2                          1             1
     4 S3                          1             1

   No. Column name       Activity     Lower bound   Upper bound
------ ------------    ------------- ------------- -------------
     1 x_1          *              1             0             1
     2 x_2          *              1             0             1
     3 x_3          *              0             0             1

Integer feasibility conditions:

INT.PE: max.abs.err. = 0.00e+00 on row 0
        max.rel.err. = 0.00e+00 on row 0
        High quality

INT.PB: max.abs.err. = 0.00e+00 on row 0
        max.rel.err. = 0.00e+00 on row 0
        High quality

End of output

另外,我不清楚如何直接获取解决问题的 x 向量,尽管它在本节上面的输出中进行了编码:

  No. Column name       Activity     
------ ------------    ------------- 
     1 x_1          *              1 
     2 x_2          *              1 
     3 x_3          *              0  

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:

minimize

cost = 1 x_1 + 2 x_2 + 3 x_3

s.t. constraints:

S1 = 1 x_1 + 0 x_2 + 0 x_3
S2 = 0 x_1 + 1 x_2 + 0 x_3
S3 = 1 x_1 + 0 x_2 + 1 x_3

S1 >= 1
S2 >= 1
S3 >= 1

0 <= x1 <= 1
0 <= x2 <= 1
0 <= x3 <= 1

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:

> glpsol --freemps example.mps -o example.out

example.mps file:

NAME          VM
ROWS
 N cost
 G S1
 G S2
 G S3
COLUMNS
 x_1    cost    1.0
 x_1    S1      1.0
 x_1    S3      1.0
 x_2    cost    2.0
 x_2    S2      1.0
 x_3    cost    3.0
 x_3    S3      1.0
RHS 
 RHS1 cost   0.0
 RHS1 S1     1.0
 RHS1 S2     1.0
 RHS1 S3     1.0
BOUNDS
 UI BND1 x_1 1.0
 UI BND1 x_2 1.0
 UI BND1 x_3 1.0
ENDATA

outputs:

Problem:    VM
Rows:       4
Columns:    3 (3 integer, 3 binary)
Non-zeros:  7
Status:     INTEGER OPTIMAL
Objective:  cost = 3 (MINimum)

   No.   Row name        Activity     Lower bound   Upper bound
------ ------------    ------------- ------------- -------------
     1 cost                        3
     2 S1                          1             1
     3 S2                          1             1
     4 S3                          1             1

   No. Column name       Activity     Lower bound   Upper bound
------ ------------    ------------- ------------- -------------
     1 x_1          *              1             0             1
     2 x_2          *              1             0             1
     3 x_3          *              0             0             1

Integer feasibility conditions:

INT.PE: max.abs.err. = 0.00e+00 on row 0
        max.rel.err. = 0.00e+00 on row 0
        High quality

INT.PB: max.abs.err. = 0.00e+00 on row 0
        max.rel.err. = 0.00e+00 on row 0
        High quality

End of output

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:

  No. Column name       Activity     
------ ------------    ------------- 
     1 x_1          *              1 
     2 x_2          *              1 
     3 x_3          *              0  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文