📄 objfun6.m
字号:
% OBJFUN6.M (OBJective function for rastrigins FUNction 6)
%
% This function implements the RASTRIGIN function 6.
%
% Syntax: ObjVal = objfun6(Chrom,rtn_type)
%
% Input parameters:
% Chrom - Matrix containing the chromosomes of the current
% population. Each row corresponds to one individual's
% string representation.
% if Chrom == [], then special values will be returned
% rtn_type - if Chrom == [] and
% rtn_type == 1 (or []) return boundaries
% rtn_type == 2 return title
% rtn_type == 3 return value of global minimum
%
% Output parameters:
% ObjVal - Column vector containing the objective values of the
% individuals in the current population.
% if called with Chrom == [], then ObjVal contains
% rtn_type == 1, matrix with the boundaries of the function
% rtn_type == 2, text for the title of the graphic output
% rtn_type == 3, value of global minimum
%
% Author: Hartmut Pohlheim
% History: 26.11.93 file created
% 27.11.93 text of title and rtn_type added
% 30.11.93 show Dim in figure titel
% 16.12.93 rtn_type == 3, return value of global minimum
% 01.03.94 name changed in obj*
% 13.01.03 updated for MATLAB v6 by Alex Shenfield
function ObjVal = objfun6(Chrom,rtn_type);
% Dimension of objective function
Dim = 20;
% Compute population parameters
[Nind,Nvar] = size(Chrom);
% Check size of Chrom and do the appropriate thing
% if Chrom is [], then define size of boundary-matrix and values
if Nind == 0
% return text of title for graphic output
if rtn_type == 2
ObjVal = ['RASTRIGINs function 6-' int2str(Dim)];
% return value of global minimum
elseif rtn_type == 3
ObjVal = 0;
% define size of boundary-matrix and values
else
% lower and upper bound, identical for all n variables
ObjVal = [-5.12; 5.12];
ObjVal = ObjVal(1:2,ones(Dim,1));
end
% if Dim variables, compute values of function
elseif Nvar == Dim
% function 6, Dim*A + sum of (xi^2 - A*cos(Omega*xi)) for i = 1:Dim (Dim=20)
% n = Dim, -5.12 <= xi <= 5.12
% global minimum at (xi)=(0) ; fmin=0
A = 10;
Omega = 2 * pi;
ObjVal = Dim * A + sum(((Chrom .* Chrom) - A * cos(Omega * Chrom))')';
% ObjVal = diag(Chrom * Chrom'); % both lines produce the same
% otherwise error, wrong format of Chrom
else
error('size of matrix Chrom is not correct for function evaluation');
end
% End of function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -