-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_obj.m
More file actions
54 lines (43 loc) · 1.04 KB
/
func_obj.m
File metadata and controls
54 lines (43 loc) · 1.04 KB
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
function obj = func_obj(x)
%in this function we define the objective function
%you need not to change the first block, which does the parameter boundary
%control and scaling.
%
global vrange
Nvar = size(vrange, 1);
if size(x,1)==1
x = x';
end
p = vrange(:,1) + (vrange(:,2) - vrange(:,1)).*x;
if min(x)<0 || max(x)>1
dxlim = 0;
for ii=1:Nvar
if x(ii)<0
dxlim = dxlim + abs(x(ii));
elseif x(ii)>1
dxlim = dxlim + abs(x(ii)-1);
end
end
obj = NaN; %-5 + dxlim^2;
return;
end
%% evaluate the objective function
asum = 0;
for i = 1 : Nvar - 1
asum = asum - 10*exp(-0.2*sqrt((p(i))^2 + (p(i + 1))^2));
end
%add a random number to simulate noise.
% asum = asum + randn*0.001;
obj(1) = asum;
asum = 0;
for i = 1 : Nvar
asum = asum + (abs(p(i))^0.8 + 5*(sin(p(i)))^3);
end
obj(2) = asum;
obj = obj(:);
%% save data to a global variable.
global g_data g_cnt
g_cnt = g_cnt+1;
g_data(g_cnt,:) = [p',obj(:)']; %
%uncomment the next line to print out the solution
% [g_cnt, p',obj]