📄 elitistreplacement.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File: ElitistReplacement.m
%
% Description: Perform Lambda+Mu elitist replacement. Combine parent and
% offspring population and choose the best n individuals
%
% @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
%
% @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 [bestPopulation, bestFitness] = elitistReplacement(population, fitness, newPopulation, newFitness)
% Determine the population size;
n = size(population,1);
% Combine the parent and offspring population and their fitness values
combinedPopulation = [population; newPopulation];
combinedFitness = [fitness; newFitness];
% Sort the combined fitness vector
[sortedFitness, index] = sort(combinedFitness, 'descend');
% Select the top n individuals and their fitness.
bestPopulation = combinedPopulation(index(1:n),:);
bestFitness = combinedFitness(index(1:n));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -