%%===MOSMA:多目标粘液霉菌算法=====
%% 目标函数
% 目标函数描述包含了有关目标函数的信息。M为目标空间的维数,D为决策变量空间的维数,
% LB和UB为决策变量空间中变量的取值范围。
% 用户必须使用决策变量定义目标函数。务必编辑功能‘评估_目标',以适应您的需要。
clc
clear all
D = 30; % 决策变量数目
M = 2; % 目标函数的个数
K=M+D;
LB = ones(1, D).*0; % LB - 表示每个决策变量的最小值的十进制值的向量。
UB = ones(1, D).*1; % UB - 决策变量的最大可能值向量。
GEN = 200; % 设置最大生成数
ecosize = 200; % 种群数量 (NP)
ishow = 10;
%% 开始进化过程
Pareto = MOSMA(D,M,LB,UB,ecosize,GEN,ishow);
Obtained_Pareto= Pareto(:,D+1:D+M); % extract data to plot
Obtained_Pareto=sortrows(Obtained_Pareto,2);
True_Pareto=load('ZDT3.txt');
%% 可视化
%% =========两个目标函数时======================
if M == 2
plot(Obtained_Pareto(:,1),Obtained_Pareto(:,2),'o','LineWidth',2,...
'MarkerEdgeColor','r','MarkerSize',2);
hold on
plot(True_Pareto(:,1),True_Pareto(:,2),'k');
title('采用MOSMA算法求解Pareto最优解集');
legend('MOSMA');
xlabel('F_1');
ylabel('F_2');
%% =====3个目标函数时==========================
elseif M == 3
plot3(Obtained_Pareto(:,1),Obtained_Pareto(:,2),Obtained_Pareto(:,3),'o','LineWidth',2,...
'MarkerEdgeColor','r','MarkerSize',2);
hold on
plot3(Obtained_Pareto(:,1),Obtained_Pareto(:,2),Obtained_Pareto(:,3),'.','LineWidth',2,...
'MarkerEdgeColor','k','MarkerSize',6);
title('采用MOSMA算法求解Pareto最优解集');
legend('MOSMA');
xlabel('F_1');
ylabel('F_2');
zlabel('F_3');
end
%% Metric Value
M_IGD=IGD(Obtained_Pareto,True_Pareto);
M_GD=GD(Obtained_Pareto,True_Pareto);
M_HV=HV(Obtained_Pareto,True_Pareto);
M_Spacing=Spacing(Obtained_Pareto,True_Pareto);
M_Spread=Spread(Obtained_Pareto,True_Pareto);
M_DeltaP=DeltaP(Obtained_Pareto,True_Pareto);
display(['The IGD Metric obtained by MOSMA is : ', num2str(M_IGD)]);
display(['The GD Metric obtained by MOSMA is : ', num2str(M_GD)]);
display(['The HV Metric obtained by MOSMA is : ', num2str(M_HV)]);
display(['The Spacing Metric obtained by MOSMA is : ', num2str(M_Spacing)]);
display(['The Spread Metric obtained by MOSMA is : ', num2str(M_Spread)]);
display(['The DeltaP Metric obtained by MOSMA is : ', num2str(M_DeltaP)]);
|