我有这段代码,需要通过在每个时间步上加权(使用wind_throttle)一个常数(wind_power_annuum)来保持电池的输出电量完全耗尽和完全充电。所以我想这是一个有边界的优化问题。
这非常重要,我以为我已经完成了这个项目感到非常沮丧,但是我发现代码中的错误使我看得出的结果是正确的,但经过进一步检查,这是非常不正确的! 不是将差异添加到上一个时间步,而是将其自身重置为放错位置的变量。如此之多,以至于我期望有波动,但数值不正确。下面的代码现在已从先前的迭代中得到纠正,但是现在的问题是需要限制电源参数,使其保持在电池的范围内。
因此,我真的非常感谢您的帮助和指导。我将在下面发布代码和文件以供查看,并附上一张图片,希望可以描述问题。
一如既往,感谢您的宝贵时间。我真的很感谢你们抽出宝贵的时间来帮助某人!
https://drive.google.com/open?id=1IpOBNz1TQHAqxyG_E2qwERhIdigxzzzB
我已更新以下电池功能,以寻求解决方案。它目前正在运行,并且要花很长时间,因为它是蛮力的方法!
import numpy as np # Initial code posted to Overflow
import matplotlib.pyplot as pyplot
Battery_Charge_Initial = 6.9 # kWh = Fully Charged with 13.8 kW output 55 mins of output per battery (x3)
Battery_Max = 13.8
timebase = 1440*365
t0 = 0
load = np.load('load_power_anuum.npy')
supply = np.load('wind_power_anuum.npy')*(wind_throttle) + np.load('solar_power_anuum.npy')*2
#def wind_throttle(): #ahbdbwasdxSOS
# for t in range(timebase):
# if
def battery():
charge = np.zeros(timebase)
value = np.array ( range(timebase), dtype = float)
supply_zero = np.zeros(timebase)
value = (supply-load)*(1/60)
charge[0] = Battery_Charge_Initial
for t in range(1,timebase):
charge[t] = charge[t-1] + value[t]
return charge
ts = np.arange( t0, 1440*365, 1)
Batt = battery()
plot_type = 1
figure = pyplot.figure()
if plot_type == 0:
print ( " Plot type cannot equal zero! Please select a the relevant plot type" )
elif plot_type == 1:
pyplot.subplot(211)
pyplot.plot(ts, Batt, color = 'black', linewidth = 0.5)
pyplot.ylabel("Battery kWh")
pyplot.xlabel("Time (Minutes)")
pyplot.ylim(-0.05,13.85)
pyplot.legend()
pyplot.subplot(212)
pyplot.plot(ts, supply, color = 'b', linewidth = 0.5)
pyplot.plot(ts, load, color = 'r', linewidth = 0.5)
pyplot.ylabel("Power kW")
pyplot.xlabel("Time (Minutes)")
pyplot.legend()
if plot_type > 0:
def battery():
charge = np.zeros(timebase)
value = np.array ( range(timebase), dtype = float)
wind_throttle = np.array( range(timebase), dtype = float)
charge[0] = Battery_Charge_Initial
supply = np.zeros(timebase)
for t in range(1,timebase):
if t == 0:
charge[t] = charge[t]
else:
wind_throttle[t] = 1.00
supply[t] = wind_power[t]*(wind_throttle[t]) + solar_power[t]*2
value[t] = (supply[t]-load[t])*(1/60)
charge[t] = charge[t-1] + value[t]
while charge[t] >= Battery_Max or charge[t] <= 0.00:
wind_throttle[t] = random.random()
if 0.00 < charge[t] <= Battery_Max:
break
return charge, wind_throttle, supply