多目标优化算法之多目标黏菌算法MOSMA(附Matlab免费代码)

引言

Multi-Objective Slime Mould Algorithm (MOSMA) 是一种新兴的多目标优化算法,受到自然界中黏菌行为的启发。黏菌在寻找食物时表现出的动态行为和优化路径选择能力,为设计高效的优化算法提供了灵感。MOSMA 通过模拟黏菌的生命周期中的营养、活跃和动态阶段,实现了对多目标优化问题的求解。

1. 算法原理

MOSMA 的核心思想是通过模拟黏菌在寻找食物时的行为模式,包括接近食物、包围食物和消化食物等过程,来实现优化。具体来说,算法通过以下步骤进行:

  1. 初始化:生成一组随机的候选解,每个解代表一个黏菌的位置。

  2. 适应度评估:计算每个候选解的适应度值,通常使用目标函数的值来评估。

  3. 排序:根据适应度值对候选解进行排序,通常使用非支配排序方法。

  4. 权重更新:根据排序结果更新每个候选解的权重,权重较高的解表示更优的解。

  5. 位置更新:根据权重和随机选择的其他候选解,更新每个候选解的位置。

2. 应用场景
  • 机械工程设计:用于解决复杂的机械工程优化问题,如电机设计和自动电压调节系统

  • 图像处理:用于图像分割和特征选择,提高图像处理的效率和准确性

  • 电力系统:用于电力系统的谐波滤波器设计,优化电力系统的性能

    图片

    从代距(GD)、倒代距(IGD)、最大传播(MS)、间隔和运行时间等性能指标对MOSMA进行了性能评估。仿真结果表明,该算法在求解线性、非线性、连续和离散Pareto最优前沿等多目标问题方面具有优势。

    图片

参考文献

Matlab代码下载

微信搜索并关注-优化算法侠(英文名:Swarm-Opti),或扫描下方二维码关注,以算法名字搜索历史文章即可下载。


% 请关注微信公众号:优化算法侠,发现更多精彩

function f = MOSMA(dim,M,lb,ub,N,Max_iter)          
X = zeros(N,dim);
Sol = zeros(N,dim);
weight = ones(N,dim);%fitness weight of each slime mold
%% Initialize the population
for i=1:N
   x(i,:)=lb+(ub-lb).*rand(1,dim); 
   f(i,1:M) = evaluate_objective(x(i,:), M);
end
new_Sol=[x f]; 
new_Sol = solutions_sorting(new_Sol, M, dim);
for i = 1 : Max_iter 
[SmellOrder,SmellIndex] = sort(Sol);  
worstFitness = SmellOrder(N);
bestFitness = SmellOrder(1);
S=bestFitness-worstFitness+eps;  % plus eps to avoid denominator zero
        for k=1:N
            if k<=(N/2)  
                weight(SmellIndex(k),:) = 1+rand()*log10((bestFitness-SmellOrder(k))/(S)+1);
            else
                weight(SmellIndex(k),:) = 1-rand()*log10((bestFitness-SmellOrder(k))/(S)+1);
            end
        end     
