ACO-MPPT ant colony optimization, mppt
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
am working on maximum power point tracking using ant colony optimization technique. but i dont know the fitness function of ant colony system for my MPPT. i am attaching a working code for aco n panel
code for panel
function Ipv = fcn(u)
% This block supports an embeddable subset of the MATLAB language.
% See the help menu for details.
TaC=u(1); Suns=u(2); Va=u(3); Ia=0;
if Va<0
Va=0;
end
if(Va<25.06)
k=1.38e-23;
q=1.60e-19;
A=2.5; Vg=1.12; Ns=36;
T1=273+25;
Voc_T1=10/Ns;
Isc_T1=5;
T2=273+75;
Voc_T2=9/Ns;
Isc_T2=6;
TaK=273+TaC;
TrK=273+25;
Iph_T1=Isc_T1*Suns;
a=(Isc_T2-Isc_T1)/Isc_T1*1/(T2-T1);
Iph=Iph_T1*(1+a*(TaK-T1));
Vt_T1=k*T1/q;
Ir_T1=Isc_T1/(exp(Voc_T1/(A*Vt_T1))-1);
Ir_T2=Isc_T2/(exp(Voc_T2/(A*Vt_T1))-1);
b=Vg*q/(A*k);
Ir=Ir_T1*((TaK/T1)^(3/A))*exp(-b*(1/TaK-1/T1));
X2v=(Ir_T1/(A*Vt_T1))*exp(Voc_T1/(A*Vt_T1));
dVdI_Voc=-1.15/Ns/2;
Rs=-dVdI_Voc-1/X2v;
Vt_Ta=A*k*TaK/q;
Vc=Va/Ns;
A1=Iph-Ia-Ir*(exp((Vc+Ia*Rs)/Vt_Ta)-1);
A2=-1-Ir*(exp((Vc+Ia*Rs)/Vt_Ta)-1)*(Rs/Vt_Ta);
Ia=Ia-A1/A2;
if (Ia>10)
Ia=10;
end
if (Ia<0)
Ia=0;
end
if (Va>25.06)
Ia=0;
end
else
Ia=0;
end
Ipv=Ia/10;
code for Ant colony system
% Initialize the parameters of Ant = 50;% ant-scale ECHO = 50;% iterations% F = (X1.-1) ^ 2 + (X2.-2.2) ^ 2 +1;% step = function to be optimized 0.1 * rand (1);% of local search step size temp = [0,0];
%各子区间长度start1=0; % Of each sub-interval length start1 = 0;
end1=2; end1 = 2;
start2=1; start2 = 1;
end2=3; end2 = 3;
Len1=(end1-start1)/Ant; Len1 = (end1-start1) / Ant;
Len2=(end2-start2)/Ant; Len2 = (end2-start2) / Ant;
%P = 0.2; % P = 0.2;
%初始化蚂蚁位置subplot(2,2,1); % Initialize the ant location subplot (2,2,1);
for i=1:Ant for i = 1: Ant
X(i,1)=(start1+(end1-start1)*rand(1)); X (i, 1) = (start1 + (end1-start1) * rand (1));
X(i,2)=(start2+(end2-start2)*rand(1)); X (i, 2) = (start2 + (end2-start2) * rand (1));
T0(i)=exp(-((X(i,1)-1)^2+(X(i,2)-2.2)^2+1));%初始信息素,随函数值大,信息素浓度小,反之亦然plot(X(i,1),X(i,2),'k.') T0 (i) = exp (- ((X (i, 1) -1) ^ 2 + (X (i, 2) -2.2) ^ 2 +1));% initial pheromone, with the function value is large, pheromone concentration is small, and vice versa plot (X (i, 1), X (i, 2), 'k.')
hold on; hold on;
title('(a)'); title ('(a)');
xlabel('X1'); xlabel ('X1');
ylabel('X2'); ylabel ('X2');
grid on; grid on;
end; end;
%至此初始化完成for Echo=1:ECHO %开始寻优%P0函数定义,P0为全局转移选择因子a1=0.9; % At this point the initialization is complete for Echo = 1: ECHO% start% P0 optimization function definition, P0 is the global shift selector a1 = 0.9;
b1=(1/ECHO)*2*log(1/2); b1 = (1/ECHO) * 2 * log (1 / 2);
f1=a1*exp(b1*Echo); f1 = a1 * exp (b1 * Echo);
a2=0.225; a2 = 0.225;
b2=(1/ECHO)*2*log(2); b2 = (1/ECHO) * 2 * log (2);
f2=a2*exp(b2*Echo); f2 = a2 * exp (b2 * Echo);
if Echo=(ECHO/2) if Echo = (ECHO / 2)
P0=f1; P0 = f1;
else else
P0=f2; P0 = f2;
end; end;
%P函数定义,P为信息素蒸发系数a3=0.1; % P function definition, P is the pheromone evaporation coefficient a3 = 0.1;
b3=(1/ECHO).*log(9); b3 = (1/ECHO) .* log (9);
P=a3*exp(b3*Echo); P = a3 * exp (b3 * Echo);
lamda=0.10+(0.14-0.1)*rand(1);%全局转移步长参数Wmax=1.0+(1.4-1.0)*rand(1);%步长更新参数上限Wmin=0.2+(0.8-0.2)*rand(1);%步长更新参数下限%寻找初始最优值T_Best=T0(1); lamda = 0.10 + (0.14-0.1) * rand (1);% global transfer step size parameter Wmax = 1.0 + (1.4-1.0) * rand (1);% update the step size parameter limit Wmin = 0.2 + (0.8-0.2 ) * rand (1);% limit% step update parameters to find the optimal initial value T_Best = T0 (1);
for j=1:Ant for j = 1: Ant
if T0(j)>=T_Best if T0 (j)> = T_Best
T_Best=T0(j); T_Best = T0 (j);
BestIndex=j; BestIndex = j;
end; end;
end; end;
W=Wmax-(Wmax-Wmin)*(Echo/ECHO); %局部搜索步长更新参数for j_g=1:Ant %全局转移概率求取,当该蚂蚁随在位置不是bestindex时if j_g~=BestIndex W = Wmax-(Wmax-Wmin) * (Echo / ECHO);% update the local search step length parameter for j_g = 1: Ant% overall transition probability to strike, when the ants with the position when not bestindex if j_g ~ = BestIndex
r=T0(BestIndex)-T0(j_g); r = T0 (BestIndex)-T0 (j_g);
Prob(j_g)=exp(r)/exp(T0(BestIndex)); Prob (j_g) = exp (r) / exp (T0 (BestIndex));
else %当j_g=BestIndex的时候进行局部搜索if rand(1)<0.5 else% When j_g = BestIndex when the local search if rand (1) <0.5
temp(1,1)=X(BestIndex,1)+W*step; temp (1,1) = X (BestIndex, 1) + W * step;
temp(1,2)=X(BestIndex,2)+W*step; temp (1,2) = X (BestIndex, 2) + W * step;
else else
temp(1,1)=X(BestIndex,1)-W*step; temp (1,1) = X (BestIndex, 1)-W * step;
temp(1,2)=X(BestIndex,2)-W*step; temp (1,2) = X (BestIndex, 2)-W * step;
end; end;
Prob(j_g)=0;%bestindex的蚂蚁不进行全局转移end; Prob (j_g) = 0;% bestindex global transfer of ants without end;
X1_T=temp(1,1); X1_T = temp (1,1);
X2_T=temp(1,2); X2_T = temp (1,2);
X1_B=X(BestIndex,1); X1_B = X (BestIndex, 1);
X2_B=X(BestIndex,2); X2_B = X (BestIndex, 2);
F1_T=(X1_T-1).^2+(X2_T-2.2).^2+1; F1_T = (X1_T-1). ^ 2 + (X2_T-2.2). ^ 2 +1;
F1_B=(X1_B-1).^2+(X2_B-2.2).^2+1; F1_B = (X1_B-1). ^ 2 + (X2_B-2.2). ^ 2 +1;
if exp(-F1_T)>exp(-F1_B) if exp (-F1_T)> exp (-F1_B)
X(BestIndex,1)=temp(1,1); X (BestIndex, 1) = temp (1,1);
X(BestIndex,2)=temp(1,2); X (BestIndex, 2) = temp (1,2);
end; end;
end; end;
for j_g_tr=1:Ant for j_g_tr = 1: Ant
if Prob(j_g_tr)<P0 if Prob (j_g_tr) <P0
X(j_g_tr,1)=X(j_g_tr,1)+lamda*(X(BestIndex,1)-X(j_g_tr,1));%Xi=Xi+lamda*(Xbest-Xi) X (j_g_tr, 1) = X (j_g_tr, 1) + lamda * (X (BestIndex, 1)-X (j_g_tr, 1));% Xi = Xi + lamda * (Xbest-Xi)
X(j_g_tr,2)=X(j_g_tr,2)+lamda*(X(BestIndex,2)-X(j_g_tr,2));%Xi=Xi+lamda*(Xbest-Xi) X (j_g_tr, 2) = X (j_g_tr, 2) + lamda * (X (BestIndex, 2)-X (j_g_tr, 2));% Xi = Xi + lamda * (Xbest-Xi)
else else
X(j_g_tr,1)=X(j_g_tr,1)+((-1)+2*rand(1))*Len1;%Xi=Xi+rand(-1,1)*Len1 X (j_g_tr, 1) = X (j_g_tr, 1 )+((- 1) +2 * rand (1)) * Len1;% Xi = Xi + rand (-1,1) * Len1
X(j_g_tr,2)=X(j_g_tr,2)+((-1)+2*rand(1))*Len2;%Xi=Xi+rand(-1,1)*Len2 X (j_g_tr, 2) = X (j_g_tr, 2 )+((- 1) +2 * rand (1)) * Len2;% Xi = Xi + rand (-1,1) * Len2
end; end;
end; end;
%信息素更新for t_t=1:Ant % Pheromone update for t_t = 1: Ant
T0(t_t)=(1-P)*T0(t_t)+(exp(-(X(t_t,1)-1).^2+(X(t_t,2)-2.2).^2+1)); T0 (t_t) = (1-P) * T0 (t_t) + (exp (- (X (t_t, 1) -1). ^ 2 + (X (t_t, 2) -2.2). ^ 2 +1) );
end; end;
if Echo==round(ECHO/3)%迭代经过1/3时用绿色点表示蚂蚁的分布位置subplot(2,2,2); if Echo == round (ECHO / 3)% iterate through the 1 / 3 with the distribution of ants green dot position subplot (2,2,2);
for i_draw1=1:Ant for i_draw1 = 1: Ant
plot(X(i_draw1,1),X(i_draw1,2),'g.') plot (X (i_draw1, 1), X (i_draw1, 2), 'g.')
axis([0 2 1 3]); axis ([0 2 1 3]);
hold on; hold on;
title('(b)'); title ('(b)');
xlabel('X1'); xlabel ('X1');
ylabel('X2'); ylabel ('X2');
end; end;
grid on; grid on;
end; end;
[c_iter,i_iter]=max(T0); %求取每代全局最优解minpoint_iter=[X(i_iter,1),X(i_iter,2)]; [C_iter, i_iter] = max (T0);% of each generation to strike a global optimal solution minpoint_iter = [X (i_iter, 1), X (i_iter, 2)];
minvalue_iter=(X(i_iter,1)-1).^2+(X(i_iter,2)-2.2).^2+1; minvalue_iter = (X (i_iter, 1) -1). ^ 2 + (X (i_iter, 2) -2.2). ^ 2 +1;
min_local(Echo)=minvalue_iter;%保存每代局部最优解%将每代全局最优解存到min_global矩阵中if Echo >= 2 min_local (Echo) = minvalue_iter;% save% local optimal solution of each generation will keep the global optimal solution of each generation to min_global matrix if Echo> = 2
if min_local(Echo)<min_global(Echo-1) if min_local (Echo) <min_global (Echo-1)
min_global(Echo)=min_local(Echo); min_global (Echo) = min_local (Echo);
else else
min_global(Echo)=min_global(Echo-1); min_global (Echo) = min_global (Echo-1);
end; end;
else else
min_global(Echo)=minvalue_iter; min_global (Echo) = minvalue_iter;
end; end;
end;%ECHO循环结束subplot(2,2,3); end;% ECHO loop end subplot (2,2,3);
for i_draw3=1:Ant for i_draw3 = 1: Ant
plot(X(i_draw3,1),X(i_draw3,2),'r.')%迭代结束用红色点表示蚂蚁的分布位置axis([0 2 1 3]); plot (X (i_draw3, 1), X (i_draw3, 2), 'r.')% red dot end of the iteration the distribution of ant position axis ([0 2 1 3]);
hold on; hold on;
title('(c)'); title ('(c)');
xlabel('X1'); xlabel ('X1');
ylabel('X2'); ylabel ('X2');
end; end;
grid on; grid on;
subplot(2,2,4); subplot (2,2,4);
min_global=min_global'; min_global = min_global ';
index(:,1)=1:ECHO; index (:, 1) = 1: ECHO;
plot(index(:,1), min_global(:,1),'b-') plot (index (:, 1), min_global (:, 1), 'b-')
hold on; hold on;
title('(d)'); title ('(d)');
xlabel('iteration'); xlabel ('iteration');
ylabel('f(x)'); ylabel ('f (x)');
grid on; grid on;
[c_max,i_max]=max(T0); [C_max, i_max] = max (T0);
minpoint=[X(i_max,1),X(i_max,2)] minpoint = [X (i_max, 1), X (i_max, 2)]
minvalue=(X(i_max,1)-1).^2+(X(i_max,2)-2.2).^2+1 minvalue = (X (i_max, 1) -1). ^ 2 + (X (i_max, 2) -2.2). ^ 2 +1
runtime=toc runtime = toc
thanks for helping in advance
5 Kommentare
Antworten (0)
Communitys
Weitere Antworten in Power Electronics Control
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!