non-dominated sorting算法的matlab实现

来源:互联网 发布:pp软件2015下载 编辑:程序博客网 时间:2024/06/06 01:49

实现了一个non-dominated sorting的算法,效率是最差的那种,但是感觉思路很清晰。先描述下思路吧:

1:对于全部的种群N,每一条染色体上的元素是这么个意思[决策变量 目标函数值 rank distance],在这个地方我主要是设置rank,distance是另外步骤用的。

2:首先一个空的集合has_assigend_index 也就是已经找到rank的就挪到这里面来。

3:依次从第一个染色体开始,看看有没有已经被assigned,如果没有那就查看是否有别的dominate它,如果没有那么它就是non-dominate的了,设置当前的rank以及放入到has_assigned_index中去。一直到被全部放入到has_assigned_index。那么就完成了全部的rank的设置,并且同时还按照front的level的到对应的结果集,这个是用于distance的时候用的。

代码如下:
function [ chromosomes, fronts ] = nondominated_sorting( chromosomes, number_of_decision_variables, number_of_objectives )
% each chromosome contains four segments,[decision_variables,
% corresponding_objective_value, rank_of_front, crowding_distance].
% when this function is finished, rank of each chromosome will be assigned
% the third segment.
% Besides, a struct named “fronts” would be also got, it’s form is like
% this: fronts{i}=[chromosome1, ….], i is the rank of chromosome1…

V = number_of_decision_variables;
Q = number_of_objectives;
[M, N] = size(chromosomes);
F = 0;
fronts = [];
% once the chromosome i is assgned to the fronts, its’ index will be remove to
% has_assigned_index.
has_assigned_index = [];
F = 0;
while length(has_assigned_index) ~= M
length(has_assigned_index)
F = F + 1
fronts{F} = [];
for i = 1:M
dominate_i = [];
if isempty(find(has_assigned_index == i))
for j = 1:M
if (i ~= j) && (isempty(find(has_assigned_index == j)))
fprintf(‘compare %d, %d\n’, i, j);
less_count = 0;
equal_count = 0;
more_count = 0;
for k=V+1:V+Q
if chromosomes(i, k) < chromosomes(j, k)
less_count = less_count + 1;
elseif chromosomes(i, k) > chromosomes(j, k)
more_count = more_count + 1;
else
equal_count = equal_count + 1;
end
end
if (more_count > 0) && (less_count == 0)
% j dominates i
dominate_i = [dominate_i j];
end
end
end
if length(dominate_i) == 0
has_assigned_index = [has_assigned_index i];
chromosomes(i, end-1) = F;
fronts{F} = [fronts{F} i];
end
end
end

end

0 0
原创粉丝点击