微电网日前优化调度 。算例有代码(1)

个人电气博文传送门
学好电气全靠它,个人电气博文目录(持续更新中…)
符号说明

问题1 求解

  1. 经济性评估方案:
    若微网中蓄电池不作用,且微网与电网交换功率无约束,在无可再生能源和
    可再生能源全额利用两种情况下,分别计算各时段负荷的供电构成(kW)、全
    天总供电费用(元)和负荷平均购电单价(元/kWh)。

情况1 无可再生能源
微网中蓄电池不作用,与电网交换功率无约束,且无可再生能源,所以供电
构成:

#读取数据
python 代码

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
file=pd.read_csv('微电网日前优化调度.csv',header=0,encoding='gbk')

print(file.head())

添加购电售电价格因素
注意。在前文博客中(微电网日前优化调度 。算例有代码(0))给出的价格是购电电价(元/kWh),和售电电价(元/kWh) ,而负荷给出的是负荷(kW)。有96个节点,对应1小时有4个节点。所所以对应每点价格应除以4.

file['售电价格']=''
file.loc[file['序号']>=1,'售电价格']=0.22/4
file.loc[file['序号']>=29,'售电价格']=0.42/4
file.loc[file['序号']>=41,'售电价格']=0.65/4
file.loc[file['序号']>=61,'售电价格']=0.42/4
file.loc[file['序号']>=73,'售电价格']=0.65/4
file.loc[file['序号']>=85,'售电价格']=0.42/4

file['购电价格']=''
file.loc[file['序号']>=1,'购电价格']=0.25/4
file.loc[file['序号']>=29,'购电价格']=0.53/4
file.loc[file['序号']>=41,'购电价格']=0.82/4
file.loc[file['序号']>=61,'购电价格']=0.53/4
file.loc[file['序号']>=73,'购电价格']=0.82/4
file.loc[file['序号']>=85,'购电价格']=0.53/4

负荷曲线画图

#负荷曲线
fuhe=file['负荷(kW)']
plt.plot(fuhe)
plt.show()
全天总供电费用: ```python #购电价格 file['buyprice']=file['负荷(kW)']*file['购电价格'] buyprice_sum=file['buyprice'].sum() print(buyprice_sum) ``` 结果:1976.4142499999996

平均成本为总供电费用比全天负荷消耗功率:
平均成本为平均1kWh的钱。所以代码里要乘以4

#平均成本
buyprice1_mean=buyprice_sum*4/file['负荷(kW)'].sum()
print(buyprice1_mean)

结果为:0.5975779129974677

情况2 可再生能源的全额利用的模型建立与求解
全新代码,不看之前情况1的代码
题中要求可再生能源全额利用:

微网中可再生能源全额利用,则若较负荷所需功率不足,不足部分向主网购
买;若剩余,则剩余部分售卖给主网,供电构成:

#添加是否购电状态

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#读取文件
file=pd.read_csv('微电网日前优化调度.csv',header=0,encoding='gbk')



file['售电价格']=''
file.loc[file['序号']>=1,'售电价格']=0.22/4
file.loc[file['序号']>=29,'售电价格']=0.42/4
file.loc[file['序号']>=41,'售电价格']=0.65/4
file.loc[file['序号']>=61,'售电价格']=0.42/4
file.loc[file['序号']>=73,'售电价格']=0.65/4
file.loc[file['序号']>=85,'售电价格']=0.42/4

file['购电价格']=''
file.loc[file['序号']>=1,'购电价格']=0.25/4
file.loc[file['序号']>=29,'购电价格']=0.53/4
file.loc[file['序号']>=41,'购电价格']=0.82/4
file.loc[file['序号']>=61,'购电价格']=0.53/4
file.loc[file['序号']>=73,'购电价格']=0.82/4
file.loc[file['序号']>=85,'购电价格']=0.53/4

#是否购电
file['状态']=''
file.loc[file['负荷(kW)']-file['风机(kW)']-file['光伏(kW)']>=0,'状态']=1#向主网购电
file.loc[file['负荷(kW)']-file['风机(kW)']-file['光伏(kW)']<0,'状态']=0#向主网售电
print(file)

全天总供电费用应为 风机费用 +光伏费用 +主网费用

#风机费用

#风机购电费用
windprice=file['风机(kW)']*0.52/4#除以4和前文一样
print(windprice.sum())

结果为 1447.2224
#光伏费用

#光伏费用
sumprice=file['光伏(kW)']*0.75/4
print(sumprice.sum())

结果为:471.85875

#主网费用
微网中可再生能源全额利用,则若较负荷所需功率不足,不足部分向主网购
买;若剩余,则剩余部分售卖给主网。
所以主网费用有是否购电这一项 。费用为向主网购电费用-向主网售电费用
计算公式:

#主网费用
因为file[‘与主网交换负荷’]里有负值,所以向主网购电与向主网售电两项费用采用+号


file['与主网交换负荷']=file['负荷(kW)']-file['风机(kW)']-file['光伏(kW)']

