Slime mold optimization algorithm (SMA) of intelligent optimization algorithm, with matlab code

The slime mold algorithm is an intelligent optimization algorithm proposed in 2020. It mainly simulates the foraging behavior and state changes of Chlamydomonas polycephalum in nature under different food concentrations. Slime molds mainly secrete enzymes to digest food. The front end of the slime mold is extended into a fan shape, and the rear end is surrounded by a network of interconnected veins. Different concentrations of food in the environment affect the flow of cytoplasm in the venous network of slime molds, thus forming different states of foraging for slime molds.

1. Algorithm principle

When the slime mold is close to the food, the mathematical model of the slime mold algorithm is expressed as follows:

X(t+1)=\left\{\begin{array}{cc}X_{b}(t)+v b \cdot\left(W \cdot X_{m}(t)-X_{n}(t)\right), & r<p \\v c \cdot X(t), & r \geq p\end{array}\right.

Among them, t is the current iteration number, Xb(t) is the optimal position of the slime mold individual at the tth iteration, Xm(t) and Xn(t) are the positions of two slime mold individuals randomly selected, and vb is used as the control parameter The range is [-a,a], vc is a parameter that decreases linearly from 1 to 0, and r is a random value between [0,1]. W is the weight of the slime mold, representing the fitness weight. The mathematical model formula of control variable p and parameter vb is as follows:

p=tanh\left | S(i)-DF) \right |

vb=[-a,a]]

The calculation formula of a is as follows:

Among them, i∈1, 2, 3..., n, S(i) is the fitness value of the ith slime mold, and DF is the best fitness value in all iterations. The fitness weight W is shown in the formula:

Among them, condition indicates the slime mold individuals whose fitness value ranks in the top half. The fitness sequence is the fitness value sequence of the slime mold. When solving the minimum problem, it uses the ascending order method. Among them, the optimal fitness value in the current iteration times is represented by OF, and the worst fitness value is represented by MF. When the slime mold wraps the food, the mathematical model of the slime mold algorithm is as follows:

The slime mold's venous tissue and biological oscillators change as the slime mold grabs food.
The higher the concentration of food that the vein is exposed to, the stronger the wave generated by the bio-oscillator , and by virtue of this change, the slime mold will grasp the higher concentration of food. Variations in slime mold vein width were achieved using W, vb and vc. W simulates the oscillation frequency of slime molds in the vicinity under different food concentrations. vb changes randomly between [-a, a], and gradually approaches zero as the number of iterations increases. The value of vc oscillates between [-1,1] and eventually tends to 0. The mutual synergy between vb and vc plays an important role when slime molds choose food.

2. Results display

Take the CEC2005 function set as an example to display the results

 3. MATLAB core code

% 黏菌优化算法(SMA)
% max _ iter:最大迭代次数,N:种群大小,收敛曲线:收敛曲线,
function [Destination_fitness,bestPositions,Convergence_curve]=SMA(N,Max_iter,lb,ub,dim,fobj)

%% 初始化位置
bestPositions=zeros(1,dim);
Destination_fitness=inf;%将此更改为 -inf 以解决最大化问题
AllFitness = inf*ones(N,1);%记录所有粘菌的适应度
weight = ones(N,dim);%每个粘菌的适应度权重
%% 初始化随机解集
X=initialization(N,dim,ub,lb);
Convergence_curve=zeros(1,Max_iter);
it=1;  %迭代次数
lb=ones(1,dim).*lb; % 变量下限
ub=ones(1,dim).*ub; % 变量上限
z=0.03; % 参数

%% 主循环
while  it <= Max_iter
    
    %=====适应度排序======
    for i=1:N
        % 检查解决方案是否超出搜索空间并将其带回
        Flag4ub=X(i,:)>ub;
        Flag4lb=X(i,:)<lb;
        X(i,:)=(X(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;
        AllFitness(i) = fobj(X(i,:));
    end
    
    [SmellOrder,SmellIndex] = sort(AllFitness); 
    worstFitness = SmellOrder(N);
    bestFitness = SmellOrder(1);

    S=bestFitness-worstFitness+eps;  %加上 eps 以避免分母为零

    %====计算每个粘菌的适应度权重=====
    for i=1:N
        for j=1:dim
            if i<=(N/2) 
                weight(SmellIndex(i),j) = 1+rand()*log10((bestFitness-SmellOrder(i))/(S)+1);
            else
                weight(SmellIndex(i),j) = 1-rand()*log10((bestFitness-SmellOrder(i))/(S)+1);
            end
        end
    end
    
    %====更新最佳适应度值和最佳位置=====
    if bestFitness < Destination_fitness
        bestPositions=X(SmellIndex(1),:);
        Destination_fitness = bestFitness;
    end
    
    a = atanh(-(it/Max_iter)+1);  
    b = 1-it/Max_iter;
    
    %====更新搜索代理的位置=====
    for i=1:N
        if rand<z    
            X(i,:) = (ub-lb)*rand+lb;
        else
            p =tanh(abs(AllFitness(i)-Destination_fitness)); 
            vb = unifrnd(-a,a,1,dim); 
            vc = unifrnd(-b,b,1,dim);
            for j=1:dim
                r = rand();
                A = randi([1,N]);  % 从总体中随机选择两个位置
                B = randi([1,N]);
                if r<p    
                    X(i,j) = bestPositions(j)+ vb(j)*(weight(i,j)*X(A,j)-X(B,j));
                else
                    X(i,j) = vc(j)*X(i,j);
                end
            end
        end
    end
    Convergence_curve(it)=Destination_fitness;
     display(['At iteration ', num2str(it), ' the best solution fitness is ', num2str(Destination_fitness)]);
    it=it+1;
      
end

end

How to obtain the complete code: Reply to the keyword in the small card below: TGDM1209

references:

[1] Li S, Chen H, Wang M, et al. Slime mould algorithm: A newmethod for stochastic optimization[J]. Future Generation Computer Systems. 2020, 111(1): 300-323.

[2] Gong Ran, Shi Wenjuan, Zhu Zhenyuan. Slime Mold Optimization Algorithm Based on Chaos Mapping and Levi's Flight[J]. Computer and Digital Engineering, 2023,51(02):361-367.

Guess you like

Origin blog.csdn.net/woaipythonmeme/article/details/131303357