truncationselection.m

来自「由我收集或写出的GA源码」· M 代码 · 共 25 行

M
25
字号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File: truncationSelection.m
%
% Description: Perform truncation selection and return the mating pool
% (index of selected individuals)
%
% @param truncParam is the selection pressure parameter
%
% @return winners is an array with the index of the individuals that won
% the tournaments.
%
% Author: Kumara Sastry
%
% Date: March 2007
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function winners = truncationSelection(truncParam, fitness)

n = length(fitness);
numWinners = floor(n*truncParam);
numCopies = ceil(1/truncParam);

[sortedFitness, index] = sort(fitness,'descend');
potentialWinners = repmat(index(1:numWinners),numCopies,1);
winners = potentialWinners(1:n);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?