【问题标题】:CPLEX can't find a solution if I use binary vabriables如果我使用二进制变量,CPLEX 找不到解决方案
【发布时间】:2020-10-15 19:10:36
【问题描述】:

我正在使用 CPLEX 12.9 和 Python 来解决 MILP(混合整数线性问题)。 我尝试了两种方法;我期望得到相同的结果,但是虽然第一种方法有效,但第二种方法无效。

1) 第一种方法:

这种方法很成功。在生成的“.lp”文件(一个包含人类可读的问题表述的文本文件:有一个必须最小化的目标函数和一些约束)中,可以看出x6, x7, x8, x9, x10, x11continuous 变量和它们都等于500(我定义了它们的upperlower 边界等于500;所以它们实际上是常量)。

2) 第二种方法:

它返回 CPLEX Error 1217: No solution exists,因此 CPLEX 无法找到解决方案,但我不明白为什么。

我唯一改变的是:

  • 我将x6, x7, x8, x9, x10, x11设置为binary变量;
  • 对于它们中的每一个,我定义了 lower 边界等于 0upper 边界等于 500

因此,生成的“.lp”文件与使用第一种方法生成的文件非常相似;唯一不同的是:

  • x6, x7, x8, x9, x10, x11 被定义为范围(而不是常量),所以它们是:

    0 <= x6 <= 500
    0 <= x7 <= 500
    0 <= x8 <= 500
    0 <= x9 <= 500
    0 <= x10 <= 500
    0 <= x11 <= 500
    
  • Binaries 部分(在“.lp”文件的末尾)现在也包含 x6, x7, x8, x9, x10, x11 变量。

注意: 即使(在第二种方法中)我将lowerupper 的边界都设置为500,问题仍然存在。

【问题讨论】:

  • 二进制意味着 lowerbound=0 和 upperbound=1。
  • 谢谢!我读到here 那个"Binary variables are automatically given bounds of 0 (zero) and 1 (one), unless alternative bounds are specified in the BOUNDS section, in which case a warning message is issued."。因此,起初,我认为对二进制变量边界使用非默认值只会生成警告,并且无论如何,CPLEX 都会按预期工作。相反,CPLEX 似乎实际上不允许二进制变量的边界不同于 0/1。
  • 我认为您可以使用边界来修复(二进制)变量。

标签: python optimization linear-programming cplex mixed-integer-programming


【解决方案1】:

如果您使用二进制,这意味着决策变量将是 0 或 1,即使您稍后添加了一些约束条件,即它应该小于 500。

如果您希望决策变量允许 500 作为值,您应该使用浮点数或整数作为类型。

如果我使用zoo example 并将整数更改为二进制:

from docplex.mp.model import Model

mdl = Model(name='buses')
nbbus40 = mdl.binary_var(name='nbBus40')
nbbus30 = mdl.binary_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.minimize(nbbus40*500 + nbbus30*400)

mdl.solve()

print(mdl.solve_details.status)

给予:

integer infeasible

【讨论】:

  • 我读到here"Binary variables are automatically given bounds of 0 (zero) and 1 (one), unless alternative bounds are specified in the BOUNDS section, in which case a warning message is issued."。因此,起初,我认为对二进制变量边界使用非默认值只会导致警告,但 CPLEX 会按预期工作。相反,CPLEX 似乎实际上不允许二进制变量的边界不同于 0/1。 BTW,现在我解决了,谢谢!
猜你喜欢
  • 1970-01-01
  • 2017-03-14
  • 1970-01-01
  • 2019-11-21
  • 1970-01-01
  • 2020-12-01
  • 1970-01-01
  • 2020-09-18
  • 1970-01-01
相关资源
最近更新 更多