首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >非支配排序算法通用MATLAB代码

非支配排序算法通用MATLAB代码

作者头像
里克贝斯
发布2021-05-21 16:40:02
发布2021-05-21 16:40:02
1.4K0
举报
文章被收录于专栏:图灵技术域图灵技术域

规模为N的种群中的每个个体都要针对M个目标函数和种群中的N-1个个体进行比较,复杂度为O(MN),因此种群中的N个个体都比较结束的复杂度为O(MN2),即每进行一次Pareto分级的时间复杂度为O(MN2)。

该算法需要保存两个量:

(1).支配个数np。该量是在可行解空间中可以支配个体p的所有个体的数量。

(2).被支配个体集合SP。该量是可行解空间中所有被个体p支配的个体组成的集合。

matlab代码:

(注意PopObj填入的多目标的函数值,如果有两个目标,100个个体,那么就是100*2的矩阵,nSort是前沿面的编号)

MATLAB

代码语言:txt
复制
function [FrontNO,MaxFNO] = NDSort(PopObj,nSort)
%NDSort - Do non-dominated sorting on the population by ENS
 
%
 
%   FrontNO = NDSort(A,s) does non-dominated sorting on A, where A is a
 
%   matrix which stores the objective values of all the individuals in the
 
%   population, and s is the number of individuals being sorted at least.
 
%   FrontNO(i) means the number of front of the i-th individual.
 
%
 
%   [FrontNO,K] = NDSort(...) also returns the maximum number of fronts,
 
%   except for the value of inf.
 
%
 
%   In particular, s = 1 stands for find only the first non-dominated
 
%   front, s = size(A,1)/2 stands for sort only half of the population
 
%   (which is often used in the algorithm), and s = inf stands for sort the
 
%   whole population.
 
%
 
%   Example:
 
%       [FrontNO,MaxFNO] = NDSort(PopObj,1)
 
 
    [N,M] = size(PopObj);
    
    FrontNO = inf(1,N);
    MaxFNO  = 0;
    [PopObj,rank] = sortrows(PopObj);
    while sum(FrontNO<inf) < min(nSort,N)
        MaxFNO = MaxFNO + 1;
        for i = 1 : N
            if FrontNO(i) == inf
                Dominated = false;
                for j = i-1 : -1 : 1
                    if FrontNO(j) == MaxFNO
                        m = 2;
                        while m <= M && PopObj(i,m) >= PopObj(j,m)
                            m = m + 1;
                        end
                        Dominated = m > M;
                        if Dominated || M == 2
                            break;
                        end
                    end
                end
                if ~Dominated
                    FrontNO(i) = MaxFNO;
                end
            end
        end
    end
    FrontNO(rank) = FrontNO;
end

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-02-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档