📄 restrictedtournamentreplacement.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File: restrictedTournamentReplacement.m
%
% Description: Perform restricted tournament replacement. For every
% offspring select the closest parent from among w randomly chosen parents.
% If the offspring is better than the closest parent then it replaces the
% parent.
%
% @param population is the parent population
%
% @param fitness is the fitness of parent individuals
%
% @param newPopulation is the offspring population
%
% @param newFitness is the fitness of offspring individuals
%
% @param windowSize is the fitness of offspring individuals
%
% @return bestPopulation is the top n individuals from the combined
% population of parent and offspring individuals.
%
% @return bestFitness is the fitness of the top n individuals from the
% combined population of parent and offspring individuals.
%
% Author: Kumara Sastry
%
% Date: March 2007
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [population, fitness] = restrictedTournamentReplacement(population, fitness, newPopulation, newFitness, windowSize)
% Get the number of offspring individuals
n = size(newPopulation,1);
% For each offspring individual
for i = 1:n,
% Randomly select windowSize individuals from the parent population
shuffleArray = randperm(n);
chosenParentsIndex = shuffleArray(1:windowSize);
%Compute the hamming distance of the offspring with the randomly
%selected parents
hammingDistance = sum(abs(population(chosenParentsIndex,:)-repmat(newPopulation(i,:),windowSize,1)),2);
% Find the closest parent
[closestDistance, closestDistanceIndex] = min(hammingDistance);
closestParent = chosenParentsIndex(closestDistanceIndex);
% If the offspring is better than the closest parent than replace the
% parent with the offspring.
if(newFitness(i) > fitness(closestParent))
population(closestParent,:) = newPopulation(i,:);
fitness(closestParent) = newFitness(i);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -