?? epso.m
字號:
function out=epso(functchc,D,Maxgen,epochtime,Rmax,Rmin,Stop_criteria)
% Exponential Distribution PSO
global initial_flag EpochtimeArr tr FE_success_runs success_runs M O
global result_type
% Parameter Settings
NP=25;C1=2;C2=2;Xmax(1:D)=Rmax;Xmin(1:D)=Rmin;
Vmax = 0.25*(Xmax - Xmin);
%------------------------------
%---------- Initialization of swarm -------------
for count_p = 1:NP
for count_d= 1:D
X(count_p,count_d) = edrand;
V(count_p,count_d) = edrand;
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
%-----------------------------------------------
if epochtime ==1
tic;
end
%-------- Main routine starts ---------------
for count_g = 1:Maxgen
% ---------- Velocity and Possition Updation ---------------------------
for count_p = 1:NP
for count_d= 1:D
V(count_p,count_d)=edrand*(p_best(count_p,count_d)-X(count_p,count_d))+edrand*(g_best(count_d)-X(count_p,count_d));
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
if( X(count_p,:) > Xmin & X(count_p,:) < Xmax)
for count_d= 1:D
xy(count_d)=X(count_p,count_d);
end
current_fitness(count_p)=BENCH_FUNCS(xy,functchc);
end
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
%---------------------------------------
% -------- 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;
FitnessEPSO=g_best_fitness(Maxgen)
else
out=g_best_fitness(Maxgen);
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -