tselect.m
来自「一种标准的遗传算法实例」· M 代码 · 共 37 行
M
37 行
function mateset = tselect(population,scores,elite)
% TSELECT tournament mating selection
% Version 1.0 Ron Shaffer 1/23/96
%
% set constants
%
[popsize,ndim] = size(population);
%
% With elistist strategy on you only need to choose a mating set with popsize - 1
% members in it b/c the last spot is save for the elite chromosome
%
if elite == 1
popsize = popsize - 1;
end
%
% compute vector of random integers
%
randlist = [round(rand((popsize*2),1)*popsize+0.5)];
%
% Begin tournament selection
%
count = 0;
for i = 1:popsize
count = count + 2;
cmo = count - 1;
%
% 2 randomly chosen chromosomes from population
% will compete for inclusion in mating subset
%
if scores(randlist(count)) > scores(randlist(cmo))
mateset(i,1:ndim) = population(randlist(count),1:ndim);
else
mateset(i,1:ndim) = population(randlist(cmo),1:ndim);
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?