-
Notifications
You must be signed in to change notification settings - Fork 33
/
objharv.m
77 lines (69 loc) · 2.51 KB
/
objharv.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
% OBJHARV.M (OBJective function for HARVest problem)
%
% This function implements the HARVEST PROBLEM.
%
% Syntax: ObjVal = objharv(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: 18.02.94 file created (copy of vallinq.m)
% 01.03.94 name changed in obj*
% 21.01.03 updated for MATLAB v6 by Alex Shenfield
function ObjVal = objharv(Chrom,rtn_type);
% global gen;
% Dimension of objective function
Dim = 20;
% values from MICHALEWICZ
a = 1.1;
x0 = 100;
xend = x0;
XENDWEIGHT = 0.4/(Dim^0.6);
% 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 = ['HARVEST PROBLEM-' int2str(Dim)];
% return value of global minimum
elseif rtn_type == 3
ObjVal = -sqrt(x0*(a^Dim-1)^2/(a^(Dim-1)*(a-1)));
% define size of boundary-matrix and values
else
% lower and upper bound, identical for all n variables
ObjVal1 = [0; 10*Dim];
ObjVal = rep(ObjVal1,[1 Dim]);
end
% if Dim variables, compute values of function
elseif Nvar == Dim
ObjVal = zeros(Nind,1);
X = rep(x0,[Nind 1]);
for irun = 1:Nvar,
X = a*X - Chrom(:,irun);
end
X;
ObjVal = -(sum(sqrt(Chrom)')' - XENDWEIGHT * abs(X-x0));
% otherwise error, wrong format of Chrom
else
error('size of matrix Chrom is not correct for function evaluation');
end
% End of function