【微电网】并网微电网运行经济性研究(Python代码实现)

简介: 【微电网】并网微电网运行经济性研究(Python代码实现)

👨‍🎓个人主页:研学社的博客

💥💥💞💞欢迎来到本博客❤️❤️💥💥



🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。



⛳️座右铭:行百里者,半于九十。


📋📋📋本文目录如下:🎁🎁🎁

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Python代码、数据、详细文章讲解



💥1 概述

image.gif

在本文中,我们提出了我们的策略和算法来管理微电网中的能量,更具体地说,在考虑消费者负荷、太阳能发电和动态电价的情况下,每小时与主电网的能量交易。

该算法的主要目标是在用户负荷、太阳能发电和电价波动的情况下,优化储能系统( ESS )的运行,最大化微电网的货币效益。除了货币收益外,该算法还考虑了需要保留的最小能量,因为这对于确保微电网中关键任务操作的连续性至关重要。研究分析了两种能量管理算法的性能:1 )具有预测未来知识的模型预测控制线性规划( MPCLPF );2 )不具有未来知识的强化学习。在MPCLPF中,分析了不同的预测算法,并对最优预测算法进行了整合。下面是文章目录:

image.gif

image.gif

详细文章见第4部分。

📚2 运行结果

fig, ax = plt.subplots(1, 1, figsize = (7.5,5))

ax2 = ax.twinx()

PV_plot = ax.step(np.arange(24), df.iloc[0:24,0], 'ro-', label = "PV")

load_plot = ax.step(np.arange(24), df.iloc[0:24,1], 'b*-', label = "Load")

price_plot = ax2.step(np.arange(24), df.iloc[0:24,2], 'k.-', label = "RTP")


# Display all label in one box

plots = PV_plot + load_plot + price_plot

labels = [plot.get_label() for plot in plots]

ax.legend(plots, labels, loc = 0)

ax.set_xlabel("Hour")

ax.set_ylabel("Power (kW)")

ax2.set_ylabel("Price ($/ kWh)")


plt.show()

fig, ax = plt.subplots(3, 2, figsize = (15, 15))


ax[0, 0].step(np.arange(len(x[:,0])), x[:,0])

ax[0, 0].set_xlabel("Hour")

ax[0, 0].set_ylabel("PV (kW)")

ax[0, 1].step(np.arange(len(x[0:24,0])), x[0:24,0])

ax[0, 1].set_xlabel("Hour")

ax[0, 1].set_ylabel("PV (pu)")


ax[1, 0].step(np.arange(len(x[:,1])), x[:,1])

ax[1, 0].set_xlabel("Hour")

ax[1, 0].set_ylabel("Load (kW)")

ax[1, 1].step(np.arange(len(x[0:24,1])), x[0:24,1])

ax[1, 1].set_xlabel("Hour")

ax[1, 1].set_ylabel("Load (pu)")


ax[2, 0].step(np.arange(len(x[:,2])), x[:,2])

ax[2, 0].set_xlabel("Hour")

ax[2, 0].set_ylabel("Price ($/kWh)")

ax[2, 1].step(np.arange(len(x[0:24,2])), x[0:24,2])

ax[2, 1].set_xlabel("Hour")

ax[2, 1].set_ylabel("Price (pu)")


plt.show()

 

plt.plot(lstm.history.history["loss"], "-*", label="training")

plt.plot(lstm.history.history["val_loss"], "-o", label="validation")

plt.xticks(np.arange(0, 20, 2), np.arange(0, 20, 2))

plt.xlabel("Epoch")

plt.ylabel("MAE")

plt.legend()

plt.show()

encoder.load_weights(encoder.weights_dir)

decoder.load_weights(decoder.weights_dir)


y_train_pred, attentions = predict(x_train, y_train)

print ("Training MAE: {:.4f} pu\n".format(mae(y_train[:, :, 0], y_train_pred[:, :, 0])))


