?? cde.asv
字號:
function DE
D=2;%維數
NP=25;%NP為種群規模----
F=0.9;%交叉因子
CR=0.9;%交叉概率
eps=1e-20;%精度
gen_max=200;%最大進化代數
%----混沌搜索參數---------------
format long
C=0.1;%為早熟判斷的閾值
M=60;%混沌搜索次數
T=10;
r=0.2;%交叉系數,不斷減小的
s=0.3;%區間縮短率
%--------------------------------
bounds=100*ones(D,2);
bounds(:,1)=-1*bounds(:,1);
rng=(bounds(:,2)-bounds(:,1))';
x=(ones(NP,1)*rng).*(rand(NP,D))+(ones(NP,1)*bounds(:,1)');%初始種群
count=1;
trial=zeros(1,D);
cost=zeros(1,NP);
cost(1)=fitness(x(1,:),D);
Pb=cost(1);%存放最優值
Xb=x(1,:);%存放最優位置
for i=2:NP
cost(i)=fitness(x(i,:),D);
if(cost(i)<=Pb)
Pb=cost(i);
Xb=x(i,:);
end
end
while(count<gen_max)%count<gen_max abs(Pb)>eps
for i=1:NP
while 2>1
a=floor(rand*NP)+1;
if a~=i
break;
end
end
while 2>1
b=floor(rand*NP)+1;
if b~=i&b~=a
break;
end
end
while 2>1
c=floor(rand*NP)+1;
if c~=i&c~=a&c~=b
break;
end
end
jrand=floor(rand*D+1);
for k=1:D
if(rand<CR|jrand==k)
trial(k)=x(c,k)+F*(x(a,k)-x(b,k));
else
trial(k)=x(i,k);
end
if trial(k)<bounds(k,1)
trial(k)=bounds(k,1);
end
if trial(k)>bounds(k,2)
trial(k)=bounds(k,2);
end
end
score=fitness(trial(:),D);
if(score<=cost(i))
x(i,1:D)=trial(1:D);
cost(i)=score;
end
if cost(i)<=Pb
Pb=cost(i);
Xb(1:D)=x(i,1:D);
end
end
%-------開始混沌搜索--------
%----計算粒子的適應度方差---
favg=0;
for i=1:NP
favg=favg+cost(i)/NP;
end
f=abs(cost(1)-favg);
thet=(cost(1)-favg)^2;
for j=2:NP
thet=thet+(cost(j)-favg)^2;
kk=abs(cost(j)-favg);
if f<kk
f=kk;
end
end
if f<=1
f=1;
end
thet=thet/(f^2);
%-----thet存放早熟判斷------
%----根據thet的值來判斷是否進行混沌搜索-----
if thet<C
while k<M
yb=Xb+rid*(2*y0-1);
mm=fitness(yb,D)
if mm<Pb
Xb=yb;
Pb=mm;
end
end
end
%------混沌搜索結束----------
count=count+1;
end
%--------------結束搜索---------------
count
Xb
Pb
%-------函數值計算-----------------------
function eval=fitness(x,D)
sol=x;
eval=0;
eval=0.5-(sin(sqrt(sol(1)^2+sol(2)^2))^2-0.5)/(1+0.001*(sol(1)^2+sol(2)^2)^2);
eval=-eval;
%----------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -