A brief introduction of dragonfly algorithm

1. Dragonfly bionic optimization algorithmThe main idea of dragonfly algorithm optimization calculation is realized by simulating the predatory behavior of dragonflies (FIG. 1). This flight (evolutionary) optimization mechanism can be expressed as five steps of dragonfly colony separation, alignment, aggregation, food attraction and natural enemy dispersal.FIG. 1 Main ideas of dragonfly algorithm optimization calculation (1) separation. Denoting to avoid the close distance of dragonflies and reduce the optimization efficiency:Where Ek is the separation degree of dragonfly K; D represents the current position of the dragonfly; Dj represents the position of the JTH adjacent dragonfly; J represents the number of dragonflies adjacent to the KTH dragonfly in the population.

(2) alignment. Denotes the degree to which the speed of a dragonfly is the same as that of its neighbors:Where Uk is the alignment degree of dragonfly K; Vj represents the flight speed of the JTH nearby dragonfly; The other symbols have the same meaning.

(3). Indicates that a dragonfly has a tendency to get closer to the nearby superior dragonfly:Where Bk is the aggregation degree of Dragonfly K; The other symbols have the same meaning.

4. Food attraction. Food refers to the position of the optimal individual in an iterative calculation:Where Sk is the food attraction of dragonfly K; D+ represents the optimal dragonfly position in the current calculation.

(5) Natural enemies dispersed. The purpose is to keep individuals as far away from the worst dragonfly individuals as possible and improve the optimization calculation efficiency:Where, Tk is the natural enemy dispersal degree of dragonfly K; D- represents the position of the worst dragonfly in the current calculation. Dragonfly individual K flight position update step size:Dragonfly flight position update:In the formula, e, u, B, S and T represent the influence coefficients of separation degree, alignment degree, aggregation degree, food attraction degree and dispersal degree of natural enemies respectively. β represents the inertia coefficient; L stands for iterative counting subscript; The other symbols have the same meaning.

2 Dragonfly algorithm implementation 2.1 Algorithm Adjustment In this study, the optimization solution mechanism of Dragonfly algorithm is adjusted as follows. (1) Introducing the initial population individual optimization mechanism. For a randomly selected dragonfly individual in the initial population, a feasible solution can be obtained through preliminary optimization calculation, and the original dragonfly individual can be replaced by a new individual after optimization, which can ensure that there is at least one feasible solution in the initial population. (2) Increase the local rationality judgment mechanism. In order to improve the optimization efficiency of the algorithm, a reasonableness examination operator is added to the dragonfly algorithm, which retains the reasonable parts after flight and removes the unreasonable parts after flight by traversing the calculation dimensions of a single dragonfly.

2.2 Calculation ProcessThe calculation process of adaptive dragonfly algorithm includes 12 steps. Step1: Initialize the calculation parameters. Considering the solution scale of the short-term optimal scheduling model of cascade power stations, set the population number of dragonfly algorithm N=40 and the number of iterative calculation MAXiter=200.Step3: An initial dragonfly individual is randomly selected and POA algorithm is adopted to conduct optimization calculation on the selected dragonfly individuals based on the principle of single-station optimization to ensure that at least one dragonfly individual in the initial population is the feasible solution. Let the iteration times iter=1 and dragonfly dimension r=0. Step4: Judge whether there are neighbors in dragonfly individual Xk. If there are neighbors, go to Step5; otherwise, go to Step6. Step5: According to Formula (6)-(10), calculate population evolution: separation Sr, alignment Ar, aggregation Cr, food attraction Fr, and natural enemy dispersal Er. According to formula (11), calculate the step length of dragonfly individual position update, and enter Step7. Step6: this dragonfly has no neighbors, so Xr=e×(ZMAX(I,t) -zmin (I,t)) is adopted to conduct individual random flight of dragonflies, and Step7 is adopted. Step7: new individuals are obtained after the current dimensional position is updated, and the objective function values of dragonfly individuals func1 and func2 before and after the current dimensional position is updated are calculated. If the judgment of func2>func1 indicates that the change of the position of this dimension is beneficial to the calculation of the objective function, then the position update of the current dimension is retained, δ Xkt+1= δ Xkt+1. If func2<func1, it indicates that the current dimensional position change is unfavorable to the objective function, then δ Xkt+1=0. Step8: Make dragonfly individual calculate dimension plus 1, namely r=r+1. Determine whether the update of all dimensions of dragonfly individuals is completed. If the update of all dimensions is completed, r=rmax, Step9 is entered; otherwise, Step5 is entered for circular calculation. Step9: Update the position of dragonfly individual Xk,Xt+1=Xt+ δ Xt+1. Step10: set k=k+1 to enter the optimization calculation of a new dragonfly individual. If k>=N, the location update calculation of all dragonfly individuals is finished and enter Step11. If k<N, it enters Stpe4 for cyclic calculation. Step11: In the current number of iterations, find out the optimal dragonfly individual and compare it with the food position. According to the target function value of whether it is better than the food position, update the food position and make iter=iter+1. If iter>=MAXiter, go to Step12; otherwise, go to Step4. Step12: Return the food position in the current cycle iteration as the optimal calculation result, and the calculation ends.

Two, some source code

% % % __________________________________________ fobj = @ YourCostFunction dim = to optimize parameter number % % Max_iteration = maximum number of iterations SearchAgents_no = Number of dragonflies % lb=[LB1, LB2..., LBN] Lower limit % ub=[uB1, UB2...,ubn] Upper limit % To run DA: [Best_score,Best_pos,cg_curve]=DA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj) %__________________________________________ clear all clc SearchAgents_no=40; % number of dragonflies Function_name='F1'; % Name of the test function that can be from F1 to F23 (Table 1.2.3 in the paper)

