📄 crowding_distance.m
字号:
function f = crowding_distance(x,problem)
% This function calculates the crowding distance%% Copyright (C) 2009 Aravind Seshadri%% This program is free software: you can redistribute it and/or modify% it under the terms of the GNU General Public License as published by% the Free Software Foundation, either version 3 of the License, or% (at your option) any later version.% % This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the% GNU General Public License for more details.% % You should have received a copy of the GNU General Public License% along with this program. If not, see <http://www.gnu.org/licenses/>.
[N,M] = size(x);
switch problem
case 1
M = 2;
V = 6;
case 2
M = 3;
V = 12;
end
% Crowding distance for each front
for i = 1 : length(F(front).f)
y(i,:) = x(F(front).f(i),:);
end
for i = 1 : M
[sorted(i).individual,sorted(i).index] = sort(y(:,V + i));
distance(sorted(i).index(1)).individual = Inf;
distance(sorted(i).index(length(sorted(i).index))).individual = Inf;
end
[num,len] = size(y);
% Initialize all the distance of individuals as zero.
for i = 1 : M
for j = 2 : num - 1
distance(j).individual = 0;
end
objective(i).range = ...
sorted(i).individual(length(sorted(i).individual)) - ...
sorted(i).individual(1);
% Maximum and minimum objectives value for the ith objective
end
% Caluclate the crowding distance for front one.
for i = 1 : M
for j = 2 : num - 1
distance(j).individual = distance(j).individual + ...
(sorted(i).individual(j + 1) - sorted(i).individual(j - 1))/...
objective(i).range;
y(sorted(i).index(j),M + V + 2) = distance(j).individual;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -