1.问题描述:
function Z=fitness(x)
z1=1-exp(-sum((x-(1/sqrt(3))).^2));
z2=1-exp(-sum((x+(1/sqrt(3))).^2));
Z=[z1 z2]';
end
2.部分程序:
clc
clear
close all
format shortG
%% parameters setting
nvar=3; % number of variable
lb=[-4 -4 -4]; % lower bound
ub=[4 4 4]; % upper bound
nparticle=50; % number of particle
nrep=200; % number of repository
maxiter=200; % max iteration
nobj=2; % number of objective
Ngrid=3;
beta=10;
lambda=10;
w=1;
c1=2;
c2=2;
wdamp=0.95;
%% initialization
empty.pos=[];
empty.cost=[];
empty.velocity=[];
empty.isdominate=0;
particle=repmat(empty,nparticle,1);
for i=1:nparticle
particle(i).pos=lb+rand(1,nvar).*(ub-lb);
particle(i).cost=fitness(particle(i).pos);
particle(i).velocity=zeros(1,nvar);
end
bparticle=particle;
[particle Q]=determinate_repository(particle);
rep=particle(Q);
grid=create_grid(rep,Ngrid,nobj);
M=create_M(nobj,Ngrid);
rep=determinate_index(rep,M,nobj,grid);
%% main loop
for iter=1:maxiter
for i=1:nparticle
leader=determinate_leader(rep,beta);
particle(i).velocity=w*particle(i).velocity...
+c1*rand(1,nvar).*(bparticle(i).pos-particle(i).pos)...
+c2*rand(1,nvar).*(leader.pos-particle(i).pos);
particle(i).pos=particle(i).pos+particle(i).velocity;
particle(i).pos=min(particle(i).pos,ub);
particle(i).pos=max(particle(i).pos,lb);
particle(i).cost=fitness(particle(i).pos);
if domination(particle(i).cost,bparticle(i).cost)
bparticle(i)=particle(i);
elseif domination(bparticle(i).cost,particle(i).cost)
else
if rand<0.5
bparticle(i)=particle(i);
end
end
end
[particle Q]=determinate_repository(particle);
newrep=particle(Q);
grid=create_grid(rep,Ngrid,nobj);
newrep=determinate_index(newrep,M,nobj,grid);
[rep]=[rep;newrep];
[rep Q]=determinate_repository(rep);
rep=rep(Q);
extra=length(rep)-nrep;
if extra>0
for i=1:extra
rep=delet_ones_rep(rep,lambda);
end
end
disp([ ' iter = ' num2str(iter) ' Nrep = ' num2str(length(rep))]);
Crep=[rep.cost]';
Cp=[particle.cost]';
figure(1)
plot(Crep(:,1),Crep(:,2),'r*')
hold on
plot(Cp(:,1),Cp(:,2),'bo')
hold off
w=w*wdamp;
end
%% results
pareto=rep;
3.仿真结论:
D*56