在连续变量的优化问题中,我使用了GLPK for python(pymprog模块)。结果不是我所期望的。
begin('optimzer')
X = var('X', 5)
k = par('k', [1, 1, 1, 1, 1])
0 <= X[0] <= 100
100 <= X[1] <= 200
400 <= X[2] <= 500
400 <= X[3] <= 500
400 <= X[4] <= 500
sum(k[i]*X[i] for i in range(len(k))) >= 150
minimize(sum(k[i]*X[i] for i in range(len((k)))), 'Profit')
solve()
save(mip='_save.mip')
结果就是这样
Problem: optimzer
Rows: 1
Columns: 5 (0 integer, 0 binary)
Non-zeros: 5
Status: INTEGER UNDEFINED
Objective: Profit = 0 (MINimum)
No. Row name Activity Lower bound Upper bound
------ ------------ ------------- ------------- -------------
1 R1 0 150
No. Column name Activity Lower bound Upper bound
------ ------------ ------------- ------------- -------------
1 X[0] 0 0 100
2 X[1] 0 100 200
3 X[2] 0 400 500
4 X[3] 0 400 500
5 X[4] 0 400 500
Integer feasibility conditions:
KKT.PE: max.abs.err = 0.00e+00 on row 0
max.rel.err = 0.00e+00 on row 0
High quality
KKT.PB: max.abs.err = 4.00e+02 on column 3
max.rel.err = 9.98e-01 on column 3
SOLUTION IS INFEASIBLE
End of output
如果我使用连续变量,为什么状态为INTEGER UNDEFINED?
如果约束应该> = 150,利润如何才能为0?
这不是真正的MIP模型,而是纯LP模型(glpk似乎有所区别)。您可以通过以下方式保存LP解决方案
save(sol='_save.sol')
这将显示:
Problem: optimzer
Rows: 1
Columns: 5
Non-zeros: 5
Status: OPTIMAL
Objective: Profit = 1300 (MINimum)
No. Row name St Activity Lower bound Upper bound Marginal
------ ------------ -- ------------- ------------- ------------- -------------
1 R1 B 1300 150
No. Column name St Activity Lower bound Upper bound Marginal
------ ------------ -- ------------- ------------- ------------- -------------
1 X[0] NL 0 0 100 1
2 X[1] NL 100 100 200 1
3 X[2] NL 400 400 500 1
4 X[3] NL 400 400 500 1
5 X[4] NL 400 400 500 1
Karush-Kuhn-Tucker optimality conditions:
KKT.PE: max.abs.err = 0.00e+00 on row 0
max.rel.err = 0.00e+00 on row 0
High quality
KKT.PB: max.abs.err = 0.00e+00 on row 0
max.rel.err = 0.00e+00 on row 0
High quality
KKT.DE: max.abs.err = 0.00e+00 on column 0
max.rel.err = 0.00e+00 on column 0
High quality
KKT.DB: max.abs.err = 0.00e+00 on row 0
max.rel.err = 0.00e+00 on row 0
High quality
End of output
似乎save(mip='_save.mip')
只有在模型中至少有一个离散变量时才有效。