#主网费用 。向主网购电费用-向主网售电费用
main_price=file['与主网交换负荷']*file['购电价格']*file['状态']+(file['与主网交换负荷']*file['售电价格']*(1-file['状态']))
print(main_price.sum())

结果:356.0886250000001

一天总供电费用
三项相加

#一天总供电费用
sumprice=windprice.sum()+sumprice.sum()+main_price.sum()
print(sumprice)

结果为:2275.1697750000003

平均成本 平均1kw/h成本,所以代码要乘以4

#平均成本
buyprice1_mean=sumprice*4/file['负荷(kW)'].sum()
print(buyprice1_mean)

结果为0.6879080161759704

功率画图

import matplotlib.pyplot as plt
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False
#画图
fuhe=file['负荷(kW)']
plt.plot(file['负荷(kW)'],label='负荷')
plt.plot(file['风机(kW)'],'r',label='风机')
plt.plot(file['光伏(kW)'],'g',label='光伏')
plt.plot(file['与主网交换负荷'],'c',label='主网')
plt.legend()
plt.show()

图中 主网提供功率会出现负值,即微网对电网售电。

问题1 解决啦 ,后续会对问题2,3,4进行求解。

  • 13
    点赞
  • 88
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 21
    评论
很抱歉,我并不清楚你想要什么类型的算例代码,因为电网优化调度算法有很多种。以下是一个简单的电网优化调度算法的 Python 代码示例,其中包括了一个简单的遗传算法优化器: ```python import random # 假设电网有4台发电机,每台发电机分别有3个功率等级可供选择 num_generators = 4 num_power_levels = 3 # 假设电网需要满足的最小功率需求为100 kW min_power = 100 # 假设每个功率等级对应的发电机出力分别为[50, 100, 150] kW power_levels = [50, 100, 150] # 定义电网的负载曲线(即负载功率需求随时间变化的曲线) load_curve = [120, 90, 110, 80, 100, 130, 140, 110, 90, 100] # 定义遗传算法参数 pop_size = 50 # 种群大小 num_generations = 100 # 迭代次数 mutation_rate = 0.1 # 变异率 # 定义适应度函数 def fitness_function(solution): # 计算电网当前时刻的总功率输出 total_power = sum([power_levels[solution[i]][j] for i in range(num_generators) for j in range(len(solution[i])) if solution[i][j] == 1]) # 计算电网当前时刻的负载 load = load_curve[0] # 如果电网当前时刻的总功率输出小于最小功率需求,则适应度为0 if total_power < min_power: return 0 # 计算电网当前时刻的适应度,适应度越高表示越优秀 return load / total_power # 定义随机生成初始解的函数 def generate_random_solution(): return [[random.randint(0, 1) for _ in range(num_power_levels)] for _ in range(num_generators)] # 定义交叉函数 def crossover(parent1, parent2): child1 = [] child2 = [] # 以50%的概率对每个基因进行交叉 for i in range(num_generators): child1_gene = [] child2_gene = [] for j in range(num_power_levels): if random.random() < 0.5: child1_gene.append(parent1[i][j]) child2_gene.append(parent2[i][j]) else: child1_gene.append(parent2[i][j]) child2_gene.append(parent1[i][j]) child1.append(child1_gene) child2.append(child2_gene) return (child1, child2) # 定义变异函数 def mutate(solution): for i in range(num_generators): for j in range(num_power_levels): if random.random() < mutation_rate: solution[i][j] = 1 - solution[i][j] return solution # 初始化种群 population = [generate_random_solution() for _ in range(pop_size)] # 迭代优化 for generation in range(num_generations): # 计算每个个体的适应度 fitness_scores = [fitness_function(solution) for solution in population] # 找出当前种群中适应度最高的个体 best_solution = population[fitness_scores.index(max(fitness_scores))] print("Generation {}: Best fitness = {}".format(generation, max(fitness_scores))) # 生成下一代种群 new_population = [] # 选择父母个体进行交叉和变异 for _ in range(pop_size // 2): parent1 = population[random.randint(0, pop_size - 1)] parent2 = population[random.randint(0, pop_size - 1)] child1, child2 = crossover(parent1, parent2) child1 = mutate(child1) child2 = mutate(child2) new_population.append(child1) new_population.append(child2) # 将下一代种群替换当前种群 population = new_population ``` 上述代码演示了一个简单的电网优化调度算法,使用遗传算法对电网的发电机功率进行优化。遗传算法是一种常用的优化算法,其基本思路是通过模拟自然界的进化过程,通过选择、交叉和变异等操作来产生新的解,并不断优化解的质量,最终得到最优解。在上述代码中,适应度函数计算电网在当前时刻的总功率输出和负载之间的比例,越高表示越优秀;交叉函数和变异函数分别对父母个体进行基因交叉和基因变异,产生新的解;最终得到的种群中,适应度最高的个体即为当前时刻的最优解。
评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

总裁余(余登武)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值