一、蚁狮算法简介

1.原理

ALO算法模拟了蚁狮在自然界中的捕猎机制。它们的名字来源于它们独特的狩猎行为和它们最喜欢的猎物。蚁狮沿着圆形的路径移动,用它巨大的下颚在沙子中挖出一个锥形的坑。在挖好陷阱后,藏在圆锥形的底部(作为坐等捕食者),等待被困在坑中的昆虫(最好是蚂蚁),如图1所示。实施了蚂蚁随机行走、设置陷阱、用陷阱诱捕蚂蚁、捕捉猎物和重建陷阱等主要步骤。

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab

图1 蚁狮的捕猎行为

1.算法步骤

11觅食的蚂蚁随机行走

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_02

图2 蚂蚁的随机行走 (3次)

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_03

为了模拟蚁狮的捕猎能力,采用了轮盘赌的方法。如图3所示,假设蚂蚁只被困在一只选定的蚁狮中。蚁群算法在优化过程中需要利用轮盘赌轮操作器根据蚁群的适应度选择蚁群。这一机制为更适合的蚁狮捕食蚂蚁提供了更高的机会。

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_04

图3 蚂蚁在蚁狮陷阱里的随机行走

1.2设置陷阱

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_05

1.3用陷阱诱捕蚂蚁

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_06

1.4捕获猎物并重建洞穴

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_07

2.伪代码

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_08

图4 ALO算法伪代码

二、优选策略的自适应蚁狮优化算法

2.1自适应边界

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_09

 2.2 优选轮盘赌策略

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_10

 2.3 动态比例系数

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_11

 算法步骤

【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_12

三、仿真实验与结果分析
% fobj = @YourCostFunction
% dim = number of your variables
% Max_iteration = maximum number of generations
% 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
% If all the variables have equal lower bound you can just
% define lb and ub as two single number numbers

% To run ALO: [Best_score,Best_pos,cg_curve]=ALO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj)

function [min_value,Elite_antlion_fitness,Elite_antlion_position,Convergence_curve]=ALO(N,Max_iter,lb,ub,dim,fobj)

% Initialize the positions of antlions and ants
antlion_position=initialization(N,dim,ub,lb);
ant_position=initialization(N,dim,ub,lb);

% Initialize variables to save the position of elite, sorted antlions, 
% convergence curve, antlions fitness, and ants fitness
Sorted_antlions=zeros(N,dim);
Elite_antlion_position=zeros(1,dim);
Elite_antlion_fitness=inf;
Convergence_curve=zeros(1,Max_iter);
antlions_fitness=zeros(1,N);
ants_fitness=zeros(1,N);

% Calculate the fitness of initial antlions and sort them
for i=1:size(antlion_position,1)
    antlions_fitness(1,i)=fobj(antlion_position(i,:)); 
end

[sorted_antlion_fitness,sorted_indexes]=sort(antlions_fitness);
    
for newindex=1:N
     Sorted_antlions(newindex,:)=antlion_position(sorted_indexes(newindex),:);
end
    
Elite_antlion_position=Sorted_antlions(1,:);
Elite_antlion_fitness=sorted_antlion_fitness(1);

