最近在做天线多目标优化的实例,因此接触到了NSGA-Ⅱ算法,所以想分享以下我个人的学习内容与经历,仅作参考,如果内容有误,也希望各位能够指出来,大家一起进行交流指正。
内容将分为以下几个模块,内容可能较多,如果觉得不错的话,可以点赞👍,收藏或者转发哦!
NSGA-Ⅱ算法简介
NSGA-Ⅱ算法由Deb等人首次提出,其思想为带有精英保留策略的快速非支配多目标优化算法,是一种基于Pareto最优解的多目标优化算法。
该算法的重要过程为:将进化群体按照支配关系分成若干层,第一层为进化群体中的非支配个体集合,第二层为在进化群体中去掉第一层个体后求得非支配个体集合,第三层,第四层依此类推。
在这里,我就不再赘述NSGA-Ⅱ的具体概念,而是将重点放在如何实现上。想要进行初步学习的可以转至:作者 晓风wangchao,标题 多目标优化算法(一)NSGA-Ⅱ(NSGA2)
支配集与非支配集的了解可以参考书籍:《多目标进化优化》或者自行百度,csdn中其他的文章。个人觉得这是基本的概念哈,可以自学。
可行解为符合约束条件的解,不可行解为不符合约束条件的解。
需要注意的是,本文讲解的是带约束条件的多目标优化,因此程序中也会掺和一些约束条件,NSGA-Ⅱ适用于解决3维及以下的多目标优化问题,即优化目标不大于3。
关于NSGA-Ⅱ带约束的matlab代码网上已经有公开的资源了,在这里用到的是MATLAB code for Constrained NSGA II - Dr.S.Baskar, S. Tamilselvi and P.R.Varshini
主程序代码:
%% Description
% 1. This is the main program of NSGA II. It requires only one input, which is test problem
% index, 'p'. NSGA II code is tested and verified for 14 test problems.
% 2. This code defines population size in 'pop_size', number of design
% variables in 'V', number of runs in 'no_runs', maximum number of
% generations in 'gen_max', current generation in 'gen_count' and number of objectives
% in 'M'.
% 3. 'xl' and 'xu' are the lower and upper bounds of the design variables.
% 4. Final optimal Pareto soutions are in the variable 'pareto_rank1', with design
% variables in the coumns (1:V), objectives in the columns (V+1 to V+M),
% constraint violation in the column (V+M+1), Rank in (V+M+2), Distance in (V+M+3).
%% code starts
M = 2;%目标函数的个数
pop_size= 100;%种群数
no_runs = 10;%过程循环次数
gen_max=500;%最大迭代次数
V = 3;%变量个数
xl = [72.6,69.2,6.5,13.8,3];
xu = [75.2,73.5,9.7,16.4,6];
etac = 20;%交叉操作的分布指标
etam = 100;%编译操作的分布指标
pm = 1/V;%变异率
Q = [];%将每次循环得到的帕累托前沿保存
ref_point = [-10,-5]
for run = 1:no_runs
%初始化种群数
xl_temp=repmat(xl, pop_size,1);
xu_temp=repmat(xu, pop_size,1);
x = xl_temp+((xu_temp-xl_temp).*rand(pop_size,V));
for i =1:pop_size
[ff(i,:) err(i,:)] =feval(fname, x(i,:)); % Objective function evaulation
end
error_norm=normalisation(err);
population_init=[x ff error_norm];
[population front]=NDSCD_cons(population_init);
%迭代开始
for gen_count=1:gen_max
% 选择
parent_selected=binary_tour_selection(population);%二项锦标赛选择
% 繁殖,生成后代
child_offspring = genetic_operator(parent_selected(:,1:V));
for i =1:pop_size
[fff(i,:) err(i,:)] =feval(fname, x(i,:)); % Objective function evaulation
end
error_norm=normalisation(err);
child_offspring=[child_offspring fff error_norm];
%子代与父代合并,种群数为2N
population_inter=[population(:,1:V+M+1) ; child_offspring(:,1:V+M+1)];
[population_inter_sorted front]=NDS_CD_cons(population_inter);%非支配解排序并计算聚集距离
%精英保留策略选出N个个体,组成新的一代种群
new_pop=replacement(population_inter_sorted, front);
population=new_pop;
%% 计算超立方体积(Hypervolume)指标
pop = sortrows(new_pop,V+1);
index = find(pop(:,V+M+2)==1);
non_dominated_front = pop(index,V+1:V+2);
hypervolume(gen_count+1) = Hypervolume(non_dominated_front,ref_point);
plot(non_dominated_front(:,1),non_dominated_front(:,2),'*')
set(gca,'YScale','log')
title('NSGAII: Tradeoff')
xlabel('objective function 1')
ylabel('objective function 2')
axis square
drawnow
pause(1)
end
paretoset(run).trial=new_pop(:,1:V+M+1);
Q = [Q; paretoset(run).trial];
end
% 绘制帕累托面
if run==1
index = find(new_pop(:,V+M+2)==1);
non_dominated_front = new_pop(index,V+1:V+2);



被折叠的 条评论
为什么被折叠?



