我有一个玩具工厂LP:
# Import the PuLP lib
from pulp import *
# Products list
products = ["car", "bicycle"]
#Profit per product in $
profit = {"car": 8, "bicycle": 12}
# Used resources per product in kgs
plasticAmount = {"car": 2, "bicycle": 4}
woodAmount = {"car": 1, "bicycle": 1}
steelAmount = {"car": 3, "bicycle": 2}
# Setting Problem variables dictionary
x = LpVariable.dicts("products ", products , 0)
# The Objective function : Maximising profit in $
prob += lpSum([profit[i] * x[i] for i in products ]), "Maximise"
# Total Stock amount Constraints in kgs
prob += lpSum([plasticAmount[i] * x[i] for i in products]) <= 142 ,"MaxPlastic"
prob += lpSum([woodAmount [i] * x[i] for i in products]) <= 117 ,"MaxWood"
prob += lpSum([steelAmount[i] * x[i] for i in products]) <= 124 ,"MaxSteel"
# This constraints is not working : Minimal production amount should be at least 10 on each products ( need at least 10 Cars and 10 bicycles)
prob += lpSum([x[i] for i in produits]) >= 10 ,"MinProdObjs"
如何将每个产品的最小生产值设置为10
如果我有200种产品,我应该如何以更优雅的方式写这篇文章
Lp正确吗
最小生产限制:
prob += lpSum([x[i] for i in produits]) >= 10 ,"MinProdObjs"
简单的意思是(事实上,car是一个“车的数量”,bicycle也是一个“自行车的数量”…也许变量的名称不太好…)
prob += car + bicycle >= 10
或
prob += x1 + x2 >= 10
但它并没有像预期的那样工作
如果
x[p]
是为产品p in P
生产的单元数,则可以添加以下形式的约束:翻译成代码:
受你的约束
您的意思是,您希望所有项目的总产值至少为10
另外请注意,您的变量目前是分数的,您可能希望使用整数
相关问题 更多 >
编程相关推荐