gpt4 book ai didi

python - 为什么我的 MV 无法收敛,而普通 Vars 可以收敛?

转载 作者:行者123 更新时间:2023-12-04 04:10:31 24 4
gpt4 key购买 nike

我正在开发一个电网模型。我现在正处于需要增加电厂爬坡率的阶段。在我的模型中,当我将 Gas 作为 m.Var 时,它会在大约 2 秒内收敛,一旦我将其更改为 m.MV,它就无法找到解决方案。我正在尝试将它更改为 m.MV,以便我可以限制它的渐变能力。在模型中,它实际上升的最大值在 1900 左右,但我只打算将其限制为 3000。是否有另一种类型的变量可以更好地工作?有什么理由不能收敛为m.MV吗?

from gekko import GEKKO
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sqlalchemy import create_engine


"""
Max capacities based on MISO South Grid, Prices are currently based
google averages for a power source but will be specific to Miso soon
"""

nhrs = 240
Gas_cap = 23000 # MW
Gas_start = 18771 # Starting value for 2018-01-01
Gas_cost = 38 # $/MW
Gas_min = 5000 # MW

Coal_cap = 6500 # MW
Coal_start = 962 # Starting value for 2018-01-01
Coal_cost = 76 # $/MW
Coal_min = 900 # MW

Hydro_cap = 500 # MW
Hydro_start = 500 # Starting value for 2018-01-01
Hydro_cost = 21 # $/MW
Hydro_min = 50 # MW

Nuc_cap = 5500 # MW
Nuc_start = 5375 # Starting value for 2018-01-01
Nuc_cost = 20 # $/MW
Nuc_min = 2800 # %capacity

Other_cap = 1000 # MW
Other_start = 859.3 # Starting value for 2018-01-01
Other_cost = 10 # $/MW
Other_min = 100 # MW

query = """SELECT "Actual_Load_MWh", Date_Time FROM "Load_By_Region"
WHERE Region = "South"
AND Date_Time BETWEEN date('2018-01-01') and date('2018-12-31')
"""

con = create_engine('sqlite:///../../../../data/MISO_data.db')
Miso_data = pd.read_sql(query, con)
load_data = pd.to_numeric(Miso_data['Actual_Load_MWh']).values[:nhrs]

date = Miso_data['Date_Time'].values[:nhrs]
Time = np.arange(len(date))
# plt.plot(Time, load_data)

m = GEKKO()
m.time = Time

load = m.Param(load_data)

Nuc = m.MV(value=Nuc_start, lb=Nuc_min, ub=Nuc_cap)
Nuc.DMAX = 1413 # MW from MISO Ramp rates
Gas = m.Var(value=Gas_start, lb=Gas_min, ub=Gas_cap)
#Gas.DMAX = 3900 # MW from MISO Ramp rates
Coal = m.MV(value=Coal_start, lb=Coal_min, ub=Coal_cap)
Coal.DMAX = 2146 # MW from MISO Ramp rates
Hydro = m.MV(value=Hydro_start, lb=Hydro_min, ub=Hydro_cap)
Hydro.DMAX = 209 # MW from MISO Ramp rates
Other = m.MV(value=Other_start, lb=Other_min, ub=Other_cap)
Other.DMAX = 605 # MW from MISO Ramp rates

slack = m.Var(lb=0)
Cost = m.Var(value=0)
CostMWh = m.Var(value=0)
# Gasramp = m.Var(value=0)

# m.Equation(Gasramp == Gas.dt())
m.Equation(load == Nuc + Gas + Coal + Hydro + Other + slack)
m.Equation(Cost == Nuc*Nuc_cost + Gas*Gas_cost + Coal*Coal_cost +
Hydro*Hydro_cost + Other*Other_cost + slack*1e8)
m.Equation(CostMWh == Cost/load)
m.Obj(Cost)
m.options.IMODE = 5
m.options.SOLVER = 3
m.solve()

最佳答案

我无法运行您的确切案例,因为我无权访问您正在使用的数据库。下面是一个收敛到最优解的独立问题。这无济于事,因为您的数据集有问题。以下是使用 m.MV() 模型的一些提示。

  • 在优化之前通过模拟初始化模型。这可以通过使用 m.solve() 设置 m.options.COLDSTART=2 然后 m.options.COLDSTART=0m.options.TIME_SHIFT=0(不更新初始条件)与另一个 m.solve()MV 模型有 additional equations初始化时解决得更好。
  • 这里有更多的引用tips on initialization :
    • Safdarnejad, S.M.、Hedengren, J.D.、Lewis, N.R.、Haseltine, E.,动态系统、计算机和化学工程优化的初始化策略,卷。 78,第 39-50 页,DOI:10.1016/j.compchemeng.2015.04.016。
from gekko import GEKKO
import numpy as np

"""
Max capacities based on MISO South Grid, Prices are currently based
google averages for a power source but will be specific to Miso soon
"""

nhrs = 240
Gas_cap = 23000 # MW
Gas_start = 18771 # Starting value for 2018-01-01
Gas_cost = 38 # $/MW
Gas_min = 5000 # MW

Coal_cap = 6500 # MW
Coal_start = 962 # Starting value for 2018-01-01
Coal_cost = 76 # $/MW
Coal_min = 900 # MW

Hydro_cap = 500 # MW
Hydro_start = 500 # Starting value for 2018-01-01
Hydro_cost = 21 # $/MW
Hydro_min = 50 # MW

Nuc_cap = 5500 # MW
Nuc_start = 5375 # Starting value for 2018-01-01
Nuc_cost = 20 # $/MW
Nuc_min = 2800 # %capacity

Other_cap = 1000 # MW
Other_start = 859.3 # Starting value for 2018-01-01
Other_cost = 10 # $/MW
Other_min = 100 # MW

Time = np.arange(10)

m = GEKKO()
m.time = Time

load = m.Param(np.ones_like(Time)*13000)

Nuc = m.MV(value=Nuc_start, lb=Nuc_min, ub=Nuc_cap)
Nuc.DMAX = 1413 # MW from MISO Ramp rates
Gas = m.MV(value=Gas_start, lb=Gas_min, ub=Gas_cap)
Gas.STATUS = 1
Coal = m.MV(value=Coal_start, lb=Coal_min, ub=Coal_cap)
Coal.DMAX = 2146 # MW from MISO Ramp rates
Hydro = m.MV(value=Hydro_start, lb=Hydro_min, ub=Hydro_cap)
Hydro.DMAX = 209 # MW from MISO Ramp rates
Other = m.MV(value=Other_start, lb=Other_min, ub=Other_cap)
Other.DMAX = 605 # MW from MISO Ramp rates

slack = m.Var(lb=0)
Cost = m.Var(value=0)
CostMWh = m.Var(value=0)

m.Equation(load == Nuc + Gas + Coal + Hydro + Other + slack)
m.Equation(Cost == Nuc*Nuc_cost + Gas*Gas_cost + Coal*Coal_cost +
Hydro*Hydro_cost + Other*Other_cost + slack*1e8)
m.Equation(CostMWh == Cost/load)
m.Obj(Cost)

m.options.SOLVER = 3
m.options.IMODE = 5

# Initialize, if needed
#m.options.COLDSTART=2
#m.solve()

m.options.TIME_SHIFT=0
m.options.COLDSTART=0
m.solve()

关于python - 为什么我的 MV 无法收敛,而普通 Vars 可以收敛?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61824079/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com