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

Why is my MV unable to converge when normal Vars can?

我正在开发一个电网模型。我现在正处于需要增加电厂爬坡率的阶段。在我的模型中,当我将 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.options.COLDSTART=2 设置为 m.solve(),然后将 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()