部分代码:
function NSGAII()
clc;format compact;tic;hold on
global fitvalue;
global fitvalue2;
global fitvalue3;
global fitvalue4;
global newpop;
global pop;
global newpop_mut;
%---初始化/参数设定clear all
generations=100; %迭代次数
popnum=50; %种群大小(须为偶数)
M=8; %个体长度
N=5;
cross_rate=0.95;
mutate_rate=0.03;
% minvalue=repmat(zeros(1,poplength),popnum,1); %个体最小值
% maxvalue=repmat(ones(1,poplength),popnum,1); %个体最大值
initpop(popnum,M,N); % 初始化,产生新的初始种群
%---开始迭代进化
for gene=1:generations %开始迭代
%-------交叉
crossover(popnum,M,N, cross_rate);% 交叉操作
% newpopulation=zeros(popnum,poplength); %子代种群
% for i=1:popnum/2 %交叉产生子代
% k=randperm(popnum); %从种群中随机选出两个父母,不采用二进制联赛方法
% beta=(-1).^round(rand(1,poplength)).*abs(randn(1,poplength))*1.481; %采用正态分布交叉产生两个子代
% newpopulation(i*2-1,:)=(population(k(1),:)+population(k(2),:))/2+beta.*(population(k(1),:)-population(k(2),:))./2; %产生第一个子代
% newpopulation(i*2,:)=(population(k(1),:)+population(k(2),:))/2-beta.*(population(k(1),:)-population(k(2),:))./2; %产生第二个子代
% end
%-------变异