% Main loop start from the second iteration since the first iteration 
% was dedicated to calculating the fitness of antlions
Current_iter=2; 
while Current_iter<Max_iter+1
    
    % This for loop simulate random walks
    for i=1:size(ant_position,1)
        % Select ant lions based on their fitness (the better anlion the higher chance of catching ant)
        Rolette_index=RouletteWheelSelection(1./sorted_antlion_fitness);
        if Rolette_index==-1  
            Rolette_index=1;
        end
      
        % RA is the random walk around the selected antlion by rolette wheel
        RA=Random_walk_around_antlion(dim,Max_iter,lb,ub, Sorted_antlions(Rolette_index,:),Current_iter);
        
        % RA is the random walk around the elite (best antlion so far)
        [RE]=Random_walk_around_antlion(dim,Max_iter,lb,ub, Elite_antlion_position(1,:),Current_iter);
        
        ant_position(i,:)= (RA(Current_iter,:)+RE(Current_iter,:))/2; % Equation (2.13) in the paper          
    end
    
    for i=1:size(ant_position,1)  
        
        % Boundar checking (bring back the antlions of ants inside search
        % space if they go beyoud the boundaries
        Flag4ub=ant_position(i,:)>ub;
        Flag4lb=ant_position(i,:)<lb;
        ant_position(i,:)=(ant_position(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;  
        
        ants_fitness(1,i)=fobj(ant_position(i,:));        
       
    end
    
    % Update antlion positions and fitnesses based of the ants (if an ant 
    % becomes fitter than an antlion we assume it was cought by the antlion  
    % and the antlion update goes to its position to build the trap)
    double_population=[Sorted_antlions;ant_position];
    double_fitness=[sorted_antlion_fitness ants_fitness];
        
    [double_fitness_sorted I]=sort(double_fitness);
    double_sorted_population=double_population(I,:);
        
    antlions_fitness=double_fitness_sorted(1:N);
    Sorted_antlions=double_sorted_population(1:N,:);
        
    % Update the position of elite if any antlinons becomes fitter than it
    if antlions_fitness(1)<Elite_antlion_fitness 
        Elite_antlion_position=Sorted_antlions(1,:);
        Elite_antlion_fitness=antlions_fitness(1);
    end
      
    % Keep the elite in the population
    Sorted_antlions(1,:)=Elite_antlion_position;
    antlions_fitness(1)=Elite_antlion_fitness;
  
    % Update the convergence curve
    Convergence_curve(Current_iter)=Elite_antlion_fitness;

    % Display the iteration and best optimum obtained so far
    if mod(Current_iter,1)==0
        display(['At iteration ', num2str(Current_iter), ' the elite fitness is ', num2str(Elite_antlion_fitness)]);
    end
min_value(Current_iter)=Elite_antlion_fitness;
    Current_iter=Current_iter+1; 
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.

将改进蚁狮算法(PSALO)与原始蚁狮算法(ALO)、樽海鞘群算法(SSA)进行对比,仿真30次,每次迭代500次,种群规模为30。以F1~F3为例。
下图是F1的对比曲线。【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_13三种算法的最大值、最小值、平均值和标准差显示如下:

函数:F1
SSA:最大值: 1.976e-06,最小值:3.3803e-08,平均值:2.093e-07,标准差:3.9333e-07
ALO:最大值: 0.0097103,最小值:0.00022597,平均值:0.0018599,标准差:0.0022659
PSALO:最大值: 1.1972e-09,最小值:1.7294e-11,平均值:3.9346e-10,标准差:3.428e-10
  • 1.
  • 2.
  • 3.
  • 4.

下图是F2的对比曲线。【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_14

三种算法的最大值、最小值、平均值和标准差显示如下:

函数:F2
SSA:最大值: 5.0543,最小值:0.12765,平均值:1.9419,标准差:1.4266
ALO:最大值: 127.5844,最小值:5.1073,平均值:56.8097,标准差:48.045
PSALO:最大值: 2.1726e-05,最小值:4.3211e-06,平均值:1.0354e-05,标准差:5.0614e-06
  • 1.
  • 2.
  • 3.
  • 4.

下图是F3的对比曲线。【优化求解】基于优选策略的自适应蚁狮优化算法matlab源码_matlab_15三种算法的最大值、最小值、平均值和标准差显示如下:

函数:F3
SSA:最大值: 3008.01,最小值:236.0645,平均值:1270.2519,标准差:616.1047
ALO:最大值: 13305.4836,最小值:1777.0977,平均值:4707.7349,标准差:2533.4001
PSALO:最大值: 3.2929e-08,最小值:2.662e-09,平均值:1.3591e-08,标准差:8.0512e-09
  • 1.
  • 2.
  • 3.
  • 4.

综上,PSALO具有较好的进化寻优性能,求解精度、收敛速度和稳定性均较优。

四、参考文献

[1] 刘景森,霍宇,李煜.优选策略的自适应蚁狮优化算法[J].模式识别与人工智能,2020,33(2):121-132.