non-dominated sorting算法的matlab实现
2015-11-04 02:25
330 查看
实现了一个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
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
相关文章推荐
- matlab符号语言还未消化的语句
- [Data Mining] kNN implementaion in Matlab
- 用C/C++读取MATLAB中mat文件中的Cell数据
- Matlab2014a(64-bit)安装libsvm3.12
- matlab中double、im2double、mat2gray区别
- matlab问题
- 2.描述性统计的matlab 实现
- matlab练习程序(奇异值分解压缩图像)
- 加速matlab运行的三重境界
- matlab 位操作
- matlab读取视频VideoReader类
- 项目代码matlab
- matlab double axes, 两个坐标轴 papa的儿子,儿子的papa
- Matlab 三维图像绘制(1)——纹理贴图、球体
- libsvm在matlab和Python上的探索
- MATLAB实现坐标系变换动画演示
- 新版Matlab中函数aviread报错问题
- c# 调用 matlab
- 在win7下如何以兼容模式运行matlab
- 遗传算法的matlab实现