fig = plt.figure(figsize=(24, 5))

for idx, i in enumerate([0, 1000, 2000, 3000]):

 ax = fig.add_subplot(1, 4, idx+1)

 ax.plot(y_train_pred[i], "-*", label="prediction")

 ax.plot(y_train[i, :, 0], "-o", label="actual")

 ax.set_xlabel("Hour")

 ax.set_ylabel("Power (pu)")

 ax.legend(loc=2)

plt.show()

 

image.gif

plt.plot(lstm.history.history["loss"], "-*", label="training")

plt.plot(lstm.history.history["val_loss"], "-o", label="validation")

plt.xticks(np.arange(0, 20, 2), np.arange(0, 20, 2))

plt.xlabel("Epoch")

plt.ylabel("MAE")

plt.legend()

plt.show()

image.gif

 

idx = -10


num_steps_display = timesteps_in


attention = attention_weights

attention = tf.squeeze(attention["decoder_layer1_block2"][idx:idx+1], axis=0)


for head in range(0, num_heads):

 fig = plt.figure(figsize=(32,8))

 spec = gridspec.GridSpec(ncols=90, nrows=100)

 

 top_ax = fig.add_subplot(spec[0:15, 15:75])

 left_ax = fig.add_subplot(spec[25:, 0:10])

 right_ax = fig.add_subplot(spec[25:, 15:])

 

 top_ax.plot(x_train[idx, :num_steps_display, 0])

 top_ax.set_xlim([0, num_steps_display])

 top_ax.set_xticks(range(0, num_steps_display, 4))

 top_ax.set_xticklabels(range(0, num_steps_display, 4))


 left_ax.plot(decoder_input[idx, :, 0], range(0, timesteps_out))

 left_ax.set_yticks(range(0, timesteps_out, 4))

 left_ax.set_yticklabels(range(0, timesteps_out, 4))

 left_ax.invert_yaxis()


 sns.heatmap(attention[head][:, :num_steps_display], cmap="viridis", ax=right_ax)

 right_ax.set_xticks(range(0, num_steps_display, 4))

 right_ax.set_xticklabels(range(0, num_steps_display, 4))

 right_ax.set_yticks(range(0, timesteps_out, 4))

 right_ax.set_yticklabels(range(0, timesteps_out, 4))


 plt.title("Head {}".format(head+1))

 plt.show()

image.gif

def get_resultplot(SOC_list, action_list, x, start_idx, end_idx):

 hours = end_idx - start_idx

 if hours == 24:

   plt.figure(figsize = (8,7))

   plt.xticks(range(0, 24), range(1, 25))

 else:

   plt.figure(figsize = (25,5))

   plt.xticks(range(0, end_idx-start_idx, 24), range(1, end_idx-start_idx+1, 24))

 plt.step(range(0, hours), SOC_list[start_idx:end_idx], "ro-", label = "SOC")

 plt.step(range(0, hours), x[start_idx:end_idx, 2], "bs-", label = "price")

 plt.step(range(0, hours), x[start_idx:end_idx, 0], "g*-", label = "pv")

 plt.step(range(0, hours), x[start_idx:end_idx, 1], "m--", label = "load")

 plt.bar(range(0, hours), action_list[start_idx:end_idx],

         facecolor = "w", edgecolor = "k", label = "action")

 plt.ylabel("SOC/ Normalized Price")

 plt.xlabel("Hour")

 plt.legend(loc=2)

 plt.show()  

image.gif

# Case 1 - Charged with PV not with grid to contain excess PV even the price is higher than average

# Use the spare capacity to store PV

# Not below the target SOC

start_idx = len(SOC_list) - 192

end_idx = len(SOC_list) - 168

get_resultplot(SOC_list, action_list, x, start_idx, end_idx)

 

image.gif

 

# Zoom of case 3


fig, ax = plt.subplots(1, 1, figsize = (8,6))