Max_iteration=500; Load details of the selected Benchmark function [lb,ub,dim,fobj]=Get_Functions_details(Function_name); % Function parameters initialization [Best_score,Best_pos,cg_curve]=DA(SearchAgents_no,Max_iteration,lb, UB,dim,fobj); figure('Position'[400 400 560 190])

%Draw search space
subplot(1.2.1);
func_plot(Function_name);
title('Test function')
xlabel('x_1');
ylabel('x_2');
zlabel([Function_name,'( x_1 , x_2 )'])
grid off

%Draw objective space
subplot(1.2.2);
semilogy(cg_curve,'Color'.'r')
title('Convergence curve')
xlabel('Iteration');
ylabel('Best score obtained so far');

axis tight
grid off
box on
legend('DA')

display(['The best solution obtained by DA is : ', num2str(Best_pos')]);
display(['The best optimal value of the objective funciton found by DA is : ', num2str(Best_score)]); % DIM = Number of parameters to be optimized % Max_iteration = Maximum number of iterations % SearchAgents_no = Number of dragonflies % lb=[lB1, LB2... LBN] Lower limit % ub=[UB1, UB2... ubn] The value is described as follows: % To run DA: [Best_score,Best_pos,cg_curve]=DA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj) %__________________________________________ function [Best_score,Best_pos,cg_curve]=DA(SearchAgents_no,Max_iteration,lb, UB,dim,fobj) %function [output variable]= function name (input variable)DA is optimizing your problem'); cg_curve=zeros(1,Max_iteration); % returns a 0 matrix with 1 x Max_iteration if size(ub,2)==1 %size(ub,2) returns the number of ub columns. %ones(1,dim) generates a full 1 matrix of 1xDim lb=ones(1,dim)*lb; End % Initialize dragonfly neighborhood radius r=(UB-lb)/10; % 1*10 20 Delta_max=(ub-lb)/10; % 1*10 20 Food_fitness=inf; % infinity Food_pos=zeros(dim,1); %10*1 0 Enemy_fitness=-inf; % Enemy_pos=zeros(dim,1); %10*1 0 X=initialization(SearchAgents_no,dim,ub,lb); %10*40 [-100,100] random number Fitness=zeros(1,SearchAgents_no); %1*40 0 DeltaX=initialization(SearchAgents_no,dim,ub,lb); % 10 * 40 [100100] for iter = 1: Max_iteration r = (ub - lb) / 4 + ((ub - lb) * (iter/Max_iteration) * 2); % The greater the number of iterations. The larger the radius of the initial 1 * 10 w = 0.9-50.8 iter * ((0.9 0.4)/Max_iteration); 0.899 my_c falling % 1 * 1 = 0.1 - iter * ((0.1 0)/(Max_iteration / 2)); If my_c<0 my_c=0; if my_c<0 my_c=0; end s=2*rand*my_c; A =2*rand*my_c; % alignment 0.1884 c=2*rand*my_c; % cohesion 0.1791 F =2*rand; % food attractiveness 0.8826 e=my_c; Enemy repelling force 0.0996% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % to find food and natural enemies for I = 1: SearchAgents_no % first calculate all target Fitness (1, I) = fobj (X (: I) '); %X(:,i)If Fitness(1, I)
        
         Enemy_fitness % if all(X(:, I)
        ) && all( X(:,i)>lb') Enemy_fitness=Fitness(1,i); % 5.6813 * 10 ^ 4 Enemy_pos = X (:, I); End end end % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % find each dragonfly neighbors for I = 1: SearchAgents_no index = 0; neighbours_no=0; Clear Neighbours_DeltaX clear Neighbours_X % For j=1:SearchAgents_no Dist2Enemy=distance(X(:, I),X(:,j)); If (all(Dist2Enemy<=r) && all(Dist2Enemy~=0)) index=index+1; % Neighbours_no =neighbours_no+1; % Number of neighbours Neighbours_DeltaX(:,index)=DeltaX(:,j); Neighbours_X(:,index)=X(:,j); End end separation - % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % Eq. The (3.1) S = zeros (dim, 1); if neighbours_no>1 for k=1:neighbours_no S=S+(Neighbours_X(:,k)-X(:,i)); end S=-S; else S=zeros(dim,1); Aligned end % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % Eq. (3.2) if neighbours_no > 1 A = (sum (Neighbours_DeltaX ')')/neighbours_no;
        elseA=DeltaX(:,i); End of the cohesion and % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % Eq. The (3.3)
        if neighbours_no>1
            C_temp=(sum(Neighbours_X')')/neighbours_no; else C_temp=X(:,i); end C=C_temp-X(:,i); Near food % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % Eq. (3.4) Dist2Food = short (X (: I), Food_pos (:, 1)); if all(Dist2Food<=r) F=Food_pos-X(:,i); else F=0; End away from the natural enemy % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % Eq. (3.5) Dist2Enemy = short (X (: I), Enemy_pos (:, 1)); if all(Dist2Enemy<=r) Enemy=Enemy_pos+X(:,i); else Enemy=zeros(dim,1); End for tt=1: Dim if X(tt, I)>ub(tt)% =lb(tt, I); DeltaX(tt,i)=rand; end if X(tt,i)Copy the code

3. Operation results

Matlab version and references

1 matlab version 2014A

[1] Yang Baoyang, YU Jizhou, Yang Shan. Intelligent Optimization Algorithm and Its MATLAB Example (2nd Edition) [M]. Publishing House of Electronics Industry, 2016. [2] ZHANG Yan, WU Shuigen. MATLAB Optimization Algorithm source code [M]. Tsinghua University Press, 2017.