python - 优化器向未使用的存储系统添加能量

标签 python gekko

我目前正在制作一个模型,将电池和热能存储与电网上的核电站集成在一起。我已经制作了我的模型,以便它可以正确地分别运行两种类型的电力存储。我遇到的问题是,当我将其中一个存储器注释掉以便它不参与以某种方式在前 2 个时间步中存储能量时,即使它已断开连接,它也会获得其全部能量容量的一半。当我将其他系统注释掉时,被注释掉的电源系统也会发生同样的问题。您知道是什么原因造成的吗?

这是我的代码。我已将其简化,以便可以包含所有内容。

from gekko import GEKKO
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.integrate import quad

#Set up basic power consumption data
n = 24
t = np.linspace(0,n,n)
def load(t):
    return  -10*np.sin(2*np.pi*t/24)+40
Load = load(t)
Gen = np.ones(n)*40
def need(t):
    return 10*np.sin(2*np.pi*t/24)+10

#Set up Model
m = GEKKO()
m.time = t

Cons = m.Param(value=Load)
Enuc = m.FV(value=45, lb=0) #nuclear power
Enuc.STATUS = 1

#Thermal Energy Storage
T = m.SV(value=300,ub=500,lb=300)
mass = m.FV(value=.0746,lb=0)
mass.STATUS=0
Cp = m.Param(value=5)
thermaleff = .8   #80%efficient
thermeff = m.if3((Enuc - Cons)/(mass*Cp),1/thermaleff,thermaleff)

#Battery Electrical storage
Capacity = 76.2
EStored = m.SV(value=0,lb=0,ub=Capacity)
batteryeff = .95
batteff = m.if3((Enuc - Cons),1/batteryeff,batteryeff)

#Energy Balance 
Cost = m.Var()

m.Equation(EStored.dt() == batteff*(Enuc - Cons))  #Energy balance for Battery
#m.Equation(T.dt() == thermeff*(Enuc - Cons)/(mass*Cp)) #Energy balance for Thermal Storage
m.Equation(Cost == Enuc*1000 + Capacity*1000 + mass*5000)
m.Obj(Cost)

m.options.IMODE = 5
m.options.SOLVER = 3
m.solve()

#plot
plt.subplot(3,1,1)
plt.plot(t,Load)
plt.plot(t,Enuc.value)

plt.subplot(3,1,2)
plt.plot(t,EStored.value, label=f'Capacity = {EStored.value[12]:.03}')
plt.title("Battery Storage")
plt.ylabel("Energy")
plt.legend()

plt.subplot(3,1,3)
plt.plot(t,T.value,label=f'mass = {mass.value[-1]:.03}')
plt.title("Thermal Storage")
plt.ylabel("Temperature(K)")
plt.legend()
plt.show() 

最佳答案

问题是您正在消去等式,但变量仍可由优化器调整。优化器确定它可以在没有等式的情况下免费填满存储。您可以尝试以下操作来打开或关闭电池或热能存储功能。

# select battery or thermal storage
battery_storage = True
thermal_storage = True
if battery_storage:
    # Energy balance for Battery
    m.Equation(EStored.dt() == batteff*(Enuc - Cons))
else:
    # Battery storage off
    m.Equation(EStored.dt() == 0)
if thermal storage:
    # Energy balance for Thermal Storage
    m.Equation(T.dt() == thermeff*(Enuc - Cons)/(mass*Cp)) 
else:
    # Thermal storage off
    m.Equation(T.dt() == 0)

Energy Storage Results

另一种选择是将决策变量定义为操纵变量,并根据优化器是否可以使用它们来打开 (1) 或关闭 (0) STATUS。 另一种选择(更简洁)是在等式中直接使用 battery_storage 参数作为 m.Equation(EStored.dt() == battery_storage*batteff*(Enuc - Cons))。当 battery_storage 为零(关闭)时,它将导数设置为零。您可以对 thermal_storage 执行相同的操作。如果您将 battery_storagethermal_storage 作为 Gekko 变量的可调整参数,那么您可以在模拟逐周期运行时打开或关闭它们。

关于python - 优化器向未使用的存储系统添加能量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61391711/

相关文章:

python-3.x - 如何在 GEKKO 中使用自己的求解方法?

python - 如何修复 'can' t 打开文件 'pip' : [Errno 2] No such file or directory' when installing gekko

python - Python 中的 is 运算符

python - 为什么 Python 的 itertools.permutations 包含重复项? (当原始列表有重复时)

javascript - 如何在 odoo 8 中重写 js 函数?

nonlinear-optimization - GEKKO 可以处理哪些类型的非线性?

python - 在 python GEKKO 或 matlab APM 中指定解决方案文件的输出目录

python - 列出 1-50 范围内的 50 个随机数,使得相邻数字彼此不在 15 以内

python - 根据 user_id 获取 Google 帐户电子邮件地址

Python gekko 找不到 "options.json"文件