我正在开发一个电网模型。我现在处于阶段,需要增加电厂的升温速率。在我的模型中,当我将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=1
设置m.solve()
,然后用另一个m.options.COLDSTART=2
设置m.options.TIME_SHIFT=0
和m.solve()
(不更新初始条件)来实现。 MV
模型具有additional equations,在初始化时会更好地解决。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()