【优化算法】多目标粘菌算法(MOSMA)【含Matlab源码 1597期】

举报
海神之光 发表于 2022/05/28 23:26:10 2022/05/28
【摘要】 一、获取代码方式 获取代码方式1: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。 获取代码方式2: 完整代码已上传我的资源:【优化算法】多目标粘菌算法(MOSMA)【含Matla...

一、获取代码方式

获取代码方式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

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120

三、运行结果

在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.

文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。

原文链接:qq912100926.blog.csdn.net/article/details/121894872

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。