如何从两个变量中选择相同键的值,然后在gurobi中对两种情况进行测试?

时间:2019-07-01 09:36:21

标签: python gurobi

我必须从驾驶模式中的任何一个值中获得最佳值,以最小化目标。我具有不同的温度值,并检查侵略性和经济性值,并从中选择最佳组合。

drivingPattern, Denergy, Dtimeduration = 
multidict({
"agressive":[123, 234], 
"economic":[20, 24]
})

 # Create a new model
 m = Model("MEC")
 drivingMode = ["agressive", "economic"]

temp = m.addVar(-26,48, vtype=GRB.CONTINUOUS, name = "temp")
timeDuration = m.addVars(self.Dtimeduration, name="timeDuration")
energy = m.addVars(self.Denergy, name="energy")
mode = m.addVars(drivingMode,name="mode")

energySelect = m.addConstrs((energy.select(m,'*') for m in mode  ),"energySelect")

durationSelect = m.addConstrs((timeDuration .select(m,'*') for m in mode  ),"durationSelect ")

m.update()
m.setObjective((1.7956*temp +184.38) * durationSelect , GRB.MINIMIZE )

m.optimize()

for v in m.getVars():
   print('%s %g' % (v.varName, v.x))

print('Obj: %g' % m.objVal)

0 个答案:

没有答案