?? ycc.m
字號:
xmin=input('請輸入變量的下限:');
xmax=input('請輸入變量的上限:');
popsize=input('請輸入變量的數(shù)目:');
dimsize=input('請輸入粒子的維數(shù):');
pop=unifrnd(xmin,xmax,popsize,2*dimsize);
for i=1:popsize
obfunct1=sin(sqrt(pop(i,1)^2+pop(i,2)^2))^2-0.5;
obfunct2=(1.0+0.001*(pop(i,1)^2+pop(i,2)^2))^2;
objvalue(i,1)=obfunct1/obfunct2-0.5;
end
Pbest=pop(:,1:dimsize);
[gbest,xindex]=max(objvalue);
xtemp=pop(xindex,1:dimsize);
Gbest=xtemp;
c1min=input('請輸入c1的最小值:');
alpha=input('請輸入alpha的值:');
c2max=input('請輸入c2的最大值:');
beta=input('請輸入beta的值:');
generation=input('請輸入進(jìn)化代數(shù):');
speedmax=input('請輸入速度的最大值:');
for t=1:popsize
for dimIndex = 1:dimsize
c1=c1min+alpha*generation;
c2=c2max-alpha*generation;
a0=c1+c2-beta*generation;
phy12=c1*unifrnd(0,1)+c2*unifrnd(0,1);
phyp=c1*unifrnd(0,1)*Pbest(t,dimIndex)+c2*unifrnd(0,1)*Gbest(1,dimIndex);
tempV = a0*pop(t,dimIndex)-phy12*pop(t,dimIndex)+phyp;
if tempV > speedmax
pop(t,dimsize + dimIndex)= speedmax;
elseif tempV <(- speedmax)
pop(t,dimsize + dimIndex)=-speedmax;
else
pop(t,dimsize + dimIndex)= tempV;
end
tempposition = pop(t,dimIndex)+ pop(t,dimsize + dimIndex);
if tempposition > xmax
pop(t,dimIndex)= xmax;
elseif tempposition < xmin
pop(t,dimIndex)= xmin;
else
pop(t,dimIndex)= tempposition;
end
end
end
for i = 1:popsize
obfunct1=sin(sqrt(pop(i,1)^2+pop(i,2)^2))^2-0.5;
obfunct2=(1.0+0.001*(pop(i,1)^2+pop(i,2)^2))^2;
objvalue(i,1)=obfunct1/obfunct2-0.5;
obfunct3=sin(sqrt(Pbest(i,1)^2+Pbest(i,2)^2))^2-0.5;
obfunct4=(1.0+0.001*(Pbest(i,1)^2+Pbest(i,2)^2))^2;
pvalue(i,1)=obfunct3/obfunct4-0.5;
end
obfunct1=sin(sqrt(Gbest(1)^2+Gbest(2)^2))^2-0.5;
obfunct2=(1.0+0.001*(Gbest(1)^2+Gbest(2)^2))^2;
objvaluetemp=obfunct1/obfunct2-0.5;
for i = 1:popsize
if objvalue(i,1)< pvalue(i,1)
PBest(i,1:dimsize)= pop(i,1:dimsize);
end
if objvalue(i,1)< objvaluetemp
GBest = pop(i,1:dimsize)
xtemp = pop(i,1:dimsize)
end
end
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -