我正在建立一个用于电池存储系统套利的优化模型,但是能量平衡(电池的充电状态)约束不是,这限制了充电,我是pyomo的新手,所以我非常感谢帮助设置能量平衡约束。谢谢!
我尝试设置能量平衡model.e [i],以便当电池通过model.poscharge [i]充电时,model.e [i]的值会增加,并且您无法破坏model.negcharge [ i],除非您在先前的迭代中通过model.poscharge [i]进行了收费,否则我也尝试将其设置为参数,但这似乎不起作用。
dataset_test = pd.read_csv('TIMEinput_RFR5000 results.csv') # Reading the dataset of prices
DAM_price = dataset_test.iloc[0:24, 2].values # Creating the price Vector
model = ConcreteModel()
model.IDX = RangeSet(24)
model.IDX.pprint()
eff = 0.90
# Variables
model.negcharge = Var(model.IDX, bounds = (0.00, 10.00))
model.poscharge = Var(model.IDX, bounds = (0.00, 10.00))
model.e = Var(model.IDX, bounds = (0.00, 40.00))
# Objective
model.obj = Objective(expr = sum( -(DAM_price[i-1] * (model.negcharge[i] - model.poscharge[i])) for i in model.IDX))
# Constraints
model.cap1 = Constraint(expr = sum(model.negcharge[i] for i in model.IDX) <= 40)
model.cap2 = Constraint(expr = sum(model.poscharge[i] for i in model.IDX) <= 40)
def ebalance_rule(model, i):
if i == 1:
return e[i] == 0
else:
return e[i] == e[i-1] + eff*model.poscharge[i] - model.negcharge[i]/eff
model.ebalance = Constraint(model.IDX)
# Solving the model
opt = SolverFactory('glpk')
results = opt.solve(model)
results.write()
model.obj.value()
for x in range(1,25):
print(model.negcharge[x].value)
for x in range(1,25):
print(model.poscharge[x].value)
for x in range(1,25):
print(model.e[x].value)
我期望的是电池充电状态的值,但是我只能得到以下内容:
for x in range(1,25):
print(model.e[x].value)
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None