1 简介

分布式能源系统是能源利用的未来趋势,其中协同经济优化运行是实现能量供需平衡、 降低能源站成本的关键.首先从冷热电协同优化运行入手,建立了包括蓄电池、海水发电以及风光储在内的分布式能源协同运行优化模型,然后考虑设备约束和系统约束,目标函数综合考虑运行成本和环境成本,采用粒子群优化算法求解.结果表明,针对国内某示范园区分布式能源系统进行优化验证,所提方法能够有效降低总成本,提高分布式能源系统经济效益,促进可再生能源充分消纳.

2 部分代码


          
          
clear
clc
close all
%% 参数初始化
pso_option = struct('c1',2.05,'c2',2.05,'maxgen',5000,'sizepop',30, ...
'k',0.6,'wV',1.1,'wP',1.1,'v',5, ...
'popmax',30,'popmin',-30);
D=10;
Vmax = pso_option.k*pso_option.popmax;
Vmin = -Vmax ;
eps = 10^(-5);
%% 产生初始粒子和速度
for i=1:pso_option.sizepop
% 随机产生种群和速度
pop(i,:) = (pso_option.popmax-pso_option.popmin)*rand(1,D)+pso_option.popmin;
V(i,:)=Vmax*rands(1,D);
% 计算初始适应度
fitness(i)=myfunc_fit1(pop(i,:));
end
% 找极值和极值点
[global_fitness bestindex]=min(fitness); % 全局极值
local_fitness=fitness; % 个体极值初始化
global_x=pop(bestindex,:); % 全局极值点
local_x=pop; % 个体极值点初始化
% 每一代种群的平均适应度
avgfitness_gen = zeros(1,pso_option.maxgen);
%% 迭代寻优
for i=1:pso_option.maxgen
for j=1:pso_option.sizepop
%速度更新
V(j,:) = pso_option.wV*V(j,:) + pso_option.c1*rand*(local_x(j,:) - pop(j,:)) + pso_option.c2*rand*(global_x - pop(j,:));
if find(V(j,:) > Vmax)
V_maxflag=find(V(j,:) > Vmax);
V(j,V_maxflag) = Vmax;
end
if find(V(j,1) < Vmin)
V_minflag=find(V(j,1) < Vmin);
V(j,V_minflag) = Vmin;
end
%种群更新
pop(j,:)=pop(j,:) + pso_option.wP*V(j,:);
if find(pop(j,:) > pso_option.popmax)
pop_maxflag=find(pop(j,:) > pso_option.popmax);
pop(j,pop_maxflag) = pso_option.popmax;
end
if find(pop(j,:) < pso_option.popmin)
pop_minflag=find(pop(j,:) < pso_option.popmin);
pop(j,pop_minflag) = pso_option.popmin;
end
% 自适应粒子变异
if rand>0.5
k=ceil(2*rand);
pop(j,k) = (pso_option.popmax-pso_option.popmin)*rand + pso_option.popmin;
end
%适应度值
fitness(j)=myfunc_fit1(pop(j,:));
%个体最优更新
if fitness(j) < local_fitness(j)
local_x(j,:) = pop(j,:);
local_fitness(j) = fitness(j);
end
if fitness(j) == local_fitness(j) && length(pop(j,:) < local_x(j,:))
local_flag=find(pop(j,:) < local_x(j,:));
local_x(j,local_flag) = pop(j,local_flag);
local_fitness(j) = fitness(j);
end
%群体最优更新
if fitness(j) < global_fitness
global_x = pop(j,:);
global_fitness = fitness(j);
end
% if abs( fitness(j)-global_fitness )<=eps && length(pop(j,:) < global_x)
% global_flag=find(pop(j,:) < global_x);
% global_x(global_flag) = pop(j,global_flag);
% global_fitness = fitness(j);
% end
end
fit_gen(i)=global_fitness;
avgfitness_gen(i) = sum(fitness)/pso_option.sizepop;
end
xlswrite('fit_gen.xlsx',fit_gen);
xlswrite('avgfitness_gen.xlsx',avgfitness_gen);
%% 结果分析
figure;
hold on;
plot(fit_gen,'r*-','LineWidth',1.5);
plot(avgfitness_gen,'o-','LineWidth',1.5);
legend('最佳适应度','平均适应度');
xlabel('进化代数','FontSize',12);
ylabel('适应度','FontSize',12);
grid on;
bestX = global_x;
bestCVmse = fit_gen(pso_option.maxgen);
line1 = '适应度曲线MSE[PSOmethod]';
line2 = ['(参数c1=',num2str(pso_option.c1), ...
',c2=',num2str(pso_option.c2),',终止代数=', ...
num2str(pso_option.maxgen),',种群数量pop=', ...
num2str(pso_option.sizepop),')'];
title({line1;line2},'FontSize',12);
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.

3 仿真结果

【优化调度】基于粒子群算法求解分布式能源调度优化问题含Matlab源码_极值

【优化调度】基于粒子群算法求解分布式能源调度优化问题含Matlab源码_极值_02

4 参考文献

[1]王禹, 彭道刚, 姚峻,等. 基于改进粒子群算法的分布式能源系统协同优化运行研究[J]. 浙江电力, 2019, 038(002):33-39.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

【优化调度】基于粒子群算法求解分布式能源调度优化问题含Matlab源码_优化算法_03