实现跨时间依赖性的存储模型优化

问题描述 投票:0回答:2

尝试组合一个具有跨时间依赖性的简单线性优化问题。这是一种存储模型,其中有流入存储的水,并且需要释放水以最大化水*价格收入流 - 存储水平会结转到下一个时期。每个周期都有最大存储量和最大释放量。

我不知道如何在PULP中实现存储参数的约束和设置。请参阅下面我的尝试:

编辑:我如何实现这两个约束:
1. 存储[t+1] == 存储[t] + 流入[t] - 释放[t] + 溢出[t]
2. storage[T] == storage[0](这样结束存储=开始存储)
3.储存< maximum storage level for all t

也不确定我是否真的需要“溢出”作为变量,因为这可以从约束(1)中推断出来。

startstorage = 30
maxstorage = 35
maxrelease = 15

data = pd.DataFrame(data={'inflow':[5,3,13,62,11,1,5,9,7,8],
                          'PRICES':[1,2,3,1,3,5,3,4,2,6]})

#do I need to initialise storage and set an upper bound on storage?
#storage = [0] * len(data)
#storage[0] = startstorage

prob = pulp.LpProblem("My LP Problem", pulp.LpMaximize)
release = pulp.LpVariable.dicts('release',data.index, lowBound=0, upBound = maxrelease, cat='Continuous')
spill = pulp.LpVariable.dicts('spill',data.index, lowBound=0, cat='Continuous')
prob += sum([release[t] * data['PRICES'][t] for t in data.index])
# constraint (1)
prob += [storage[t+1] == storage[t] + data['inflow'][t] - release[t] + spill[t] for t in data.index[:-1]]
# constraint (2)
prob += storage[-1:] == storage[0] 

prob.solve()

希望这是有道理的,并提前致谢!

python linear-programming pulp
2个回答
0
投票

在阅读了更多示例后,我意识到了一些菜鸟错误。这就是我所追求的。

startstorage = 30
maxstorage = 35
maxrelease = 15

data = pd.DataFrame(data={'inflow':[5,3,13,62,11,1,5,9,7,8],'PRICES':[1,2,3,1,3,5,3,4,2,6]})

prob = pulp.LpProblem("My LP Problem", pulp.LpMaximize)
storage = pulp.LpVariable.dicts('storage',data.index, lowBound=0, upBound = maxstorage, cat='Continuous')
release = pulp.LpVariable.dicts('release',data.index, lowBound=0, upBound = maxrelease, cat='Continuous')
spill = pulp.LpVariable.dicts('spill',data.index, lowBound=0, cat='Continuous')
prob += lpSum([release[t] * data['PRICES'][t] for t in data.index])
for t in data.index[:-1]:
    prob += storage[t] + data['inflow'][t] - release[t] - spill[t] == storage[t+1]
prob += storage[0] == startstorage
prob += storage[9] == startstorage
prob.solve()

0
投票

我知道你很久以前就发布了这个 - 但是从那以后你开发过你的代码吗?或者你是否已经开发过新版本? 如果您能分享,我将不胜感激

© www.soinside.com 2019 - 2024. All rights reserved.