%%注意,目标函数的编写有可能会对粒子存档数产生很大影响,可能会使粒子存档数不会正常增加,产生波动,而达不到设置的你Rep
clc;
clear ;
close all;
tic
%% Problem Definition
%% MOPSO Settings
% number_obj=3;%目标函数为3个
nPop=100; % Population Size种群大小100
nRep=100; % Repository Size存档大小为100
MaxIt=150; % Maximum Number of Iterations原始最大迭代次数100
phi1=2.05;%phi1=phi2=2.05
phi2=2.05;
phi=phi1+phi2;%4.1
chi=2/(phi-2+sqrt(phi^2-4*phi));%0.7298
w=chi; % Inertia Weight惯性权重
wdamp=1; % Inertia Weight Damping Ratio惯性权重阻尼比1
c1=chi*phi1; % Personal Learning Coefficient个体学习因子1.4962
c2=chi*phi2; % Global Learning Coefficient群体学习因子1.4962
nVar=55;%可以理解为粒子的维数,24+24+7
% VarMin=[0 0 0 0.0033];%粒子能取到的最小值
% VarMax=[0.00195 0.0009 0.00365 0.0037]; %粒子能取到的最大值
load data_load
load data_sun
% VarMax=repmat(2.2,1,24);VarMax=[VarMax,repmat(0.1,1,24)];VarMax=[VarMax,data_load(4,1:12)];VarMax=[VarMax,data_load(7,1:12)];
% VarMin=repmat(0,1,24);VarMin=[VarMin,repmat(-0.1,1,24)];VarMin=[VarMin,repmat(0,1,12)];VarMin=[VarMin,repmat(0,1,12)];%可平移负荷设置为节点7
VarMax=repmat(0.1,1,24);VarMax=[VarMax,repmat(0.05,1,24)];VarMax=[VarMax,data_load(7,11:14),data_load(7,19:21)];
VarMin=repmat(-0.1,1,24);VarMin=[VarMin,repmat(-0.05,1,24)];VarMin=[VarMin,repmat(0,1,7)];%可平移负荷设置为节点7
end
%% Results
figure
plot(record);
xlabel('迭代次数');ylabel('存档最优目标函数值');
title('存档最优目标函数值迭代过程图');
hold on
%测试rep中粒子位置是否符合储能限制条件
for i=1:100
rep_flag(i)=battery_flag(rep(i).Position);
end
costs=GetCosts(particle);
rep_costs=GetCosts(rep);
[final final_num]=min(integrate);
best_position=rep(final_num).Best.Position;
% plot3(best_position(1),best_position(2),best_position(3),'rP','MarkerSize',12);
% hold on
figure;
subplot(2,1,1)
plot(best_position(1,1:24),'-*');
title('节点10储能运行计划图')
xlabel('时间/h');ylabel('充放电功率/Mw');
grid on
xlim([1 24]);
subplot(2,1,2)
plot(best_position(1,25:48),'-*');
grid on
xlim([1 24]);
title('节点11储能运行计划图')
xlabel('时间/h');ylabel('充放电功率/Mw');
% figure
% temp=data_load(7,1:12)-best_position(1,49:60);
% load7=[temp(1,5:12)+data_load(7,1:8),best_position(1,49:60),temp(1,1:4)+data_load(7,21:24)];
% plot(data_load(7,1:24));hold on
% plot(load7,'-*');hold on;
% xlim([1 24]);
% legend('平移前','平移后')
% title('负荷7平移前与平移后日负荷曲线')
% xlabel('时间/h');ylabel('功率/Mw');
% grid on
figure
temp1=data_load(7,11:14)-best_position(1,49:52);
temp2=data_load(7,19:21)-best_position(1,53:55);
% temp=[temp1,temp2];
load7=[temp1+data_load(7,1:4),temp2+data_load(7,5:7),data_load(7,8:11),best_position(1,49:52),data_load(7,16:18),best_position(1,53:55),data_load(7,22:24)];
plot(data_load(7,1:24));hold on
plot(load7,'-*');hold on;
xlim([1 24]);
legend('平移前','平移后')
title('负荷7平移前与平移后日负荷曲线')
xlabel('时间/h');ylabel('功率/Mw');
grid on
check=zeros(100,1);
for number=1:100
check(number)=particle(number).Dominated;
end
num_position=find(check==0);
num=numel(num_position);
clear i;
figure;
best_cost=rep(final_num).Best.Cost;
plot3(best_cost(1),best_cost(2),best_cost(3),'rP','MarkerSize',16)
hold on
plot3(costs(1,:),costs(2,:),costs(3,:),'b.');
hold on;
plot3(rep_costs(1,:),rep_costs(2,:),rep_costs(3,:),'gx');
% legend('Best Repository','Main Population','Repository');
legend('存档最优值','主要种群值','存档值');
xlabel('用于负荷平移的用户电费/元');ylabel('电网侧成本/元');zlabel('电压偏移');
grid on;
title('种群和存档最优解对应目标函数的值')
if it>MaxIt
disp(['迭代次数达到限制最大值100,','跳出迭代']);
end
disp(['最优解为:',num2str(best_position)]);
disp(['最优值为:',num2str(best_cost)]);
toc
- 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.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
- 206.
- 207.
- 208.
- 209.
- 210.
- 211.
- 212.
- 213.
- 214.
- 215.
- 216.
- 217.
- 218.
- 219.
- 220.
- 221.
- 222.
- 223.
- 224.
- 225.
- 226.
- 227.
- 228.
- 229.
- 230.
- 231.
- 232.
- 233.
- 234.
- 235.
- 236.
- 237.
- 238.
- 239.
- 240.
- 241.
- 242.
- 243.
- 244.