[code]%====================蜻蜓优化算法的五个步骤===========================function [Best_score,Best_pos,cg_curve]=DA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj)cg_curve=zeros(1,Max_iteration);if size(ub,2)==1 ub=ones(1,dim)*ub; lb=ones(1,dim)*lb;end%% 蜻蜓邻域的初始半径r=(ub-lb)/10;Delta_max=(ub-lb)/10;Food_fitness=inf;Food_pos=zeros(dim,1);Enemy_fitness=-inf;Enemy_pos=zeros(dim,1);X=initialization(SearchAgents_no,dim,ub,lb);Fitness=zeros(1,SearchAgents_no);DeltaX=initialization(SearchAgents_no,dim,ub,lb);for iter=1:Max_iteration r=(ub-lb)/4+((ub-lb)*(iter/Max_iteration)*2); w=0.9-iter*((0.9-0.4)/Max_iteration); my_c=0.1-iter*((0.1-0)/(Max_iteration/2)); if my_c1 A=(sum(Neighbours_DeltaX')')/neighbours_no; else A=DeltaX(:,i); end %% 聚集 if neighbours_no>1 C_temp=(sum(Neighbours_X')')/neighbours_no; else C_temp=X(:,i); end C=C_temp-X(:,i); %% 食物吸引 Dist2Food=distance(X(:,i),Food_pos(:,1)); if all(Dist2Food1 for j=1:dim DeltaX(j,i)=w*DeltaX(j,i)+rand*A(j,1)+rand*C(j,1)+rand*S(j,1); if DeltaX(j,i)>Delta_max(j) DeltaX(j,i)=Delta_max(j); end if DeltaX(j,i)Delta_max(j) DeltaX(j,i)=Delta_max(j); end if DeltaX(j,i)ub'; Flag4lb=X(:,i)1 C_temp=(sum(Neighbours_X')')/neighbours_no; else C_temp=X(:,i); end C=C_temp-X(:,i); %% 食物吸引 Dist2Food=distance(X(:,i),Food_pos(:,1)); if all(Dist2Food1 for j=1:dim DeltaX(j,i)=w*DeltaX(j,i)+rand*A(j,1)+rand*C(j,1)+rand*S(j,1); if DeltaX(j,i)>Delta_max(j) DeltaX(j,i)=Delta_max(j); end if DeltaX(j,i)Delta_max(j) DeltaX(j,i)=Delta_max(j); end if DeltaX(j,i)ub'; Flag4lb=X(:,i)a)+k.*((-x-a).^m).*(x