MATLAB算法实战应用案例精讲-【优化算法】混合领导优化算法(HLBO)(附MATLAB和Python代码实现)

代码实现

MATLAB

HLBO.m


function[Best_score,Best_pos,HLBO_curve]=HLBO(SearchAgents,Max_iterations,lowerbound,upperbound,dimension,fitness)

lowerbound=ones(1,dimension).*(lowerbound);                              % Lower limit for variables
upperbound=ones(1,dimension).*(upperbound);                              % Upper limit for variables

%%
for i=1:dimension
    X(:,i) = lowerbound(i)+rand(SearchAgents,1).*(upperbound(i) - lowerbound(i));                   % Initial population
end

for i =1:SearchAgents
    L=X(i,:);
    fit(i)=fitness(L);
end
%%

for t=1:Max_iterations
    %% update the best member
    [best , blocation]=min(fit);
    [fworst , ~]=max(fit);

    %% Phase 1: Exploration phase
    % candidate solution
    for i=1:SearchAgents
    Q(i,:)=fit-fworst/fit(i)-fworst;              %eqn(4)
    end

    if t==1
        Xbest=X(blocation,:);                       

你可能感兴趣的:(matlab,算法,开发语言)