-
Notifications
You must be signed in to change notification settings - Fork 1
/
NHV.m
135 lines (128 loc) · 3.58 KB
/
NHV.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function Score = NHV(PopObj,PF)
% <metric> <max>
% Normalized hypervolume
%--------------------------------------------------------------------------
% The copyright of the PlatEMO belongs to the BIMK Group. You are free to
% use the PlatEMO for research purposes. All publications which use this
% platform or any code in the platform should acknowledge the use of
% "PlatEMO" and reference "Ye Tian, Ran Cheng, Xingyi Zhang, and Yaochu
% Jin, PlatEMO: A MATLAB Platform for Evolutionary Multi-Objective
% Optimization, 2016".
%--------------------------------------------------------------------------
% Copyright (c) 2016-2017 BIMK Group
[N,M] = size(PopObj);
PopObj = PopObj./repmat(max(PF,[],1)*1.1,N,1);
PopObj(any(PopObj>1,2),:) = [];
RefPoint = ones(1,M);
if isempty(PopObj)
Score = 0;
elseif M < 5
pl = sortrows(PopObj);
S = {1,pl};
for k = 1 : M-1
S_ = {};
for i = 1 : size(S,1)
Stemp = Slice(cell2mat(S(i,2)),k,RefPoint);
for j = 1 : size(Stemp,1)
temp(1) = {cell2mat(Stemp(j,1))*cell2mat(S(i,1))};
temp(2) = Stemp(j,2);
S_ = Add(temp,S_);
end
end
S = S_;
end
Score = 0;
for i = 1 : size(S,1)
p = Head(cell2mat(S(i,2)));
Score = Score + cell2mat(S(i,1))*abs(p(M)-RefPoint(M));
end
else
SampleNum = 1000000;
MaxValue = RefPoint;
MinValue = min(PopObj,[],1);
Samples = repmat(MinValue,SampleNum,1) + rand(SampleNum,M).*repmat((MaxValue-MinValue),SampleNum,1);
Domi = false(1,SampleNum);
for i = 1 : size(PopObj,1)
drawnow();
Domi(all(repmat(PopObj(i,:),SampleNum,1)<=Samples,2)) = true;
end
Score = prod(MaxValue-MinValue)*sum(Domi)/SampleNum;
end
end
function S = Slice(pl,k,RefPoint)
p = Head(pl);
pl = Tail(pl);
ql = [];
S = {};
while ~isempty(pl)
ql = Insert(p,k+1,ql);
p_ = Head(pl);
cell_(1,1) = {abs(p(k)-p_(k))};
cell_(1,2) = {ql};
S = Add(cell_,S);
p = p_;
pl = Tail(pl);
end
ql = Insert(p,k+1,ql);
cell_(1,1) = {abs(p(k)-RefPoint(k))};
cell_(1,2) = {ql};
S = Add(cell_,S);
end
function ql = Insert(p,k,pl)
flag1 = 0;
flag2 = 0;
ql = [];
hp = Head(pl);
while ~isempty(pl) && hp(k) < p(k)
ql = [ql;hp];
pl = Tail(pl);
hp = Head(pl);
end
ql = [ql;p];
m = length(p);
while ~isempty(pl)
q = Head(pl);
for i = k : m
if p(i) < q(i)
flag1 = 1;
else
if p(i) > q(i)
flag2 = 1;
end
end
end
if ~(flag1 == 1 && flag2 == 0)
ql = [ql;Head(pl)];
end
pl = Tail(pl);
end
end
function p = Head(pl)
if isempty(pl)
p = [];
else
p = pl(1,:);
end
end
function ql = Tail(pl)
if size(pl,1) < 2
ql = [];
else
ql = pl(2:end,:);
end
end
function S_ = Add(cell_,S)
n = size(S,1);
m = 0;
for k = 1 : n
if isequal(cell_(1,2),S(k,2))
S(k,1) = {cell2mat(S(k,1))+cell2mat(cell_(1,1))};
m = 1;
break;
end
end
if m == 0
S(n+1,:) = cell_(1,:);
end
S_ = S;
end