优化算法多目标粘菌算法(MOSMA)含Matlab源码 1597期
Posted 紫极神光
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了优化算法多目标粘菌算法(MOSMA)含Matlab源码 1597期相关的知识,希望对你有一定的参考价值。
一、获取代码方式
获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2:
完整代码已上传我的资源:【优化算法】多目标粘菌算法(MOSMA)【含Matlab源码 1597期】
备注:订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、部分源代码
%% Multiple Objective Slime Mould Algorithm (MOSMA)
%% Objective Function
% The objective function description contains information about the
% objective function. M is the dimension of the objective space, D is the
% dimension of decision variable space, LB and UB are the
% range for the variables in the decision variable space. User has to
% define the objective functions using the decision variables. Make sure to
% edit the function 'evaluate_objective' to suit your needs.
clc
clear all
D = 30; % Number of decision variables
M = 2; % Number of objective functions
K=M+D;
LB = ones(1, D).*0; % LB - A vector of decimal values which indicate the minimum value for each decision variable.
UB = ones(1, D).*1; % UB - Vector of maximum possible values for decision variables.
GEN = 200; % Set the maximum number of generation (GEN)
ecosize = 200; % Set the population size (NP)
ishow = 10;
%% Start the evolution process
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');
%% Plot data
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('Optimal Solution Pareto Set using MOSMA');
legend('MOSMA');
xlabel('F_1');
ylabel('F_2');
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('Optimal Solution Pareto Set using MOSMA');
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)]);
function [Score,PopObj] = HV(PopObj,PF)
% <metric> <max>
% Hypervolume
%
% Normalize the population according to the reference point set
[N,M] = size(PopObj);
fmin = min(min(PopObj,[],1),zeros(1,M));
fmax = max(PF,[],1);
PopObj = (PopObj-repmat(fmin,N,1))./repmat((fmax-fmin)*1.1,N,1);
PopObj(any(PopObj>1,2),:) = [];
% The reference point is set to (1,1,...)
RefPoint = ones(1,M);
if isempty(PopObj)
Score = 0;
elseif M < 4
% Calculate the exact HV value
pl = sortrows(PopObj);
S = 1,pl;
for k = 1 : M-1
S_ = ;
for i = 1 : size(S,1)
Stemp = Slice(cell2mat(S(i,2)),k,RefPoint);
for j = 1 : size(Stemp,1)
temp(1) = cell2mat(Stemp(j,1))*cell2mat(S(i,1));
temp(2) = Stemp(j,2);
S_ = Add(temp,S_);
end
end
S = S_;
end
Score = 0;
for i = 1 : size(S,1)
p = Head(cell2mat(S(i,2)));
Score = Score + cell2mat(S(i,1))*abs(p(M)-RefPoint(M));
end
else
% Estimate the HV value by Monte Carlo estimation
SampleNum = 1000000;
MaxValue = RefPoint;
MinValue = min(PopObj,[],1);
Samples = unifrnd(repmat(MinValue,SampleNum,1),repmat(MaxValue,SampleNum,1));
if gpuDeviceCount > 0
% GPU acceleration
Samples = gpuArray(single(Samples));
PopObj = gpuArray(single(PopObj));
end
for i = 1 : size(PopObj,1)
drawnow();
domi = true(size(Samples,1),1);
m = 1;
while m <= M && any(domi)
domi = domi & PopObj(i,m) <= Samples(:,m);
m = m + 1;
end
Samples(domi,:) = [];
end
Score = prod(MaxValue-MinValue)*(1-size(Samples,1)/SampleNum);
end
end
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
以上是关于优化算法多目标粘菌算法(MOSMA)含Matlab源码 1597期的主要内容,如果未能解决你的问题,请参考以下文章
优化算法自适应对抗粘菌优化算法 (AOSMA)含Matlab源码 1425期
优化算法先导粘菌算法(LSMA)含Matlab源码 1436期
多目标优化求解基于matlab遗传优化萤火虫算法求解多目标优化问题含Matlab源码 1484期
多目标优化求解基于matlab遗传优化萤火虫算法求解多目标优化问题含Matlab源码 1484期