#ax2 = ax.twinx()

ln1 = ax.step(range(0, 24), SOC_list[13079:13103], "ro-", label = "SOC")

ln2 = ax.bar(range(0, 24), action_list[13079:13103],

            facecolor = "w", edgecolor = "k", label = "action")

ln3 = ax.axhline(y  = 0.5, linestyle = "--", label = "target SOC")

ax.set_xlabel("Hour")

ax.set_ylabel("SOC")

lns = ln1 + [ln2] + [ln3]

labs = [l.get_label() for l in lns]

ax.legend(lns, labs, loc = 3)

plt.xticks(range(0, 24), range(1, 25))

plt.show()

image.gif

其余详细部分见第4部分。

🎉3 参考文献

部分理论来源于网络,如有侵权请联系删除。

image.gif编辑

 

🌈4 Python代码、数据、详细文章讲解

https://ttaozhi.com/t/p.html?id=2YA7W3RDkr

相关文章
|
20小时前
|
算法 Java 编译器
优化Python代码性能的实用技巧
提高Python代码性能是每个开发者的关注焦点之一。本文将介绍一些实用的技巧和方法,帮助开发者优化他们的Python代码,提升程序的执行效率和性能。
|
3天前
|
Python
Python中的装饰器:提升代码可读性与复用性
Python中的装饰器是一种强大的工具,能够提升代码的可读性和复用性。本文将深入探讨装饰器的原理、用法以及在实际项目中的应用,帮助读者更好地理解和利用这一特性,提升代码质量和开发效率。
|
4天前
|
监控 Python
Python中的装饰器:提升代码可读性与可维护性
Python中的装饰器是一种强大的工具,可以在不修改函数源代码的情况下,增加新的功能。本文将介绍装饰器的基本概念,以及如何使用装饰器来提升代码的可读性和可维护性。通过实例演示,读者将了解装饰器在各种场景下的灵活运用,从而更好地理解并应用于实际开发中。
|
4天前
|
缓存 Python
Python中的装饰器:提升代码可读性与灵活性
在Python编程中,装饰器是一种强大的工具,可以通过在函数或方法周围包装额外的功能来提升代码的可读性和灵活性。本文将深入探讨装饰器的概念、用法和实际应用,帮助读者更好地理解并运用这一Python编程的利器。
|
4天前
|
算法 调度 Python
【Python】可再生能源发电与电动汽车的协同调度策略研究
【Python】可再生能源发电与电动汽车的协同调度策略研究
|
5天前
|
缓存 并行计算 Serverless
优化Python代码性能的5个技巧
在日常Python编程中,代码性能的优化是一个重要的议题。本文介绍了5个实用的技巧,帮助你提高Python代码的执行效率,包括使用适当的数据结构、优化循环结构、利用内置函数、使用生成器表达式以及并行化处理。通过这些技巧,你可以更高效地编写Python代码,提升程序的性能和响应速度。
|
5天前
|
缓存 Shell 开发工具
[oeasy]python0016_在vim中直接运行python程序
在 Vim 编辑器中,可以通过`:!`命令来执行外部程序,例如`:!python3 oeasy.py`来运行Python程序。如果想在不退出Vim的情况下运行当前编辑的Python文件,可以使用`%`符号代表当前文件名,所以`:!python3 %`同样能运行程序。此外,可以使用`|`符号连续执行命令,例如`:w|!python3 %`会先保存文件(`w`)然后运行Python程序。这样,就可以在不离开Vim的情况下完成编辑、保存和运行Python程序的流程。
16 0
|
4天前
|
JSON 数据格式 开发者
pip和requests在Python编程中各自扮演着不同的角色
`pip`是Python的包管理器,用于安装、升级和管理PyPI上的包;`requests`是一个HTTP库,简化了HTTP通信,支持各种HTTP请求类型及数据交互。两者在Python环境中分别负责包管理和网络请求。
19 5