如何在最优控制中限制SoC?

How to limit the SoC in Optimal control?

我正在尝试建立这个生理模型。我想模拟运动员恢复,这类似于电动汽车的充电状态。 我不确定如何限制 100% SoC。

我遇到的问题是问题变得非常大,因为我需要获取以前的 SoC 来测量当前的 Soc。此外,我不确定如何模拟放电率与充电率不同的事实。 谢谢

#discharging
W'Exp = (P - CP) * dt                     
soc = soc - W'Exp                       
#If the Power for the data point is below CP or CV, W' is reconstituted:
W'Rec = (CP - P) * dt                            
Rate = (W' - W'Bal) / W'                         
soc = soc + W'Rec * Rate

第一个问题,我猜SOC是个变量。一个变量的上下界可以设置如下:

m = GEKKO()    
SOC = m.Var(10, lb=0, ub=100)

10为SOC初值。 对于你的第二个问题,是否给出了P, CP, W'Bal

检查找到的简单能量存储模型的 Gekko 实现 here as an example problem。您或许可以为运动员修改此模型。

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
from gekko import GEKKO

m = GEKKO(remote=False)

t = np.linspace(0, 24, 24*3+1)
m.time = t

m.options.SOLVER   = 1
m.options.IMODE    = 6
m.options.NODES    = 3
m.options.CV_TYPE  = 1
m.options.MAX_ITER = 300

p = m.FV()           # production
p.STATUS = 1
s = m.Var(100, lb=0) # storage inventory
store = m.SV()       # store energy rate
vy = m.SV(lb=0)      # store slack variable
recover = m.SV()     # recover energy rate
vx = m.SV(lb=0)      # recover slack variable

eps = 0.7

d = m.MV(-20*np.sin(np.pi*t/12)+100)

m.periodic(s)

m.Equations([p + recover/eps - store >= d,
             p - d == vx - vy,
             store == p - d + vy,
             recover == d - p + vx,
             s.dt() == store - recover/eps,
             store * recover <= 0])
m.Minimize(p)

m.solve(disp=True)

#%% Visualize results
fig, axes = plt.subplots(4, 1, sharex=True)

ax = axes[0]
ax.plot(t, store, 'C3-', label='Store Rate')
ax.plot(t, recover, 'C0-.', label='Recover Rate')

ax = axes[1]
ax.plot(t, d, 'k-', label='Electricity Demand')
ax.plot(t, p, 'C3--', label='Power Production')

ax = axes[2]
ax.plot(t, s, 'C2-', label='Energy Inventory')

ax = axes[3]
ax.plot(t, vx, 'C2-', label='$S_1$')
ax.plot(t, vy, 'C3--', label='$S_2$')
ax.set_xlabel('Time (hr)')

for ax in axes:
    ax.legend(bbox_to_anchor=(1.01, 0.5), \
              loc='center left', frameon=False)
    ax.grid()
    ax.set_xlim(0, 24)
    loc = mtick.MultipleLocator(base=6)
    ax.xaxis.set_major_locator(loc)

plt.tight_layout()
plt.show()