赛事选择:
伪代码:
choose k (the tournament size) individuals from the population at random
choose the best individual from pool/tournament with probability p
choose the second best individual with probability p*(1-p)
choose the third best individual with probability p*((1-p)^2)
and so on...
Run Code Online (Sandbox Code Playgroud)
确定性锦标赛选择在任何锦标赛中选择最佳个人(当 p = 1 时)。单向锦标赛 (k = 1) 选择等效于随机选择。如果需要,可以从进行选择的群体中移除所选择的个体,否则可以多次为下一代选择个体。与(随机)适应度比例选择方法相比,锦标赛选择由于缺乏随机噪声而在实践中经常实施。
MatLab 中的比赛选择:
Matepool=randi(PopLength,PopLength,2);%%select two individuals randomly for tournament and chooose the one with best fitness value
%% number of tournament is equal to the number of population size
for i=1:PopLength
if Fitness(Matepool(i,1))>= Fitness(Matepool(i,2))
SelectedPop(i,1:IndLength)=CurrentPop(Matepool(i,1),1:IndLength);
else
SelectedPop(i,1:IndLength)=CurrentPop(Matepool(i,2),1:IndLength);
end
end
Run Code Online (Sandbox Code Playgroud)
考虑到您正在使用健身标准,这里有一个可以帮助您的伪代码.
func tournament_selection(pop, k):
best = null
for i=1 to k
ind = pop[random(1, N)]
if (best == null) or fitness(ind) > fitness(best)
best = ind
return best
Run Code Online (Sandbox Code Playgroud)
所以基本上你所遵循的方法很好.虽然有更多的交叉和东西,我想你已经照顾它了.
具有出色解决方案的参考链接 - 遗传算法中的锦标赛选择
要扩展它,请使用另一个变量'better'.做类似的事情 -
better = best
best = ind
Run Code Online (Sandbox Code Playgroud)
返回时,返回一个对象,这是一对这两个变量.
或者另一种方法是 - 两次调用相同的函数实例,它将返回BEST和BEST-1.代码中需要进行一些调整才能处理Sample.
PS:这可能不是最佳方法.