⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 select6.m

📁 王小平老师的遗传算法-理论应用与软件实现的源代码(matlab
💻 M
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -