目录
一、背景
二、源程序及结果
simulink%E4%BB%BF%E7%9C%9F%E7%A8%8B%E5%BA%8F-toc" name="tableOfContents" style="margin-left:120px">2.1 simulink仿真程序
2.2 GA模块源程序
2.3 PSO模块源程序
三、程序运行结果
3.1 基于GA优化的MPPT
3.2 基于PSO优化的MPPT
一、背景
MPPT策略能够显著提高光伏、风电等发电效率,节省大量成本。该策略的经典算法是:采用遗传算法(GA)和粒子群优化算法(PSO)进行MPPT控制器中调节器占空比的实时寻优。
只有将这两种经典算法吃明白了,才算入了门,可以在后续MPPT策略改进中游刃有余,答辩时也能信手拈来。
GA和PSO策略不多赘述,核心在于此时在线优化,而非离线优化。即以实时局部最优策略进行MPPT控制。建议大家吃透源程序
二、源程序及结果
在线优化有源程序基于遗传算法(GA)和粒子群优化(PSO)算法的MPPT控制策略资源-CSDN文库
simulink%E4%BB%BF%E7%9C%9F%E7%A8%8B%E5%BA%8F" name="2.1%20simulink%E4%BB%BF%E7%9C%9F%E7%A8%8B%E5%BA%8F">2.1 simulink仿真程序
2.2 GA模块源程序
function D = GSA(Vpv,Ipv)
coder.extrinsic('randi')
persistent u;
persistent dcurrent;%store current duty cycle
persistent pbest;%store local best dc for power
persistent force; %store force
persistent acceleration; %store acceleration
persistent mass; % mass
persistent q; % strength of mass
persistent p; % power for each particle
persistent p_current; % power current for each particle
persistent p_min; % power min for each particle
persistent worse; %store best worse of each particle
persistent dc; %store duty cycle ~ position
persistent v; %velocity
persistent counter; %delay iteration
persistent iteration;
persistent gbest;%store global best dc for power
%initializationmax_iter = 3000;
if(isempty(counter))counter = 0;dcurrent = 0.5; gbest = 0.5;pbest = zeros(3,1);worse = zeros(3,1);v = zeros (3,1);force = zeros(3,1);mass = zeros(3,1);q = zeros(3,1);p = zeros(3,1);p_current = zeros(3,1);p_min=zeros(3,1);acceleration=zeros(3,1);u = 0;dc = zeros (3,1); iteration = 1;%initialize position for each particledc(1)=0.69;dc(2)= 0.7;dc(3)=0.8;endif(counter >=1 && counter < 3000)D=dcurrent;counter= counter+1;return;
endif(u>=1 && u<=3)p_current(u) = Vpv*Ipv;if((Vpv*Ipv)>=p(u))p(u) = Vpv*Ipv;pbest(u)=dcurrent;endif(Vpv*Ipv < p_min(u))p_min(u) = Vpv*Ipv;worse(u) = dcurrent;end
end
u=u+1;
if(u==5)u=1;
end
if(u >= 1 && u <= 3)%Avoid over shootingif(iteration < max_iter)D=dc(u);dcurrent=D;counter=1;return;elseD = dcurrent;returnend
elseif(u==4)iteration = iteration +1;[~,i]=max(p);gbest=pbest(i);D=gbest;dcurrent=D;counter=1;%Calculate strength of massfor i = 1:3q(i) = (p_current(i) - worse(i))/(pbest(i)-worse(i));end%Calculate sum of strength of masssum_strength_of_mass = q(1) + q(2) + q(3);%Calculate mass for i = 1:3mass(i) = q(i)/sum_strength_of_mass;end%Calculate forcealpha = 200;G0 = 1;G = G0 * exp(-alpha*iteration/max_iter);%G = 6.67430 * 10^-13; %gravitational constante = 2.2204*10^-16;force(1) = rand()*G*(mass(3)*mass(1)*(dc(3)-dc(1))/(Euclidian_distance(dc(3),dc(1))+e) + mass(2)*mass(1)*(dc(3)-dc(1))/(Euclidian_distance(dc(3),dc(1))+e));force(2) = rand()*G*(mass(3)*mass(2)*(dc(3)-dc(2))/(Euclidian_distance(dc(3),dc(2))+e) + mass(1)*mass(2)*(dc(1)-dc(2))/(Euclidian_distance(dc(1),dc(2))+e));force(3) = rand()*G*(mass(2)*mass(3)*(dc(2)-dc(3))/(Euclidian_distance(dc(2),dc(3))+e) + mass(1)*mass(3)*(dc(1)-dc(3))/(Euclidian_distance(dc(1),dc(3))+e));%Avoid over shootingif(iteration == max_iter)D=dcurrent;return;end%Calculate acceleration for i = 1:3acceleration(i) = force(i)/mass(i);endfor i=1:3v(i)=updatevelocity(v(i),acceleration(i));dc(i)=updateduty(dc(i),v(i));end return;elseD=0.5;
end
endfunction d = Euclidian_distance(d1,d2)d = sqrt(d1^2+d2^2);
endfunction vfinal=updatevelocity(velocity,acceleration)vfinal = rand()*velocity + acceleration;
endfunction dfinal=updateduty(d,velocity)
dup=d+velocity;
if(dup>1)dfinal=1;
elseif(dup<0.1)dfinal=0.1;
elsedfinal=dup;
end
end
2.3 PSO模块源程序
function D = PSO(Vpv, Ipv)coder.extrinsic('randi')persistent localbest globalbest k p dc Pbest Pprev dcurrent u v temp;c1 = 1;c2 = 2;P = Ipv * Vpv;if isempty(globalbest)k = 0;dc = zeros(3,1);dc(1)=randi( [5 330])/1000;dc(2)=randi( [330 660])/1000;dc(3)=randi( [660 995])/1000;p = zeros(3,1);localbest = zeros(3,1);v = zeros(3,1);Pbest = Ipv * Vpv;Pprev = 0;dcurrent = 0.5;globalbest = dcurrent;u=0;temp = 0;endD=dcurrent;if (temp < 0)temp = temp + 1;return;endif (P > Pbest)Pbest = P; endif (k < 3000)k=k+1;return;elsek=0;endif abs(P - Pprev) < 1if abs(P - Pbest) > 15dc(1)=randi( [5 330])/1000;dc(2)=randi( [330 660])/1000;dc(3)=randi( [660 995])/1000;v = zeros(3,1);localbest = zeros(3,1);p = zeros(3,1);u= 0;endendif(u>=1 && u<=3)if(P>p(u))p(u)=P;localbest(u)=dcurrent;endendu=u+1;if (u > 4)u=1;endif (u == 4)[~,idx]=max(p);globalbest=localbest(idx);D = globalbest;dcurrent=D;for j=1:3v(j)=updatevelocity(c1,c2,v(j),localbest(j),dc(j),globalbest);dc(j)=updateduty(dc(j),v(j));endelseD=dc(u);dcurrent=dc(u);Pprev = P;endendfunction vfinal=updatevelocity(c1,c2,velocity,pobest,d,gwbest)% PSO Parametersvfinal = (0.1*velocity)+(c1*rand(1)*(pobest-d))+(c2*rand(1)*(gwbest-d));
endfunction dfinal=updateduty(d,velocity)dup=d+velocity;if(dup>1)dfinal=1;elseif(dup<0)dfinal=abs(dup);elsedfinal=dup;end
end
三、程序运行结果
3.1 基于GA优化的MPPT
3.2 基于PSO优化的MPPT
四、源程序获取
上述章节已经给出了框图和源码,但一定要喂到嘴里,下载即可:
在线优化有源程序基于遗传算法(GA)和粒子群优化(PSO)算法的MPPT控制策略资源-CSDN文库