gpt4 book ai didi

python - 在 Python 中定义 DEA 优化的约束

转载 作者:太空宇宙 更新时间:2023-11-03 18:10:49 27 4
gpt4 key购买 nike

我正在尝试解决线性化 DEA 优化问题。

这是我在 python 中定义问题的方式:

Philadelphia = plp.LpProblem("Philadelphia", plp.LpMaximize)
U1 = plp.LpVariable("U1", 0)
U2 = plp.LpVariable("U2", 0)
V1 = plp.LpVariable("V1", 0)
V2 = plp.LpVariable("V2", 0)
Philadelphia += 700*U1 + 300*U2, "obj"
Philadelphia += 700*U1 + 300*U2 - 40*V1 - 500*V2 <= 0, "c1"
Philadelphia += 300*U1 + 600*U2 - 50*V1 - 500*V2 <= 0, "c2"
Philadelphia += 200*U1 + 700*U2 - 50*V1 - 400*V2 <= 0, "c3"
Philadelphia += 400*U1 + 600*U2 - 50*V1 - 500*V2 <= 0, "c4"
Philadelphia += 500*U1 + 400*U2 - 40*V1 - 400*V2 <= 0, "c5"
Philadelphia += 500*U1 + 500*U2 - 50*V1 - 500*V2 <= 0, "c6"
Philadelphia += 800*U1 + 500*U2 - 40*V1 - 600*V2 <= 0, "c7"
Philadelphia += 300*U1 + 200*U2 - 30*V1 - 400*V2 <= 0, "c8"
Philadelphia += 40*V1 + 500*V2 = 1, "c9"

但是,约束:

Philadelphia += 40*V1 + 500*V2 = 1, "c9"

给出错误“语法无效”,并带有指向等号的箭头。

如何修改约束以避免出现此错误?

最佳答案

PuLP 语法需要 == 来强制相等。

Philadelphia += 40*V1 + 500*V2 == 1, "c9"

这应该有效!

关于python - 在 Python 中定义 DEA 优化的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26004610/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com