1. 程式人生 > 其它 >【優化演算法】海洋捕食者演算法(MPA)【含Matlab原始碼 478期】

【優化演算法】海洋捕食者演算法(MPA)【含Matlab原始碼 478期】

一、簡介

海洋捕食者演算法(MPA)是一種自然啟發式的優化演算法,它遵循在最佳覓食策略中自然支配的規則,並且在海洋生態系統中遇到捕食者與獵物之間的速率策略。

二、原始碼

%_________________________________________________________________________
%  Marine Predators Algorithm source code (Developed in MATLAB R2015a)
%
%  programming: Afshin Faramarzi & Seyedali Mirjalili
%
% paper:
%  A. Faramarzi, M. Heidarinejad, S. Mirjalili, A.H. Gandomi, 
%  Marine Predators Algorithm: A Nature-inspired Metaheuristic
%  Expert Systems with Applications
%  DOI: doi.org/10.1016/j.eswa.2020.113377
%  
%  E-mails: [email protected]            (Afshin Faramarzi)
%           [email protected]                   (Mohammad Heidarinejad)
%           [email protected]    (Seyedali Mirjalili) 
%           [email protected]               (Amir H Gandomi)
%_________________________________________________________________________

% --------------------------------------------
% fobj = @YourCostFunction
% dim = number of your variables
% Max_iteration = maximum number of iterations
% SearchAgents_no = number of search agents
% lb=[lb1,lb2,...,lbn] where lbn is the lower bound of variable n
% ub=[ub1,ub2,...,ubn] where ubn is the upper bound of variable n
% ---------------------------------------------------------

clear all
clc
format long
SearchAgents_no=25; % Number of search agents

Function_name='F23';
   
Max_iteration=500; % Maximum number of iterations

[lb,ub,dim,fobj]=Get_Functions_details(Function_name);

[Best_score,Best_pos,Convergence_curve]=MPA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);

% function topology
figure('Position',[500 400 700 290])
subplot(1,2,1);
func_plot(Function_name);
title('Function Topology')
xlabel('x_1');
ylabel('x_2');
zlabel([Function_name,'( x_1 , x_2 )'])

% Convergence curve
subplot(1,2,2);
semilogy(Convergence_curve,'Color','r')
title('Objective space')
xlabel('Iteration');
ylabel('Best score obtained so far');
%_________________________________________________________________________
%  Marine Predators Algorithm source code (Developed in MATLAB R2015a)
%
%  programming: Afshin Faramarzi & Seyedali Mirjalili
%
% paper:
%  A. Faramarzi, M. Heidarinejad, S. Mirjalili, A.H. Gandomi, 
%  Marine Predators Algorithm: A Nature-inspired Metaheuristic
%  Expert Systems with Applications
%  DOI: doi.org/10.1016/j.eswa.2020.113377
%  
%  E-mails: [email protected]            (Afshin Faramarzi)
%           [email protected]                   (Mohammad Heidarinejad)
%           [email protected]    (Seyedali Mirjalili) 
%           [email protected]               (Amir H Gandomi)
%_________________________________________________________________________

% This function containts full information and implementations of the benchmark 
% functions in Table 1, Table 2, and Table 3 in the paper

% lb is the lower bound: lb=[lb_1,lb_2,...,lb_d]
% up is the uppper bound: ub=[ub_1,ub_2,...,ub_d]
% dim is the number of variables (dimension of the problem)

function [lb,ub,dim,fobj] = Get_Functions_details(F)


switch F
    case 'F1'
        fobj = @F1;
        lb=-100;
        ub=100;
        dim=50;
        
    case 'F2'
        fobj = @F2;
        lb=-10;
        ub=10;
        dim=50;
        
    case 'F3'
        fobj = @F3;
        lb=-100;
        ub=100;
        dim=50;
        
    case 'F4'
        fobj = @F4;
        lb=-100;
        ub=100;
        dim=50;
        
    case 'F5'
        fobj = @F5;
        lb=-30;
        ub=30;
        dim=50;
        
    case 'F6'
        fobj = @F6;
        lb=-100;
        ub=100;
        dim=50;
        
    case 'F7'
        fobj = @F7;
        lb=-1.28;
        ub=1.28;
        dim=50;
        
    case 'F8'
        fobj = @F8;
        lb=-500;
        ub=500;
        dim=50;
        
    case 'F9'
        fobj = @F9;
        lb=-5.12;
        ub=5.12;
        dim=50;
        
    case 'F10'
        fobj = @F10;
        lb=-32;
        ub=32;
        dim=50;
        
    case 'F11'
        fobj = @F11;
        lb=-600;
        ub=600;
        dim=50;
        
    case 'F12'
        fobj = @F12;
        lb=-50;
        ub=50;
        dim=50;
        
    case 'F13'
        fobj = @F13;
        lb=-50;
        ub=50;
        dim=50;
        
    case 'F14'
        fobj = @F14;
        lb=-65.536;
        ub=65.536;
        dim=2;
        
    case 'F15'
        fobj = @F15;
        lb=-5;
        ub=5;
        dim=4;
        
    case 'F16'
        fobj = @F16;
        lb=-5;
        ub=5;
        dim=2;
        
    case 'F17'
        fobj = @F17;
        lb=[-5,0];
        ub=[10,15];
        dim=2;
        
    case 'F18'
        fobj = @F18;
        lb=-2;
        ub=2;
        dim=2;
        
    case 'F19'
        fobj = @F19;
        lb=0;
        ub=1;
        dim=3;
        
    case 'F20'
        fobj = @F20;
        lb=0;
        ub=1;
        dim=6;     
        
    case 'F21'
        fobj = @F21;
        lb=0;
        ub=10;
        dim=4;    
        
    case 'F22'
        fobj = @F22;
        lb=0;
        ub=10;
        dim=4;    
        
    case 'F23'
        fobj = @F23;
        lb=0;
        ub=10;
        dim=4;   

 end
end

% F1

function o = F1(x)
o=sum(x.^2);
end

% F2

function o = F2(x)
o=sum(abs(x))+prod(abs(x));
end

% F3

function o = F3(x)
dim=size(x,2);
o=0;
for i=1:dim
    o=o+sum(x(1:i))^2;
end
end

% F4

function o = F4(x)
o=max(abs(x));
end

三、執行結果

四、備註

版本:2014a
完整程式碼或代寫加1564658423