evaluateindividuals.m

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

M
39
字号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File: evaluateIndividuals.m
%
% Description: Evaluate the fitness of the individual in the population.
% The example implemented is the m-k deceptive trap function.
%
% @param ranges is the a vector containing the cardinality of each of the
% alphabet. For example if all variables are binary then ranges(1:ell) = 2.
%
% @param population is the population of candidate solutions
%
% @return fitness is the fitness of all the individuals
%
% Author: Kumara Sastry
%
% Date: March 2007
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function fitness = evaluateIndividuals(ranges, population)

ell = size(ranges,2);
n = size(population,1);
% Building block size
k = 4;
% Signal difference
d = 0.25;
% Deceptive trap function
bbFitness = [1-d (1-d)*(1-1/3) (1-d)*(1-2/3) 0 1];

% Loose linkage
%bbMap = reshape(reshape(1:ell,ell/k,k)',1,ell);

% Tight linkage (uncomment the line below)
bbMap = 1:ell;

reshapedPop = reshape(population(:,bbMap),n,k,ell/k);
unitation = sum(reshapedPop,2);
fitness = sum(bbFitness(unitation+1),3);

⌨️ 快捷键说明

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