a = atanh(-(i/Max_iter)+1);   
b = 1-i/Max_iter;
    for j=1:N 
        best=(new_Sol(j,1:dim) - new_Sol(1,(1:dim)));
        if rand<0.03    
            X(j,:) = (ub-lb).*rand+lb;
        else
            p =tanh(abs(f(j)-best));  
            vb = unifrnd(-a,a,1,dim); 
            vc = unifrnd(-b,b,1,dim);        
                r = rand();
                A = randi([1,N]);  
                B = randi([1,N]);
                if r<p    
                    X(j,:) = best+ vb.*(weight(j,:).*X(A,:)-X(B,:));
                else
                    X(j,:) = best+ vc.*(weight(j,:).*X(A,:)-X(B,:));
                end  
        end
        Sol(j,1:dim) = X(j,1:dim);       
        Flag4ub=Sol(j,1:dim)>ub;
        Flag4lb=Sol(j,1:dim)<lb;
        Sol(j,1:dim)=(Sol(j,1:dim).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;  
        %% Evalute the fitness/function values of the new population
        Sol(j, dim+1:M+dim) = evaluate_objective(Sol(j,1:dim),M);
        if Sol(j,dim+1:dim+M) <= new_Sol(1,(dim+1:dim+M)) 
           new_Sol(1,1:(dim+M)) = Sol(j,1:(dim+M));  
        end
    end    
%% ! Very important to combine old and new bats !
   Sort_bats(1:N,:) = new_Sol;
   Sort_bats((N + 1):(2*N), 1:M+dim) = Sol;
%% Non-dominated sorting process (a separate function/subroutine)
   Sorted_bats = solutions_sorting(Sort_bats, M, dim); 
%% Select npop solutions among a combined population of 2*npop solutions  
    new_Sol = cleanup_batspop(Sorted_bats, M, dim, N);  
end
f=new_Sol;

end



%% Clean up the populations (both old and new) to give a new population
% This cleanup here is similar to the Non-dominated Sorting Genetic
% Algorithm (NSGA-II) by K. Deb et al. (2002), which can be applied to 
% any cleanup of 2*npop solutions to form a set of npop solutions.
function new_bats = cleanup_batspop(bats, m, ndim, npop)
% The input population to this part has twice (ntwice) of the needed 
% population size (npop). Thus, selection is done based on ranking and 
% crowding distances, calculated from the non-dominated sorting
ntwice= size(bats,1);
% Ranking is stored in column Krank
Krank=m+ndim+1;
% Sort the population of size 2*npop according to their ranks
[~,Index] = sort(bats(:,Krank)); sorted_bats=bats(Index,:);
% Get the maximum rank among the population
RankMax=max(bats(:,Krank)); 

%% Main loop for selecting solutions based on ranks and crowding distances
K = 0;  % Initialization for the rank counter 
% Loop over all ranks in the population
for i =1:RankMax,  
    % Obtain the current rank i from sorted solutions
    RankSol = max(find(sorted_bats(:, Krank) == i));
    % In the new bats/solutions, there can be npop solutions to fill
    if RankSol<npop,
       new_bats(K+1:RankSol,:)=sorted_bats(K+1:RankSol,:);
    end 
    % If the population after addition is large than npop, re-arrangement
    % or selection is carried out
    if RankSol>=npop
        % Sort/Select the solutions with the current rank 
        candidate_bats = sorted_bats(K + 1 : RankSol, :);
        [~,tmp_Rank]=sort(candidate_bats(:,Krank+1),'descend');
        % Fill the rest (npop-K) bats/solutions up to npop solutions 
        for j = 1:(npop-K), 
            new_bats(K+j,:)=candidate_bats(tmp_Rank(j),:);
        end
    end
    % Record and update the current rank after adding new bats 
    K = RankSol;
end
end



%% The sorting of nondomninated solutions from a population of 2*npop     %
%% (New solutions+old population) to form a population of npop solutions  %
function sorted_x = solutions_sorting(x, m, ndim)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Inputs and outputs are the extended solutions x with a dimension of    %
%% npop by (ndim+m+2). The objective values are already included in x.    %
% More specifically, the first ndim columns are the actual solutions or 
% variable values (1:ndim), followed by the m columns of objective values. 
% Then, the next column (i.e.,ndim+m+1) corresponds to the ranks, whereas 
% the final column (i.e., ndim+m+2) records the crowd distances. 
% ----------------------------------------------------------------------- %
%% Get the parameters from the inputs such as the size of input population
npop=size(x,1);    % Population size
frontRank=1;       % Pareto frontRank (counter) initialization
Rcol=ndim+m+1;     % Store the ranks in the column Rcol=ndim+m+1
% Define the Parato Front as a class (PF) and initilization of xSol
PF(frontRank).R=[];   xSol=[];
%% The main non-dominated sorting starts here             %%%%%%%%%%%%%%%%% 
for i = 1:npop, 
    % Set the number (initially, 0) of solutions dominating this solution
    xSol(i).n=0;
    % Find all the solutions (that dominated by this solution)
    xSol(i).q=[];
    % Sorting into 3 categories: better (minimization), equal & otherwise
    for j=1:npop,
        % Definte 3 counters for 3 categories
        ns_categ_1=0; ns_categ_2=0; ns_categ_3=0;
        for k=1:m,  % for all m objectives
            % Update the counters for 3 different categories
            if (x(i,ndim+k) < x(j,ndim+k)),      % better/non-dominated
                ns_categ_1=ns_categ_1+1;
            elseif (x(i,ndim+k)==x(j,ndim+k)),   % equal
                ns_categ_2=ns_categ_2+1;
            else                                 % dominated
                ns_categ_3=ns_categ_3+1;
            end
        end % end of k
        % Update the solutions in their class
        if ns_categ_1==0 && ns_categ_2 ~= m
            xSol(i).n=xSol(i).n+1;
        elseif ns_categ_3 == 0 && ns_categ_2 ~= m
            xSol(i).q=[xSol(i).q j];
        end
    end % end of j   
    %% Record/Udpate the Pareto Front
    if xSol(i).n==0, 
        x(i,Rcol)=1;   % Update the Rank #1 (i.e., the Pareto Front)
        PF(frontRank).R = [PF(frontRank).R i];
    end
end % end of i=1:npop (The first round full rank-sorting process)

% Update the rest frontRanks (close, but not on the Pareto Front)
while ~isempty(PF(frontRank).R),
    nonPF=[];    % Intialization the set
    N=length(PF(frontRank).R);
for i=1 :N, 
   % Get the solution/list 
   Sol_tmp_q=xSol(PF(frontRank).R(i)).q; 
   % If not empty, update 
   if ~isempty(xSol(Sol_tmp_q))
       for j = 1:length(Sol_tmp_q),
         % Get the solutions dominated by the current solution    
          Sol_tmp_qj=xSol(PF(frontRank).R(i)).q(j);   
          xSol(Sol_tmp_qj).n=xSol(Sol_tmp_qj).n-1;
          if xSol(Sol_tmp_qj).n==0
             x(Sol_tmp_qj, Rcol)=frontRank + 1;
             nonPF = [nonPF Sol_tmp_qj];
          end
       end % end of j
   end
end  % end of i
   frontRank=frontRank+1;
   PF(frontRank).R=nonPF;
end % end of PF(frontRank)

% Now carry out the sorting of ranks and then update 
[~,frontRanks_Index]=sort(x(:, Rcol));
Sorted_frontRank=x(frontRanks_Index,:); 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Evaluate the crowding distances for each solution for each frontRank   %
% That is, all the non-domonated solutions on the Pareto Front.  %%%%%%%%%%
Qi=0;      % Initialize a counter
for frontRank=1:(length(PF)-1), 
    % Define/initialize a generalized distance matrix 
    dc = [];    past_Q=Qi+1;
    for i=1:length(PF(frontRank).R),
        dc(i,:)=Sorted_frontRank(Qi+i,:);
    end
    Qi=Qi+i;
    % Solutions are sorted according to their fitness/objective values
    fobj_sorted=[];
    for i=1:m, 
        [~, f_Rank]=sort(dc(:,ndim+i));
        fobj_sorted=dc(f_Rank,:);
        % Find the max and min of the fobj values   
        fobj_max=fobj_sorted(length(f_Rank), ndim+i);
        fobj_min=fobj_sorted(1, ndim+i);
        % Calculate the range of the fobj
        f_range=fobj_max-fobj_min;
        % If the solution is at the end/edge, set its distance as infinity
        dc(f_Rank(length(f_Rank)), Rcol+i)=Inf;
        dc(f_Rank(1), Rcol+i) = Inf;
        for j=2:length(f_Rank)-1, 
            fobj2=fobj_sorted(j+1,ndim + i);
            fobj1=fobj_sorted(j-1,ndim + i);  
            % Check the range or special cases
            if (f_range==0),
                dc(f_Rank(j), Rcol+i)=Inf;
            else
            % Scale the range for distance normalization     
            dc(f_Rank(j),Rcol+i)=(fobj2-fobj1)/f_range;
            end
        end % end of j
    end % end of i
    
    % Calculate and update the crowding distances on the Pareto Front
    dist = []; dist(:,1)=zeros(length(PF(frontRank).R),1);
    for i=1:m, 
        dist(:,1)=dist(:,1)+dc(:, Rcol+i);
    end
    % Store the crowding distrance (dc) in the column of Rcol+1=ndim+m+2
    dc(:, Rcol+1)=dist;  dc=dc(:,1:Rcol+1);
    % Update for the output
    xy(past_Q:Qi,:)=dc;  
end  % end of all ranks search/update
sorted_x=xy();    % Output the sorted solutions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end of non-dominated sorting %%%%%%%%%%%%%%
end

完整代码

图片

👇👇👇

MOSMA.zip

点击链接跳转:

375种群优化算法免费下载-matlab

https://mp.weixin.qq.com/s/AsFTBmaZ8UOgES9TQuL0Kg?token=1339859150&lang=zh_CN

求解cec测试函数-matlab 

cec2017测试函数使用教程及matlab代码免费下载

cec2018测试函使用教程及matlab代码免费下载

cec2019测试函使用教程及matlab代码免费下载

cec2020测试函使用教程及matlab代码免费下载

cec2021测试函使用教程及matlab代码免费下载

cec2022测试函使用教程及matlab代码免费下载
绘制cec2017/018/2019/2020/2021/2022函数的三维图像教程,SO EASY!

215种群智能优化算法python库

Amazing!Python版215种群智能优化算法icon-default.png?t=O83Ahttps://mp.weixin.qq.com/s?__biz=MzkxMDQ5MDk4Ng==&mid=2247486669&idx=1&sn=6b439e55b37b6482b8d3831ca85f1d55&chksm=c12be0c8f65c69de71ad51d3b736b871ff52f8646e90624f95dd32b024dfaad369d654aaf8fc#rd

解决12工程设计优化问题-matlab

略微出手,工程设计问题(12)(附Matlab代码)icon-default.png?t=O83Ahttps://mp.weixin.qq.com/s?__biz=MzkxMDQ5MDk4Ng==&mid=2247485052&idx=1&sn=80e5573c1c005ee5640e44935044ee35&chksm=c12bea79f65c636fc73758b4f4893502bd89cbd1c5d15d7db15e8b5c94eeae40450439d44944&token=681266555&lang=zh_CN#rd

求解11种cec测试函数-python

【选择自由,免费下载】215种优化算法求解11种cec测试函数-python代码icon-default.png?t=O83Ahttps://mp.weixin.qq.com/s?__biz=MzkxMDQ5MDk4Ng==&mid=2247486669&idx=2&sn=eea8fb04dc507ab9119e2c97c03ca2f6&chksm=c12be0c8f65c69decd6c8109f6b997986bf58725fdbbd7ab03752cb6f61aacdb5a2dc7fec762#rd

解决30种工程设计优化问题-python

【一码解决】215种优化算法求解30个现实世界的工程设计优化问题,让你的论文增色10倍(附Python代码)icon-default.png?t=O83Ahttps://mp.weixin.qq.com/s?__biz=MzkxMDQ5MDk4Ng==&mid=2247486669&idx=3&sn=ea6d26ae7cb651e5c368f4c73ade228e&chksm=c12be0c8f65c69de739af72d9793838f59ab77bfee36bc2c204f96e2a9e5c6d87dfbbbae698e#rd

仅需一行,可改进所有优化算法:21种混沌映射方法-混沌初始化(附matlab代码)

用于改进所有优化算法:21种混沌映射方法-混沌初始化(附matlab代码)21种混沌映射方法-混沌初始化,适用于所有优化算法icon-default.png?t=O83Ahttps://mp.weixin.qq.com/s?__biz=MzkxMDQ5MDk4Ng==&mid=2247486215&idx=2&sn=58f1a69175b0d6431a4c7cdfa114b84d&chksm=c12be702f65c6e14e6bd1ddc33b9cec74991d93303c325853049b7e4afd09039b13083fa79c5&token=25423484&lang=zh_CN#rd

【有经典,有最新】24种信号分解方法(附matlab代码) 

沙场大点兵:24种信号分解方法(附matlab代码)icon-default.png?t=O83Ahttps://mp.weixin.qq.com/s?__biz=MzkxMDQ5MDk4Ng==&mid=2247486001&idx=1&sn=a87c24cb401017a78a90bd1b1439fcb0&chksm=c12be634f65c6f22368b7229a59ac5ef330b89d710c826dbfd1a1c34a02b1dd7e909c7f40d79&token=25423484&lang=zh_CN#rd

 【分类新范式】27种一维数据转换成二维图像的方法-matlab代码

沙场大点兵:27种一维数据转换成二维图像的方法-matlab代码icon-default.png?t=O83Ahttps://mp.weixin.qq.com/s?__biz=MzkxMDQ5MDk4Ng==&mid=2247486260&idx=1&sn=81b1970cb89364c0289ccdfb403e5388&chksm=c12be731f65c6e273a85456326b503b7f35d9f035405050932ff1926e0b1bfa8076b1bc2d1f2&token=25423484&lang=zh_CN#rd

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值