2024年新算法-三角拓扑聚合优化算法(TTAO)-MATLAB代码

三角拓扑聚合优化算法(TTAO)提出了一种新的基于数学的元启发式算法,即三角化拓扑聚合优化器(TTAO),用于求解连续优化和工程应用。该算法的核心是基于数学中类似的三角形拓扑结构。TTAO算法包含泛型聚合和局部聚合两种策略,有助于迭代地构造多个相似的三角形拓扑单元。

MATLAB代码如下:

function [fbest,Xbest,Convergence_curve]=TTAO(PopSize,T,Low,Up,Dim,fobj)
N=floor(PopSize/3); % Initialize N/3 individuals.
X1=rand(N,Dim).*(Up-Low)+Low;
t=1;
while t<T+1
    %% Formation of triangular topological units
    l=9*exp(-t/T);% The size of a triangular topological unit.
    for i=1:N
        theta=rand(1,Dim)*pi;
        h1=cos(theta);
        h2=cos(theta+pi/3);
        X2(i,:)=X1(i,:)+l*h1;
        X3(i,:)=X1(i,:)+l*h2;
    end
    X2 = max(X2,Low);
    X2 = min(X2,Up);
    X3 = max(X3,Low);
    X3 = min(X3,Up);
    r1=rand;r2=rand;
    X4=r1*X1+r2.*X2+(1-r1-r2)*X3;
    X4 = max(X4,Low);
    X4 = min(X4,Up);
    for i=1:N
        X1_fit(i)=fobj(X1(i,:));
        X2_fit(i)=fobj(X2(i,:));
        X3_fit(i)=fobj(X3(i,:));
        X4_fit(i)=fobj(X4(i,:));
    end
    X=[X1 X2 X3 X4];
    fit=[X1_fit;X2_fit;X3_fit;X4_fit];
    [X_sort,index]=sort(fit);
    %% Find the ptimial point and the suboptimial point in each triangular topological unit.
    for i=1:N
        X_best_1(i,:)=X(i,(index(1,i)-1)*Dim+1:index(1,i)*Dim);
        X_best_2(i,:)=X(i,(index(2,i)-1)*Dim+1:index(2,i)*Dim);
    end
    best_fit_1=X_sort(1,:);
    best_fit_2=X_sort(2,:);
    %% Generic aggregation
    for i=1:N
        r=rand(1,Dim);
        X_new=X_best_1;
        X_new(i,:)=[];
        l1=randi(N-1);
        X_G(i,:)=(r.*X_best_1(i,:)+(ones(1,Dim)-r).*X_new(l1,:));
        X_G(i,:) = max(X_G(i,:),Low);
        X_G(i,:) = min(X_G(i,:),Up);
        X_fit_G(i)=fobj(X_G(i,:));
        if X_fit_G(i)<best_fit_1(i)
            X_best_1(i,:)=X_G(i,:);
            best_fit_1(i)=X_fit_G(i);
        elseif X_fit_G(i)<best_fit_2(i)
            X_best_2(i,:)=X_G(i,:);
        end
    end
    %% Local aggregation
    for i=1:N
        a=(exp(1)-(exp(1))^3)/(T-1);
        b=(exp(1))^3-a;
        alpha=log(a*t+b);
        X_C(i,1:Dim)=X_best_1(i,1:Dim)+alpha*(X_best_1(i,1:Dim)-X_best_2(i,1:Dim));
        X_C(i,:) = max(X_C(i,:),Low);
        X_C(i,:) = min(X_C(i,:),Up);
        X_fit_C(i)=fobj(X_C(i,:));
        if X_fit_C(i)<best_fit_1(i)
            X_best_1(i,:)=X_C(i,:);
            best_fit_1(i)=X_fit_C(i);
        end
    end
    %% 
    N00=PopSize-N*3;
    if N00~=0
        X00=rand(PopSize-N*3,Dim).*(Up-Low)+Low;
        for i=1:N00
            X00_fit=fobj(X00(i,:));
        end
        X_1_0=[X_best_1;X00];
        X_1_0_fit=[best_fit_1,X00_fit];
        [~,index01]=sort(X_1_0_fit);
        X_best_1=X_1_0(index01(1:N),:);
        best_fit_1=X_1_0_fit(index01(1:N));
    end
    X1=X_best_1;
    %% The first N/3 individuals serve as the initial population for the next iteration.
    [~,index1]=min(best_fit_1);
    Xbest=X1(index1,:);
    fbest=best_fit_1(index1);
    Convergence_curve(t)=fbest;
    t = t + 1;
end

测试结果:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值