0

我正在尝试使用 Python 中的 PuLP 在多个时间段内优化单个产品的运输。我面临一个用它形成目标函数的问题:

routes =[(t,i,j) for t in TIME for i in ORIGIN for j in DESTINATION]
amount_var = LpVariable.dicts('Volume', (TIME, ORIGIN, DESTINATION), lowBound=0, cat='Integer')
route_usage = LpVariable.dicts('route_usage', routes, cat='Binary')

目标fn:

model += LpProblem("Minimize costs", LpMinimize)
model+=lpSum(amount_[t][i][j]*price[t][i] for (t,i,j) in routes for t in TIME  for i in ORIGIN)

price是一个元组字典:整数对,例如 {(period1,origin1) : price1, (period2,origin1) : price2 等}。

你知道如何解决它吗?

4

1 回答 1

0

如果price是一个以元组为键的字典,则应将目标编写为:

model = LpProblem("Minimize costs", LpMinimize)
model += lpSum(amount_var[t][i][j] * price[(t, i)] for (t, i, j) in routes)
于 2019-09-25T15:25:00.413 回答