【问题标题】:PULP optimization solution undefinedPULP 优化解决方案 undefined
【发布时间】:2020-02-11 05:36:05
【问题描述】:

我正在尝试使用 python 纸浆优化以下问题

import pulp
# Instantiate our problem class
model = pulp.LpProblem("Cost minimising problem", pulp.LpMinimize)

W = pulp.LpVariable('W', cat='Integer')
X = pulp.LpVariable('X', cat='Integer')
Y = pulp.LpVariable('Y', cat='Integer')
Z = pulp.LpVariable('Z', cat='Integer')

# Objective function
model += 1.33 * W + 1.76 * X + 1.46 * Y + 0.79 * Z,"Cost"

# Constraints
model += W + X + Y + Z == 1

 model += W >= 0.1
 model += W <= 0.75

 model += X >= 0.1
 model += X <= 0.85

 model += Y >= 0.1
 model += Y <= 0.65

 model += Z >= 0.1
 model += Z <= 0.40


# Solve our problem
model.solve()
pulp.LpStatus[model.status]

'Undefined'

结果是未定义的解决方案。我是在问题表述上犯了错误还是遗漏了什么?

【问题讨论】:

标签: python optimization pulp


【解决方案1】:

当我实现相同的代码时,我得到的结果是“不可行”。

这是有道理的,因为您的变量 W, X, Y, Z 都必须是整数,但是您随后将它们绑定为大于 0.1,并且小于另一个小于 1 的数字。

0.1和0.XX之间没有整数,所以没有可行解。

【讨论】:

  • 谢谢它的工作,但在 PulP 中有没有办法不指定为 integer 。就像当我使用 excel 求解器解决相同问题时,我得到的值是 32.567 ,38.9867 等。可以使用 PulP 来实现吗?
  • cat='Integer' 替换为cat='Continuous'。见coin-or.org/PuLP/pulp.html#pulp.LpVariable
猜你喜欢
  • 1970-01-01
  • 2017-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多