纸浆:向 LpVariable.dicts() 添加边界

Pulp : Adding bounds to LpVariable.dicts()

假设我有这本字典:

cars = ["car1","car2","car3","car4","car5"]

x = LpVariable.dicts("car",cars, cat='Integer', lowBound=0, upBound=800)

有什么办法可以给每辆车添加不同的lowBound和upBounds吗?

备注

简易代码版本如下所示:

car1 = LpVariable("car1", 0, 40)   
car2 = LpVariable("car2", 0, 1000) 

请注意car1 upBound为40,car 2 upBound为1000。

最后, 我已经做到了,使用他的伟大代码: 非常感谢,DSM,兄弟!

prob = LpProblem("problem", LpMaximize)

# Setting LP variables
lpVars =["car1","car2","car3"]
upbounds=[40,80,30]
xs = [LpVariable("car{}".format(i+1), lowBound = 0,  upBound = upbounds[i], cat='Integer'  ) for i in range(len(lpVars))]

 # add objective
    margin = [3,2,3]
    total_prof = sum(x * value for x,value in zip(xs, margin))
    prob += total_prof

# add constraint
    labour = [2,1,4]
    total_labour = sum(x * w for x,w in zip(xs, labour))
    prob += total_labour <= 100

 # Solve the problem
    prob.solve()

下一步是从前端应用程序获取数组变量(upbounds、margin、labour 等..),谢谢兄弟,偷看我的github