📄 ceclpso.m
字号:
function out=ceclpso(functchc,D,Maxgen,epochtime,Rmax,Rmin,Stop_criteria)
% Combined Effect Comprehensive learning PSO
global initial_flag EpochtimeArr tr FE_success_runs success_runs M O
global result_type
% Parameter Settings
NP=25;Xmax(1:D)=Rmax;Xmin(1:D)=Rmin;
Vmax = 0.25*(Xmax - Xmin);
P=0.07;m=0.20*D; wmax=0.9; wmin=0.2;w0=0.9; w1=0.2;
%------------------------------
%--- Inertia weight And C1,C2,C3 decreases linearly ----------------
for iter=1:Maxgen
W(iter)=( (w0-w1)*(Maxgen -iter))/Maxgen + w1;
end
%---------- Initialization of swarm -------------
for count_p = 1:NP
for count_d= 1:D
X(count_p,count_d) = rand;
V(count_p,count_d) = rand;
p_best(count_p,count_d) = X(count_p,count_d);
end
end
%------------------------------
%-------------Evaluate fitness value pbest and gbest of all particles
for count_p = 1:NP
for count_d= 1:D
xy(count_d)=X(count_p,count_d);
end
current_fitness(count_p)=BENCH_FUNCS(xy,functchc);
end
[g_best_val,g_best_index] = min(current_fitness);
for count_d = 1:D
g_best(count_d) = X(g_best_index,count_d);
end
%-----------------------------------------------
%------- Second gbest ------------
temp=current_fitness;
temp(g_best_index)=max(current_fitness);
[g_best_val_2,g_best_index_2] = min(temp);
for count_d= 1:D
g_best_2(count_d) = X(g_best_index,count_d);
end
%-------------------------------------
if epochtime ==1
tic;
end
%-------- Main routine starts ---------------
for count_g = 1:Maxgen
%------------------------------
if mod(count_g,10) == 1
for count_p=1:NP
rc=randperm(D);
a(count_p,:)=zeros(1,D);
b(count_p,:)=zeros(1,D) ;
a(count_p,rc(1:m))=1;
b(count_p,:)=ceil(rand(1,D)-1+P);
f(count_p,:)=ceil(rand(1,D).*NP);
end
end
%-------------------------------
%----------------------------- Finding the Trapped Particle
if mod(count_g,10) == 1
if count_g~=1
sorted_fitness=sort(current_fitness);
k=floor(NP./2);
N=k;
if mod(NP,2)~=0
k=k+1;
end
for m=1:N
for q=1:NP
dif =sorted_fitness(k+m)-current_fitness(q);
if dif==0
for count_d=1:D
X(q,count_d)=rand*g_best(count_d);
end
end
end
end
end
end
%----------------------------------------------------------------
% ---------- Velocity and Possition Updation
for count_p = 1:NP
for count_d= 1:D
if a(count_p,count_d)==1
V(count_p,count_d)=W(count_g)*V(count_p,count_d)+rand*(g_best(count_d)-X(count_p,count_d))+rand*(g_best_2(count_d)-X(count_p,count_d));
else if b(count_p,count_d)==1
V(count_p,count_d)=W(count_g)*V(count_p,count_d)+rand*(p_best(f(count_d),count_d)-X(count_p,count_d))+rand*(g_best_2(count_d)-X(count_p,count_d));
else
V(count_p,count_d)=W(count_g)*V(count_p,count_d)+rand*(p_best(count_p,count_d)-X(count_p,count_d))+rand*(g_best_2(count_d)-X(count_p,count_d));
end
end
V(count_p,count_d)=min(Vmax(count_d),max(-Vmax(count_d),V(count_p,count_d)));
X(count_p,count_d)=X(count_p,count_d)+V(count_p,count_d);
end
end
%------------------------------------------------------------------------
% -------- Computing f(xi) ---------
for count_p = 1:NP
for count_d= 1:D
xy(count_d)=X(count_p,count_d);
end
current_fitness(count_p)=BENCH_FUNCS(xy,functchc);
end
% -------- updating pbest---------
for count_p = 1:NP
for count_d= 1:D
xy(count_d)=p_best(count_p,count_d);
end
p_best_fitness(count_p)=BENCH_FUNCS(xy,functchc);
if current_fitness(count_p)< p_best_fitness(count_p)
p_best_fitness(count_p) = current_fitness(count_p);
for count_d = 1:D
p_best(count_p,count_d) = X(count_p,count_d);
end
end
end
%-----------------------------
%--------- Updating gbest------------
for count_d= 1:D
xy(count_d)=g_best(count_d);
end
g_best_fitness(count_g)=BENCH_FUNCS(xy,functchc);
[g_best_val,g_best_index] = min(p_best_fitness);
if g_best_val < g_best_fitness(count_g)
g_best_fitness(count_g)=g_best_val;
for count_d = 1:D
g_best(count_d) = p_best(g_best_index,count_d);
end
end
%---------------------------------------
%------- Updating Second gbest ------------
for count_d= 1:D
xy(count_d)=g_best_2(count_d);
end
g_best_fitness_2(count_g)=BENCH_FUNCS(xy,functchc);
temp=p_best_fitness;
temp(g_best_index)=max(p_best_fitness);
[g_best_val_2,g_best_index_2] = min(temp);
if g_best_val_2 < g_best_fitness_2(count_g)
g_best_fitness_2(count_g)=g_best_val_2;
for count_d = 1:D
g_best_2(count_d) = p_best(g_best_index_2,count_d);
end
end
% -------- Stop criteria ---------
if g_best_fitness(count_g) <Stop_criteria
disp('Stop criteria');
success_runs= success_runs+1;
FE_success_runs(success_runs)=g_best_fitness(count_g);
break
end
%---------------------------------
end
if epochtime ==1
EpochtimeArr(tr)=toc;
end
for n=count_g:Maxgen
g_best_fitness(n)=g_best_fitness(count_g);
end
Value=g_best;
if result_type==1
out=g_best_fitness;
FitnessCECLPSO=g_best_fitness(Maxgen)
else
out=g_best_fitness(Maxgen);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -