In-depth explanation of practical application cases of MATLAB algorithm - [Optimization Algorithm] Hybrid Leadership Optimization Algorithm (HLBO) (with MATLAB and Python code implementation)

Code

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,:);                       

Guess you like

Origin blog.csdn.net/qq_36130719/article/details/133355002