select6.m
来自「收集的GA的一些源程序」· M 代码 · 共 66 行
M
66 行
function [out,coefs,pin,best,bestpin]=select6(chrom,d,x,y,s1,s2,s3,best,bestpin)
%
% out=select(in);
%
% selects a new population
%
%
%
% Mix up the population
%
chrom=shuffle(chrom);
%
% Decode the existing population
%
coefs=decodall(chrom,d);
%
% Evaluate its' performance
%
pin=perf6(coefs,x,y,s1,s2,s3);
%
% Find the best
%
[b ind1]=min(pin);
if b < bestpin
bestpin=b;
best=chrom(ind1,:);
end
%
% Now work through the population to
% select the best.
% "Who's the hardest?" selection
%
[D L]=size(chrom);
pin2=pin;
coefs2=coefs;
for i = 1:2:D
if pin(i)<pin(i+1)
chrom(i+1,:)=chrom(i,:);
coefs2(i+1,:)=coefs2(i,:);
pin2(1,i+1)=pin2(1,i);
else
chrom(i,:)=chrom(i+1,:);
coefs2(i,:)=coefs2(i+1,:);
pin2(1,i)=pin2(1,i+1);
end
end
pin=pin2;
coefs=coefs2;
%
% Now replace the worst with the previous best
%
[b ind1]=max(pin);
chrom(ind1,:)=best;
pin(1,ind1)=bestpin;
out=chrom;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?