1.问题描述:
dT = 1;
cc = xx;
Hours = 24;
N = 10;%先按10个仿真,你自己测试的时候,改为2000,但是仿真及其缓慢
S = 15;
%充电开始时间概率密度函数
miue = 17.6;
dete = 3.4;
Pet = [7.7+(25.6-7.7)*rand(1,N)];
f1=@(t) 1./dete./sqrt(2*pi).*exp(-(t-miue).^2./2./dete.^2);
f2=@(t) 1./dete./sqrt(2*pi).*exp(-(t+24-miue).^2./2./dete.^2);
tt=linspace(1,24,1000);%蒙特卡洛循环
ff=f1(tt).*(tt<=miue-12)+f2(tt).*(tt>miue-12);%根据公式计算概率密度
ss=trapz(tt,ff); %计算整个区间概率密度的积分
%日行驶里程概率密度函数
miul = 5.15;
detl = 0.88;
ff0 = @(l) 1./l./detl./sqrt(2*pi).*exp(-(log(l)-miul).^2./2./detl.^2);
ll0 = linspace(1,1000,1000);%蒙特卡洛循环
2.部分程序:
clc;
clear;
close all;
warning off;
addpath 'func\'
dim = 24; %变量数量
Lmin = 0.5;
Lmax = 1.5;
c1 = 1.2; %学习因子1
c2 = 1.2; %学习因子2
w = 0.5; %惯性权重
Iters = 30; %最大迭代次数
Num = 500;
%初始化种群的个体(可以在这里限定位置和速度的范围)
x = Lmin + (Lmax-Lmin)*rand(Num,dim); %随机初始化位置
v = Lmin + (Lmax-Lmin)*rand(Num,dim); %随机初始化速度
y = [];
%先计算各个粒子的适应度,并初始化Pi和Pg
for i=1:Num
i
[p(i)] = func_F(x(i,:));
y(i,:)= x(i,:);
end
%全局最优
pg = x(1,:);
for i=2:Num
i
[pa(i)] = func_F(x(i,:));
pb(i) = func_F(pg);
if pa(i) < pb(i)
pg=x(i,:);
end
end
for t=1:Iters
t
for i=1:Num
v(i,:) = w*v(i,:)+c1*rand*(y(i,:)-x(i,:))+c2*rand*(pg-x(i,:));
x(i,:) = x(i,:)+v(i,:);
[pa(i)] = func_F(x(i,:));
if pa(i)<p(i)
p(i) = pa(i);
y(i,:)= x(i,:);
end
[pb(i)] = func_F(pg);
if p(i)<pb(i)
pg=y(i,:);
end
for jj = 1:dim
if pg(jj)>=Lmax|pg(jj)<=Lmin;
pg(jj)=0.8 + randn/4;
end
end
[Pbest(i)] = func_F(pg);
end
Fs(t)=mean(Pbest);
end
figure;
plot(Fs);
xlabel('PSO迭代次数');
ylabel('fitness');
grid on
pg
3.仿真结论:
A-02-73