├── LICENSE ├── Optimizers ├── AFT.m ├── AHA.m ├── ALO.m ├── AOA.m ├── AVOA.m ├── CSA.m ├── DA.m ├── DMOA.asv ├── DMOA.m ├── EO.m ├── E_WOA.m ├── FDA.m ├── GA.m ├── GOA.m ├── GTO.m ├── GWO.m ├── Get_Functions_details.m ├── IGOA.m ├── IGWO.m ├── MFO.m ├── MVO.m ├── Main2.m ├── NGO.m ├── POA.m ├── PSO.m ├── SA.m ├── SCA.m ├── SO.m ├── SS.m ├── SSA.m ├── WOA.m ├── WSO.m ├── color_list.mat └── main.m ├── README.md └── Results ├── 1.bmp ├── 2.bmp ├── 3.bmp └── 4.bmp /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 VG-TechCenter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Optimizers/AFT.m: -------------------------------------------------------------------------------- 1 | 2 | %% Ali baba and the Forty Thieves (AFT) algorithm source code version 1.0 3 | % 4 | % Developed in MATLAB R2018a 5 | % 6 | % Programmed by Malik Braik 7 | % Al-Balqa Applied University (BAU) % 8 | % e-Mail: m_fjo@yahoo.com 9 | % mbraik@bau.edu.au 10 | 11 | % ------------------------------------------------- 12 | % This demo implements a standard version of AFT algorithm for minimization problems 13 | % of a standard test function on MATLAB (R2018). 14 | % ------------------------------------------------- 15 | % Note: 16 | % Due to the stochastic nature of meta-heuristcs, 17 | % different runs may slightly produce different results. 18 | 19 | function [fitness,gbest,ccurve]=AFT(noThieves,itemax,lb,ub,dim,fobj) 20 | 21 | %% Convergence curve 22 | ccurve=zeros(1,itemax); 23 | 24 | % f1 = figure (1); 25 | % set(gcf,'color','w'); 26 | % hold on 27 | % xlabel('Iteration','interpreter','latex','FontName','Times','fontsize',10) 28 | % ylabel('fitness value','interpreter','latex','FontName','Times','fontsize',10); 29 | % grid; 30 | 31 | % Fit dimension 32 | if size(ub,1)==1 33 | ub=ones(dim,1)*ub; 34 | lb=ones(dim,1)*lb; 35 | end 36 | 37 | %% Start AFT 38 | % % Generation of initial solutions (position of thieves) 39 | 40 | xth=zeros(noThieves, dim); 41 | 42 | for i=1:noThieves 43 | for j=1:dim 44 | xth(i,j)= lb(j)-rand()*(lb(j)-ub(j)) ; % Position of the thieves in the space 45 | end 46 | end 47 | 48 | %% Evaluate the fitness of the initial population (thieves) 49 | 50 | fit=zeros(noThieves, 1); 51 | 52 | for i=1:noThieves 53 | fit(i,1)=fobj(xth(i,:)); 54 | end 55 | 56 | %% Initalization of the parameters of AFT 57 | 58 | fitness=fit; % Initial the fitness of the random positions of the thieves 59 | 60 | %Calculate the initial fitness of the thieves 61 | 62 | [sorted_thieves_fitness,sorted_indexes]=sort(fit); 63 | 64 | for index=1:noThieves 65 | Sorted_thieves(index,:)=xth(sorted_indexes(index),:); 66 | end 67 | 68 | gbest=Sorted_thieves(1,:); % initialization of the global position of the thieves 69 | fit0=sorted_thieves_fitness(1); 70 | 71 | best = xth; % initialization of the best position of the thieves (based on Marjaneh's astute plans) 72 | xab=xth; % initialization of the position of Ali Baba 73 | 74 | 75 | %% Start running AFT 76 | for ite=1:itemax 77 | 78 | % Two essential parameters for the AFT algorithm 79 | Pp=0.1*log(2.75*(ite/itemax)^0.1); % Perception potential 80 | Td = 2* exp(-2*(ite/itemax)^2); % Tracking distance 81 | 82 | % Generation of random candidate followers (thieves (chasing)) 83 | a=ceil((noThieves-1).*rand(noThieves,1))'; % 84 | %% % Generation of a new position for the thieves 85 | for i=1:noThieves 86 | if (rand>=0.5)% In this case, the thieves know where to search (TRUE); 87 | if rand>Pp 88 | xth(i,:)=gbest +(Td*(best(i,:)-xab(i,:))*rand+Td*(xab(i,:)-best(a(i),:))*rand)*sign(rand-0.50);% Generation of a new position for the thieves (case 1) 89 | else 90 | 91 | for j=1:dim 92 | xth(i,j)= Td*((ub(j)-lb(j))*rand+lb(j)); % Generation of a new position for the thieves (case 3) 93 | end 94 | 95 | end 96 | % Generation of a new position for the thieves (case 2) 97 | else %In this case, the thieves do NOT know where to search (based on Marjaneh's astute plans), but the thieves can GUESS to look at several opposite directions (Tricks) 98 | 99 | for j=1:dim 100 | xth(i,j)=gbest(j) -(Td*(best(i,j)-xab(i,j))*rand+Td*(xab(i,j)-best(a(i),j))*rand)*sign(rand-0.50); 101 | 102 | end 103 | end 104 | 105 | end 106 | 107 | %% Update the global, best, position of the thieves and Ali Baba as well 108 | 109 | for i=1:noThieves 110 | 111 | % Evaluation of the fitness 112 | 113 | fit(i,1)=fobj(xth(i,:)); 114 | 115 | % Handling the boundary conditions 116 | 117 | if and (~(xth(i,:)-lb<= 0),~(xth(i,:) - ub>= 0)) 118 | xab(i,:)=xth(i,:); % Update the position of Ali Baba based on the movements of the thieves and Marjaneh plans 119 | 120 | if fit(i)=3 47 | RandNum=ceil(rand*(Dim-2)+1); 48 | else 49 | RandNum=ceil(rand*(Dim-1)+1); 50 | end 51 | DirectVector(i,RandDim(1:RandNum))=1; 52 | else 53 | if r>2/3 % Omnidirectional flight 54 | DirectVector(i,:)=1; 55 | else % Axial flight 56 | RandNum=ceil(rand*Dim); 57 | DirectVector(i,RandNum)=1; 58 | end 59 | end 60 | 61 | if rand<0.5 % Guided foraging 62 | [MaxUnvisitedTime,TargetFoodIndex]=max(VisitTable(i,:)); 63 | MUT_Index=find(VisitTable(i,:)==MaxUnvisitedTime); 64 | if length(MUT_Index)>1 65 | [~,Ind]= min(PopFit(MUT_Index)); 66 | TargetFoodIndex=MUT_Index(Ind); 67 | end 68 | 69 | newPopPos=PopPos(TargetFoodIndex,:)+randn*DirectVector(i,:).*... 70 | (PopPos(i,:)-PopPos(TargetFoodIndex,:)); 71 | newPopPos=SpaceBound(newPopPos,Up,Low); 72 | newPopFit=BenFunctions(newPopPos); 73 | 74 | if newPopFitUp)+(Xub; 91 | Flag4lb=ant_position(i,:)1 145 | for i=1:dim 146 | ub_i=ub(i); 147 | lb_i=lb(i); 148 | X(:,i)=rand(SearchAgents_no,1).*(ub_i-lb_i)+lb_i; 149 | end 150 | end 151 | end 152 | 153 | function [RWs]=Random_walk_around_antlion(Dim,max_iter,lb, ub,antlion,current_iter) 154 | if size(lb,1) ==1 && size(lb,2)==1 %Check if the bounds are scalar 155 | lb=ones(1,Dim)*lb; 156 | ub=ones(1,Dim)*ub; 157 | end 158 | 159 | if size(lb,1) > size(lb,2) %Check if boundary vectors are horizontal or vertical 160 | lb=lb'; 161 | ub=ub'; 162 | end 163 | 164 | I=1; % I is the ratio in Equations (2.10) and (2.11) 165 | 166 | if current_iter>max_iter/10 167 | I=1+100*(current_iter/max_iter); 168 | end 169 | 170 | if current_iter>max_iter/2 171 | I=1+1000*(current_iter/max_iter); 172 | end 173 | 174 | if current_iter>max_iter*(3/4) 175 | I=1+10000*(current_iter/max_iter); 176 | end 177 | 178 | if current_iter>max_iter*(0.9) 179 | I=1+100000*(current_iter/max_iter); 180 | end 181 | 182 | if current_iter>max_iter*(0.95) 183 | I=1+1000000*(current_iter/max_iter); 184 | end 185 | 186 | 187 | % Dicrease boundaries to converge towards antlion 188 | lb=lb/(I); % Equation (2.10) in the paper 189 | ub=ub/(I); % Equation (2.11) in the paper 190 | 191 | % Move the interval of [lb ub] around the antlion [lb+anlion ub+antlion] 192 | if rand<0.5 193 | lb=lb+antlion; % Equation (2.8) in the paper 194 | else 195 | lb=-lb+antlion; 196 | end 197 | 198 | if rand>=0.5 199 | ub=ub+antlion; % Equation (2.9) in the paper 200 | else 201 | ub=-ub+antlion; 202 | end 203 | 204 | % This function creates n random walks and normalize accroding to lb and ub 205 | % vectors 206 | for i=1:Dim 207 | X = [0 cumsum(2*(rand(max_iter,1)>0.5)-1)']; % Equation (2.1) in the paper 208 | %[a b]--->[c d] 209 | a=min(X); 210 | b=max(X); 211 | c=lb(i); 212 | d=ub(i); 213 | X_norm=((X-a).*(d-c))./(b-a)+c; % Equation (2.7) in the paper 214 | RWs(:,i)=X_norm; 215 | end 216 | end 217 | 218 | function choice = RouletteWheelSelection(weights) 219 | accumulation = cumsum(weights); 220 | p = rand() * accumulation(end); 221 | chosen_index = -1; 222 | for index = 1 : length(accumulation) 223 | if (accumulation(index) > p) 224 | chosen_index = index; 225 | break; 226 | end 227 | end 228 | choice = chosen_index; 229 | end 230 | -------------------------------------------------------------------------------- /Optimizers/AOA.m: -------------------------------------------------------------------------------- 1 | 2 | function [Best_FF,Best_P,Conv_curve]=AOA(N,M_Iter,LB,UB,Dim,F_obj) 3 | % display('AOA Working'); 4 | %Two variables to keep the positions and the fitness value of the best-obtained solution 5 | 6 | Best_P=zeros(1,Dim); 7 | Best_FF=inf; 8 | Conv_curve=zeros(1,M_Iter); 9 | 10 | %Initialize the positions of solution 11 | X=initialization(N,Dim,UB,LB); 12 | Xnew=X; 13 | Ffun=zeros(1,size(X,1));% (fitness values) 14 | Ffun_new=zeros(1,size(Xnew,1));% (fitness values) 15 | 16 | MOP_Max=1; 17 | MOP_Min=0.2; 18 | C_Iter=1; 19 | Alpha=5; 20 | Mu=0.499; 21 | 22 | 23 | for i=1:size(X,1) 24 | Ffun(1,i)=F_obj(X(i,:)); %Calculate the fitness values of solutions 25 | if Ffun(1,i)0.5 45 | Xnew(i,j)=Best_P(1,j)/(MOP+eps)*((UB-LB)*Mu+LB); 46 | else 47 | Xnew(i,j)=Best_P(1,j)*MOP*((UB-LB)*Mu+LB); 48 | end 49 | else 50 | r3=rand(); 51 | if r3>0.5 52 | Xnew(i,j)=Best_P(1,j)-MOP*((UB-LB)*Mu+LB); 53 | else 54 | Xnew(i,j)=Best_P(1,j)+MOP*((UB-LB)*Mu+LB); 55 | end 56 | end 57 | end 58 | 59 | 60 | if (size(LB,2)~=1) % if each of the UB and LB has more than one value 61 | r1=rand(); 62 | if r10.5 65 | Xnew(i,j)=Best_P(1,j)/(MOP+eps)*((UB(j)-LB(j))*Mu+LB(j)); 66 | else 67 | Xnew(i,j)=Best_P(1,j)*MOP*((UB(j)-LB(j))*Mu+LB(j)); 68 | end 69 | else 70 | r3=rand(); 71 | if r3>0.5 72 | Xnew(i,j)=Best_P(1,j)-MOP*((UB(j)-LB(j))*Mu+LB(j)); 73 | else 74 | Xnew(i,j)=Best_P(1,j)+MOP*((UB(j)-LB(j))*Mu+LB(j)); 75 | end 76 | end 77 | end 78 | 79 | end 80 | 81 | Flag_UB=Xnew(i,:)>UB; % check if they exceed (up) the boundaries 82 | Flag_LB=Xnew(i,:)1 121 | for i=1:Dim 122 | Ub_i=UB(i); 123 | Lb_i=LB(i); 124 | X(:,i)=rand(N,1).*(Ub_i-Lb_i)+Lb_i; 125 | end 126 | end 127 | end 128 | 129 | -------------------------------------------------------------------------------- /Optimizers/AVOA.m: -------------------------------------------------------------------------------- 1 | %秃鹰优化算法 2 | function [Best_vulture1_F,Best_vulture1_X,convergence_curve]=AVOA(pop_size,max_iter,lower_bound,upper_bound,variables_no,fobj) 3 | 4 | % initialize Best_vulture1, Best_vulture2 5 | Best_vulture1_X=zeros(1,variables_no); 6 | Best_vulture1_F=inf; 7 | Best_vulture2_X=zeros(1,variables_no); 8 | Best_vulture2_F=inf; 9 | 10 | %Initialize the first random population of vultures 11 | X=initialization(pop_size,variables_no,upper_bound,lower_bound); 12 | 13 | %% Controlling parameter 14 | p1=0.6; 15 | p2=0.4; 16 | p3=0.6; 17 | alpha=0.8; 18 | betha=0.2; 19 | gamma=2.5; 20 | 21 | %%Main loop 22 | current_iter=0; % Loop counter 23 | 24 | while current_iter < max_iter 25 | for i=1:size(X,1) 26 | % Calculate the fitness of the population 27 | current_vulture_X = X(i,:); 28 | current_vulture_F=fobj(current_vulture_X); 29 | 30 | % Update the first best two vultures if needed 31 | if current_vulture_FBest_vulture1_F && current_vulture_F= 1 % Exploration: 52 | current_vulture_X = exploration(current_vulture_X, random_vulture_X, F, p1, upper_bound, lower_bound); 53 | elseif abs(F) < 1 % Exploitation: 54 | current_vulture_X = exploitation(current_vulture_X, Best_vulture1_X, Best_vulture2_X, random_vulture_X, F, p2, p3, variables_no, upper_bound, lower_bound); 55 | end 56 | 57 | X(i,:) = current_vulture_X; % place the current vulture back into the population 58 | end 59 | 60 | current_iter=current_iter+1; 61 | convergence_curve(current_iter)=Best_vulture1_F; 62 | 63 | X = boundaryCheck(X, lower_bound, upper_bound); 64 | 65 | % fprintf("In Iteration %d, best estimation of the global optimum is %4.4f \n ", current_iter,Best_vulture1_F ); 66 | end 67 | 68 | end 69 | 70 | %% 71 | % This function initialize the first population of search agents 72 | function [ X ]=initialization(N,dim,ub,lb) 73 | 74 | Boundary_no= size(ub,2); % numnber of boundaries 75 | 76 | % If the boundaries of all variables are equal and user enter a signle 77 | % number for both ub and lb 78 | if Boundary_no==1 79 | X=rand(N,dim).*(ub-lb)+lb; 80 | end 81 | 82 | % If each variable has a different lb and ub 83 | if Boundary_no>1 84 | for i=1:dim 85 | ub_i=ub(i); 86 | lb_i=lb(i); 87 | X(:,i)=rand(N,1).*(ub_i-lb_i)+lb_i; 88 | end 89 | end 90 | end 91 | %% 92 | function [current_vulture_X] = exploitation(current_vulture_X, Best_vulture1_X, Best_vulture2_X, ... 93 | random_vulture_X, F, p2, p3, variables_no, upper_bound, lower_bound) 94 | 95 | % phase 1 96 | if abs(F)<0.5 97 | if rand=0.5 107 | if randub; 156 | FL=X(i,:)=0.1 91 | chameleonPositions(i,:)= chameleonPositions(i,:)+ p1*(chameleonBestPosition(ch(i),:)-chameleonPositions(i,:))*rand()+... 92 | + p2*(gPosition -chameleonPositions(i,:))*rand(); 93 | else 94 | for j=1:dim 95 | chameleonPositions(i,j)= gPosition(j)+mu*((ub(j)-lb(j))*rand+lb(j))*sign(rand-0.50) ; 96 | end 97 | end 98 | end 99 | %% Rotation of the chameleons - Update the position of CSA (Exploitation) 100 | 101 | %%% Rotation 180 degrees in both direction or 180 in each direction 102 | % 103 | 104 | % [chameleonPositions] = rotation(chameleonPositions, searchAgents, dim); 105 | 106 | %% % Chameleon velocity updates and find a food source 107 | for i=1:searchAgents 108 | 109 | v(i,:)= omega*v(i,:)+ p1*(chameleonBestPosition(i,:)-chameleonPositions(i,:))*rand +.... 110 | + p2*(gPosition-chameleonPositions(i,:))*rand; 111 | 112 | chameleonPositions(i,:)=chameleonPositions(i,:)+(v(i,:).^2 - v0(i,:).^2)/(2*a); 113 | end 114 | 115 | v0=v; 116 | 117 | %% handling boundary violations 118 | for i=1:searchAgents 119 | if chameleonPositions(i,:)ub 122 | chameleonPositions(i,:)=ub; 123 | end 124 | end 125 | 126 | %% Relocation of chameleon positions (Randomization) 127 | for i=1:searchAgents 128 | 129 | ub_=sign(chameleonPositions(i,:)-ub)>0; 130 | lb_=sign(chameleonPositions(i,:)-lb)<0; 131 | 132 | chameleonPositions(i,:)=(chameleonPositions(i,:).*(~xor(lb_,ub_)))+ub.*ub_+lb.*lb_; %%%%%*2 133 | 134 | fit(i,1)=fobj (chameleonPositions(i,:)) ; 135 | 136 | if fit(i)> get_orthonormal(5,4) 210 | % 211 | % ans = 212 | % 0.1503 -0.0884 -0.0530 0.8839 213 | % -0.4370 -0.7322 -0.1961 -0.2207 214 | % -0.3539 0.3098 0.7467 -0.0890 215 | % 0.7890 -0.1023 0.0798 -0.3701 216 | % -0.1968 0.5913 -0.6283 -0.1585 217 | 218 | 219 | 220 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 221 | % 222 | % CHECK USER INPUT 223 | % 224 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 225 | 226 | 227 | if ( (nargin==2) && (m>n) && (isnumeric(m)*isnumeric(n)) ) 228 | 229 | elseif ( nargin==1 && isnumeric(m) && length(m)==1 ) 230 | 231 | n=m; 232 | 233 | else 234 | error('Incorrect Inputs. Please read help text in m-file.') 235 | end 236 | 237 | % to get n orthogonal vectors (each of size m), we will first get a larger mxm 238 | % set of orthogonal vectors, and then just trim the set so it is 239 | % of size mxn, 240 | % 241 | % to get an mxm set of orthogonal vectors, 242 | % we can exploit the fact that the eigenvectors 243 | % from distinct eigenspaces (corresponding to different eigenvalues) of a 244 | % symmetric matrix are orthogonal 245 | 246 | 247 | 248 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 249 | % 250 | % Create the orthonormal vectors 251 | % 252 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 253 | 254 | count=0; 255 | while (count==0) 256 | 257 | % generate an mxm matrix A, then make a symmetric mxm matrix B 258 | A=rand(m); 259 | B=A'*A ; 260 | 261 | % now take the eigenvectors of B, 262 | % eigenvectors from different eigenspaces (corresponding to different 263 | % eigenvalues) will be orthogonal 264 | 265 | % there is a chance that there will be repeat eigenvalues, which would give 266 | % rise to non-orthogonal eigenvectors (though they will still be independent) 267 | % we will check for this below 268 | % if this does happen, we will just start the loop over again 269 | % and hope that the next randomly created symmetric matrix will not 270 | % have repeat eigenvalues, 271 | % (another approach would be to put the non-orthogonal vectors 272 | % through the gram-schmidt process and get orthogonal vectors that way) 273 | 274 | % since matlab returns unit length eigenvectors, they will also be 275 | % orthonormal 276 | 277 | [P,D] = eig(B) ; 278 | 279 | % can double check the orthonormality, by taking the difference between 280 | % P'P and I, if it is non-zero, then there is an error (caused by repeat 281 | % eigenvalues), repeat the loop over again 282 | 283 | if ((P'*P - eye(m))>eps) 284 | % error, vectors not orthonormal, repeat the random matrix draw again 285 | count=0; 286 | else 287 | % we want the first n of these orthonormal columns 288 | answer=P(:,1:n) ; 289 | count=1; 290 | end 291 | 292 | 293 | end 294 | end 295 | 296 | %% 297 | function [chameleonPositions]=rotation(chameleonPosition, searchAgents, dim) 298 | for i=1:searchAgents 299 | if (dim>2) 300 | xmax=1;xmin=-1; 301 | th=round(xmin+rand(1,1)*(xmax-xmin)); 302 | vec=get_orthonormal(dim,2); 303 | vecA=vec(:,1); 304 | vecB=vec(:,2); 305 | theta=(th*rand()*180)*(pi/180) ; 306 | Rot = RotMatrix(theta,vecA, vecB) ; 307 | if (theta~=0) 308 | V=[chameleonPosition(i,:) ]; 309 | V_centre=mean(V,1); %Centre, of line 310 | Vc=V-ones(size(V,1),1)*V_centre; %Centering coordinates 311 | 312 | Vrc=[Rot*Vc']'; %Rotating centred coordinates 313 | % Vruc=[Rot*V']'; %Rotating un-centred coordinates 314 | Vr=Vrc+ones(size(V,1),1)*V_centre; %Shifting back to original location 315 | chameleonPosition(i,:)=((Vr)/1); 316 | 317 | end 318 | else 319 | xmax=1;xmin=-1; 320 | th=round(xmin+rand(1,1)*(xmax-xmin)); 321 | theta=th*rand()*180*(pi/180); 322 | Rot = RotMatrix(theta); 323 | 324 | if (theta~=0) 325 | V=[chameleonPosition(i,:) ]; 326 | V_centre=mean(V,1); %Centre, of line 327 | Vc=V-ones(size(V,1),1)*V_centre; %Centering coordinates 328 | 329 | Vrc=[Rot*Vc']'; %Rotating centred coordinates 330 | Vr=Vrc+ones(size(V,1),1)*V_centre; %Shifting back to original location 331 | chameleonPosition(i,:)=((Vr)/1); 332 | end 333 | end 334 | end 335 | chameleonPositions=chameleonPosition; 336 | end 337 | %% 338 | function R = RotMatrix(alpha, u, v) 339 | % RotMatrix - N-dimensional Rotation matrix 340 | % R = RotMatrix(alpha, u, v) 341 | % INPUT: 342 | % alpha: Angle of rotation in radians, counter-clockwise direction. 343 | % u, v: Ignored for the 2D case. 344 | % For the 3D case, u is the vector to rotate around. 345 | % For the N-D case, there is no unique axis of rotation anymore, so 2 346 | % orthonormal vectors u and v are used to define the (N-1) dimensional 347 | % hyperplane to rotate in. 348 | % u and v are normalized automatically and in the N-D case it is cared 349 | % for u and v being orthogonal. 350 | % OUTPUT: 351 | % R: Rotation matrix. 352 | % If the u (and/or v) is zero, or u and v are collinear, The rotation 353 | % matrix contains NaNs. 354 | % 355 | % REFERENCES: 356 | % analyticphysics.com/Higher%20Dimensions/Rotations%20in%20Higher%20Dimensions.htm 357 | % en.wikipedia.org/wiki/Rotation_matrix 358 | % application.wiley-vch.de/books/sample/3527406204_c01.pdf 359 | % 360 | % Initialize: ================================================================== 361 | % Global Interface: ------------------------------------------------------------ 362 | % Initial values: -------------------------------------------------------------- 363 | % Program Interface: ----------------------------------------------------------- 364 | if numel(alpha) ~= 1 365 | error('JSimon:RotMatrrix:BadInput1', ... 366 | 'Angle of rotation must be a scalar.'); 367 | end 368 | 369 | % User Interface: -------------------------------------------------------------- 370 | % Do the work: ================================================================= 371 | s = sin(alpha); 372 | c = cos(alpha); 373 | 374 | % Different algorithms for 2, 3 and N dimensions: 375 | switch nargin 376 | case 1 377 | % 2D rotation matrix: 378 | R = [c, -s; s, c]; 379 | 380 | case 2 381 | if numel(u) ~= 3 382 | error('JSimon:RotMatrrix:BadAxis2D', ... 383 | '3D: Rotation axis must have 3 elements.'); 384 | end 385 | 386 | % Normalized vector: 387 | u = u(:); 388 | u = u ./ sqrt(u.' * u); 389 | 390 | % 3D rotation matrix: 391 | x = u(1); 392 | y = u(2); 393 | z = u(3); 394 | mc = 1 - c; 395 | R = [c + x * x * mc, x * y * mc - z * s, x * z * mc + y * s; ... 396 | x * y * mc + z * s, c + y * y * mc, y * z * mc - x * s; ... 397 | x * z * mc - y * s, y * z * mc + x * s, c + z * z .* mc]; 398 | 399 | % Alternative 1 (about 60 times slower): 400 | % R = expm([0, -z, y; ... 401 | % z, 0, -x; ... 402 | % -y, x, 0] * alpha); 403 | 404 | % Alternative 2: 405 | % R = [ 0, -z, y; ... 406 | % z, 0, -x; ... 407 | % -y, x, 0] * s + (eye(3) - u * u.') * c + u * u.'; 408 | 409 | case 3 410 | n = numel(u); 411 | if n ~= numel(v) 412 | error('JSimon:RotMatrrix:BadAxes3D', ... 413 | 'ND: Axes to define plane of rotation must have the same size.'); 414 | end 415 | 416 | % Normalized vectors: 417 | u = u(:); 418 | u = u ./ sqrt(u.' * u); 419 | 420 | % Care for v being orthogonal to u: 421 | v = v(:); 422 | v = v - (u.' * v) * u; 423 | v = v ./ sqrt(v.' * v); 424 | 425 | % Rodrigues' rotation formula: 426 | R = eye(n) + ... 427 | (v * u.' - u * v.') * s + ... 428 | (u * u.' + v * v.') * (c - 1); 429 | 430 | otherwise 431 | error('JSimon:RotMatrrix:BadNInput', ... 432 | '1 to 3 inputs required.'); 433 | end 434 | 435 | end 436 | 437 | -------------------------------------------------------------------------------- /Optimizers/DA.m: -------------------------------------------------------------------------------- 1 | %___________________________________________________________________% 2 | % Dragonfly Algorithm (DA) source codes demo version 1.0 % 3 | % % 4 | % Developed in MATLAB R2011b(7.13) % 5 | % % 6 | % Author and programmer: Seyedali Mirjalili % 7 | % % 8 | % e-Mail: ali.mirjalili@gmail.com % 9 | % seyedali.mirjalili@griffithuni.edu.au % 10 | % % 11 | % Homepage: http://www.alimirjalili.com % 12 | % % 13 | % Main paper: % 14 | % % 15 | % S. Mirjalili, Dragonfly algorithm: a new meta-heuristic % 16 | % optimization technique for solving single-objective, discrete, % 17 | % and multi-objective problems, Neural Computing and Applications % 18 | % DOI: http://dx.doi.org/10.1007/s00521-015-1920-1 % 19 | % % 20 | %___________________________________________________________________% 21 | 22 | % You can simply define your cost in a seperate file and load its handle to fobj 23 | % The initial parameters that you need are: 24 | %__________________________________________ 25 | % fobj = @YourCostFunction 26 | % dim = number of your variables 27 | % Max_iteration = maximum number of generations 28 | % SearchAgents_no = number of search agents 29 | % lb=[lb1,lb2,...,lbn] where lbn is the lower bound of variable n 30 | % ub=[ub1,ub2,...,ubn] where ubn is the upper bound of variable n 31 | % If all the variables have equal lower bound you can just 32 | % define lb and ub as two single number numbers 33 | 34 | % To run DA: [Best_score,Best_pos,cg_curve]=DA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj) 35 | %__________________________________________ 36 | 37 | function [Best_score,Best_pos,cg_curve]=DA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj) 38 | 39 | % display('DA is optimizing your problem'); 40 | cg_curve=zeros(1,Max_iteration); 41 | 42 | if size(ub,2)==1 43 | ub=ones(1,dim)*ub; 44 | lb=ones(1,dim)*lb; 45 | end 46 | 47 | %The initial radius of gragonflies' neighbourhoods 48 | r=(ub-lb)/10; 49 | Delta_max=(ub-lb)/10; 50 | 51 | Food_fitness=inf; 52 | Food_pos=zeros(dim,1); 53 | 54 | Enemy_fitness=-inf; 55 | Enemy_pos=zeros(dim,1); 56 | 57 | X=initialization(SearchAgents_no,dim,ub,lb); 58 | Fitness=zeros(1,SearchAgents_no); 59 | 60 | DeltaX=initialization(SearchAgents_no,dim,ub,lb); 61 | 62 | for iter=1:Max_iteration 63 | 64 | r=(ub-lb)/4+((ub-lb)*(iter/Max_iteration)*2); 65 | 66 | w=0.9-iter*((0.9-0.4)/Max_iteration); 67 | 68 | my_c=0.1-iter*((0.1-0)/(Max_iteration/2)); 69 | if my_c<0 70 | my_c=0; 71 | end 72 | 73 | s=2*rand*my_c; % Seperation weight 74 | a=2*rand*my_c; % Alignment weight 75 | c=2*rand*my_c; % Cohesion weight 76 | f=2*rand; % Food attraction weight 77 | e=my_c; % Enemy distraction weight 78 | 79 | for i=1:SearchAgents_no %Calculate all the objective values first 80 | Fitness(1,i)=fobj(X(:,i)'); 81 | if Fitness(1,i)Enemy_fitness 87 | if all(X(:,i)lb') 88 | Enemy_fitness=Fitness(1,i); 89 | Enemy_pos=X(:,i); 90 | end 91 | end 92 | end 93 | 94 | for i=1:SearchAgents_no 95 | index=0; 96 | neighbours_no=0; 97 | 98 | clear Neighbours_DeltaX 99 | clear Neighbours_X 100 | %find the neighbouring solutions 101 | for j=1:SearchAgents_no 102 | Dist2Enemy=distance(X(:,i),X(:,j)); 103 | if (all(Dist2Enemy<=r) && all(Dist2Enemy~=0)) 104 | index=index+1; 105 | neighbours_no=neighbours_no+1; 106 | Neighbours_DeltaX(:,index)=DeltaX(:,j); 107 | Neighbours_X(:,index)=X(:,j); 108 | end 109 | end 110 | 111 | % Seperation%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 112 | % Eq. (3.1) 113 | S=zeros(dim,1); 114 | if neighbours_no>1 115 | for k=1:neighbours_no 116 | S=S+(Neighbours_X(:,k)-X(:,i)); 117 | end 118 | S=-S; 119 | else 120 | S=zeros(dim,1); 121 | end 122 | 123 | % Alignment%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 124 | % Eq. (3.2) 125 | if neighbours_no>1 126 | A=(sum(Neighbours_DeltaX')')/neighbours_no; 127 | else 128 | A=DeltaX(:,i); 129 | end 130 | 131 | % Cohesion%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 132 | % Eq. (3.3) 133 | if neighbours_no>1 134 | C_temp=(sum(Neighbours_X')')/neighbours_no; 135 | else 136 | C_temp=X(:,i); 137 | end 138 | 139 | C=C_temp-X(:,i); 140 | 141 | % Attraction to food%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 142 | % Eq. (3.4) 143 | Dist2Food=distance(X(:,i),Food_pos(:,1)); 144 | if all(Dist2Food<=r) 145 | F=Food_pos-X(:,i); 146 | else 147 | F=0; 148 | end 149 | 150 | % Distraction from enemy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 151 | % Eq. (3.5) 152 | Dist2Enemy=distance(X(:,i),Enemy_pos(:,1)); 153 | if all(Dist2Enemy<=r) 154 | Enemy=Enemy_pos+X(:,i); 155 | else 156 | Enemy=zeros(dim,1); 157 | end 158 | 159 | for tt=1:dim 160 | if X(tt,i)>ub(tt) 161 | X(tt,i)=lb(tt); 162 | DeltaX(tt,i)=rand; 163 | end 164 | if X(tt,i)r) 171 | if neighbours_no>1 172 | for j=1:dim 173 | DeltaX(j,i)=w*DeltaX(j,i)+rand*A(j,1)+rand*C(j,1)+rand*S(j,1); 174 | if DeltaX(j,i)>Delta_max(j) 175 | DeltaX(j,i)=Delta_max(j); 176 | end 177 | if DeltaX(j,i)<-Delta_max(j) 178 | DeltaX(j,i)=-Delta_max(j); 179 | end 180 | X(j,i)=X(j,i)+DeltaX(j,i); 181 | end 182 | else 183 | % Eq. (3.8) 184 | X(:,i)=X(:,i)+Levy(dim)'.*X(:,i); 185 | DeltaX(:,i)=0; 186 | end 187 | else 188 | for j=1:dim 189 | % Eq. (3.6) 190 | DeltaX(j,i)=(a*A(j,1)+c*C(j,1)+s*S(j,1)+f*F(j,1)+e*Enemy(j,1)) + w*DeltaX(j,i); 191 | if DeltaX(j,i)>Delta_max(j) 192 | DeltaX(j,i)=Delta_max(j); 193 | end 194 | if DeltaX(j,i)<-Delta_max(j) 195 | DeltaX(j,i)=-Delta_max(j); 196 | end 197 | X(j,i)=X(j,i)+DeltaX(j,i); 198 | end 199 | end 200 | 201 | Flag4ub=X(:,i)>ub'; 202 | Flag4lb=X(:,i)=L 142 | BB= 143 | AA(j,:)=(unifrnd(VarMin,VarMax,dim 144 | end 145 | pop(i).Position=unifrnd(VarMin,VarMax,VarSize); 146 | pop(i).Cost=F_obj(pop(i).Position); 147 | C(i)=0; 148 | end 149 | end 150 | % Update Best Solution Ever Found 151 | for i=1:nAlphaGroup 152 | if pop(i).Cost<=BestSol.Cost 153 | BestSol=pop(i); 154 | end 155 | end 156 | 157 | % Next Mongoose Position 158 | newtau=mean(sm); 159 | for i=1:nScout 160 | M=(pop(i).Position.*sm(i))/pop(i).Position; 161 | if newtau>tau 162 | newpop.Position=pop(i).Position-CF*phi*rand.*(pop(i).Position-M); 163 | else 164 | newpop.Position=pop(i).Position+CF*phi*rand.*(pop(i).Position-M); 165 | end 166 | tau=newtau; 167 | end 168 | 169 | % Update Best Solution Ever Found 170 | for i=1:nAlphaGroup 171 | if pop(i).Cost<=BestSol.Cost 172 | BestSol=pop(i); 173 | end 174 | end 175 | 176 | % Store Best Cost Ever Found 177 | BestCost(it)=BestSol.Cost; 178 | BEF=BestSol.Cost; 179 | BEP=BestSol.Position; 180 | % Display Iteration Information 181 | % disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(BestCost(it))]); 182 | 183 | 184 | end 185 | end 186 | 187 | %% 188 | 189 | function i=RouletteWheelSelection(P) 190 | 191 | r=rand; 192 | 193 | C=cumsum(P); 194 | 195 | i=find(r<=C,1,'first'); 196 | 197 | end 198 | %% 199 | function z=Sphere(x) 200 | 201 | z=sum(x.^2); 202 | 203 | end 204 | %% 205 | 206 | -------------------------------------------------------------------------------- /Optimizers/DMOA.m: -------------------------------------------------------------------------------- 1 | %_______________________________________________________________________________________% 2 | % Dwarf Mongoose Optimization Algorithm source codes (version 1.0) % 3 | % % 4 | % Developed in MATLAB R2015a (7.13) % 5 | % Author and programmer: Jeffrey O. Agushaka and Absalom E. Ezugwu and Laith Abualigah % 6 | % e-Mail: EzugwuA@ukzn.ac.za % 7 | % % 8 | % Main paper: % 9 | %__Dwarf Mongoose Optimization Algorithm: A new nature-inspired metaheuristic optimizer % 10 | %__Main paper: please, cite it as follws:_______________________________________________% 11 | %_______________________________________________________________________________________% 12 | %_______________________________________________________________________________________% 13 | function [BEF,BEP,BestCost]=DMOA(nPop,MaxIt,VarMin,VarMax,nVar,F_obj) 14 | 15 | 16 | 17 | %nVar=5; % Number of Decision Variables 18 | 19 | VarSize=[1 nVar]; % Decision Variables Matrix Size 20 | 21 | %VarMin=-10; % Decision Variables Lower Bound 22 | %VarMax= 10; % Decision Variables Upper Bound 23 | 24 | %% ABC Settings 25 | 26 | % MaxIt=1000; % Maximum Number of Iterations 27 | 28 | % nPop=100; % Population Size (Family Size) 29 | 30 | nBabysitter= 3; % Number of babysitters 31 | 32 | nAlphaGroup=nPop-nBabysitter; % Number of Alpha group 33 | 34 | nScout=nAlphaGroup; % Number of Scouts 35 | 36 | L=round(0.6*nVar*nBabysitter); % Babysitter Exchange Parameter 37 | 38 | peep=2; % Alpha female痴 vocalization 39 | 40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 41 | 42 | % Empty Mongoose Structure 43 | empty_mongoose.Position=[]; 44 | empty_mongoose.Cost=[]; 45 | 46 | % Initialize Population Array 47 | pop=repmat(empty_mongoose,nAlphaGroup,1); 48 | 49 | % Initialize Best Solution Ever Found 50 | BestSol.Cost=inf; 51 | tau=inf; 52 | Iter=1; 53 | sm=inf(nAlphaGroup,1); 54 | 55 | % Create Initial Population 56 | for i=1:nAlphaGroup 57 | for j=1:VarSize 58 | BB=unifrnd(VarMin(j),VarMax(j),VarSize); 59 | AA(j,:)=BB(1,:); 60 | end 61 | pop(i).Position=AA; 62 | pop(i).Cost=F_obj(pop(i).Position); 63 | if pop(i).Cost<=BestSol.Cost 64 | BestSol=pop(i); 65 | end 66 | end 67 | 68 | % Abandonment Counter 69 | C=zeros(nAlphaGroup,1); 70 | CF=(1-Iter/MaxIt)^(2*Iter/MaxIt); 71 | 72 | % Array to Hold Best Cost Values 73 | BestCost=zeros(MaxIt,1); 74 | 75 | %% DMOA Main Loop 76 | 77 | for it=1:MaxIt 78 | 79 | % Alpha group 80 | F=zeros(nAlphaGroup,1); 81 | MeanCost = mean([pop.Cost]); 82 | for i=1:nAlphaGroup 83 | 84 | % Calculate Fitness Values and Selection of Alpha 85 | F(i) = exp(-pop(i).Cost/MeanCost); % Convert Cost to Fitness 86 | end 87 | P=F/sum(F); 88 | % Foraging led by Alpha female 89 | for m=1:nAlphaGroup 90 | 91 | % Select Alpha female 92 | i=RouletteWheelSelection(P); 93 | 94 | % Choose k randomly, not equal to Alpha 95 | K=[1:i-1 i+1:nAlphaGroup]; 96 | k=K(randi([1 numel(K)])); 97 | 98 | % Define Vocalization Coeff. 99 | phi=(peep/2)*unifrnd(-1,+1,VarSize); 100 | 101 | % New Mongoose Position 102 | newpop.Position=pop(i).Position+phi.*(pop(i).Position-pop(k).Position); 103 | 104 | % Evaluation 105 | newpop.Cost=F_obj(newpop.Position); 106 | 107 | % Comparision 108 | if newpop.Cost<=pop(i).Cost 109 | pop(i)=newpop; 110 | else 111 | C(i)=C(i)+1; 112 | end 113 | 114 | end 115 | 116 | % Scout group 117 | for i=1:nScout 118 | 119 | % Choose k randomly, not equal to i 120 | K=[1:i-1 i+1:nAlphaGroup]; 121 | k=K(randi([1 numel(K)])); 122 | 123 | % Define Vocalization Coeff. 124 | phi=(peep/2)*unifrnd(-1,+1,VarSize); 125 | 126 | % New Mongoose Position 127 | newpop.Position=pop(i).Position+phi.*(pop(i).Position-pop(k).Position); 128 | 129 | % Evaluation 130 | newpop.Cost=F_obj(newpop.Position); 131 | 132 | % Sleeping mould 133 | sm(i)=(newpop.Cost-pop(i).Cost)/max(newpop.Cost,pop(i).Cost); 134 | 135 | % Comparision 136 | if newpop.Cost<=pop(i).Cost 137 | pop(i)=newpop; 138 | else 139 | C(i)=C(i)+1; 140 | end 141 | 142 | end 143 | % Babysitters 144 | for i=1:nBabysitter 145 | if C(i)>=L 146 | for j=1:VarSize 147 | BB=unifrnd(VarMin(j),VarMax(j),VarSize); 148 | AA(j,:)=BB(1,:); 149 | end 150 | % pop(i).Position=unifrnd(VarMin,VarMax,VarSize); 151 | pop(i).Position=AA; 152 | pop(i).Cost=F_obj(pop(i).Position); 153 | C(i)=0; 154 | end 155 | end 156 | % Update Best Solution Ever Found 157 | for i=1:nAlphaGroup 158 | if pop(i).Cost<=BestSol.Cost 159 | BestSol=pop(i); 160 | end 161 | end 162 | 163 | % Next Mongoose Position 164 | newtau=mean(sm); 165 | for i=1:nScout 166 | M=(pop(i).Position.*sm(i))/pop(i).Position; 167 | if newtau>tau 168 | newpop.Position=pop(i).Position-CF*phi*rand.*(pop(i).Position-M); 169 | else 170 | newpop.Position=pop(i).Position+CF*phi*rand.*(pop(i).Position-M); 171 | end 172 | tau=newtau; 173 | end 174 | 175 | % Update Best Solution Ever Found 176 | for i=1:nAlphaGroup 177 | if pop(i).Cost<=BestSol.Cost 178 | BestSol=pop(i); 179 | end 180 | end 181 | 182 | % Store Best Cost Ever Found 183 | BestCost(it)=BestSol.Cost; 184 | BEF=BestSol.Cost; 185 | BEP=BestSol.Position; 186 | % Display Iteration Information 187 | % disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(BestCost(it))]); 188 | 189 | 190 | end 191 | end 192 | 193 | %% 194 | 195 | function i=RouletteWheelSelection(P) 196 | 197 | r=rand; 198 | 199 | C=cumsum(P); 200 | 201 | i=find(r<=C,1,'first'); 202 | 203 | end 204 | %% 205 | function z=Sphere(x) 206 | 207 | z=sum(x.^2); 208 | 209 | end 210 | %% 211 | 212 | -------------------------------------------------------------------------------- /Optimizers/EO.m: -------------------------------------------------------------------------------- 1 | %_________________________________________________________________________________ 2 | % Equilibrium Optimizer source code (Developed in MATLAB R2015a) 3 | % 4 | % programming: Afshin Faramarzi & Seyedali Mirjalili 5 | % 6 | % e-Mail: afaramar@hawk.iit.edu, afshin.faramarzi@gmail.com 7 | % 8 | % paper: 9 | % A. Faramarzi, M. Heidarinejad, B. Stephens, S. Mirjalili, 10 | % Equilibrium optimizer: A novel optimization algorithm 11 | % Knowledge-Based Systems 12 | % DOI: https://doi.org/10.1016/j.knosys.2019.105190 13 | %____________________________________________________________________________________ 14 | 15 | function [Ave,Sd,Convergence_curve]=EO(Particles_no,Max_iter,lb,ub,dim,fobj,Run_no) 16 | 17 | for irun=1:Run_no 18 | 19 | Ceq1=zeros(1,dim); Ceq1_fit=inf; 20 | Ceq2=zeros(1,dim); Ceq2_fit=inf; 21 | Ceq3=zeros(1,dim); Ceq3_fit=inf; 22 | Ceq4=zeros(1,dim); Ceq4_fit=inf; 23 | 24 | C=initialization(Particles_no,dim,ub,lb); 25 | 26 | 27 | Iter=0; V=1; 28 | 29 | a1=2; 30 | a2=1; 31 | GP=0.5; 32 | 33 | while Iterub; 38 | Flag4lb=C(i,:)Ceq1_fit && fitness(i)Ceq1_fit && fitness(i)>Ceq2_fit && fitness(i)Ceq1_fit && fitness(i)>Ceq2_fit && fitness(i)>Ceq3_fit && fitness(i)=GP); % Eq(15) 83 | G0=GCP.*(Ceq-lambda.*C(i,:)); % Eq(14) 84 | G=G0.*F; % Eq(13) 85 | C(i,:)=Ceq+(C(i,:)-Ceq).*F+(G./lambda*V).*(1-F); % Eq(16) 86 | end 87 | 88 | Iter=Iter+1; 89 | Convergence_curve(Iter)=Ceq1_fit; 90 | Ceqfit_run(irun)=Ceq1_fit; 91 | 92 | end 93 | 94 | 95 | % display(['Run no : ', num2str(irun)]); 96 | % display(['The best solution obtained by EO is : ', num2str(Ceq1,10)]); 97 | % display(['The best optimal value of the objective funciton found by EO is : ', num2str(Ceq1_fit,10)]); 98 | % disp(sprintf('--------------------------------------')); 99 | end 100 | 101 | 102 | Ave=mean(Ceqfit_run); 103 | Sd=std(Ceqfit_run); 104 | end 105 | 106 | %% 107 | function [Cin,domain]=initialization(SearchAgents_no,dim,ub,lb) 108 | 109 | Boundary_no= size(ub,2); % numnber of boundaries 110 | 111 | % If the boundaries of all variables are equal and user enter a signle 112 | % number for both ub and lb 113 | if Boundary_no==1 114 | Cin=rand(SearchAgents_no,dim).*(ub-lb)+lb; 115 | domain=ones(1,dim)*(ub-lb); 116 | end 117 | 118 | 119 | % If each variable has a different lb and ub 120 | if Boundary_no>1 121 | for i=1:dim 122 | ub_i=ub(i); 123 | lb_i=lb(i); 124 | Cin(:,i)=rand(SearchAgents_no,1).*(ub_i-lb_i)+lb_i; 125 | end 126 | domain=ones(1,dim).*(ub-lb); 127 | end 128 | end 129 | -------------------------------------------------------------------------------- /Optimizers/E_WOA.m: -------------------------------------------------------------------------------- 1 | % ========================================================================= 2 | % 3 | % Enhanced whale optimization algorithm (E-WOA) source codes 4 | % 5 | % Authors: Mohammad H.Nadimi-Shahraki, Hoda Zamani,Seyedali Mirjalili 6 | % 7 | % --------------------------------------------- 8 | % Papers: Enhanced whale optimization algorithm for medical feature selection: A COVID-19 case study 9 | % Computers in Biology and Medicine,Volume 148, September 2022, 105858. 10 | % https://www.sciencedirect.com/science/article/pii/S0010482522006126 11 | % https://doi.org/10.1016/j.compbiomed.2022.105858 12 | % --------------------------------------------- 13 | % More materials are available on ResearchGate and for any questions please contact the authors. 14 | % Emails:nadimi.mh@gmail.com, zamanie.hoda@gmail.com, ali.mirjalili@gmail.com 15 | % ========================================================================= 16 | function [Score_best,X_best,Convergence]= E_WOA(SearchAgents_no,Max_iter,lb,ub,problem_size,Function) 17 | lb= lb.*ones(1, problem_size); 18 | ub=ub.*ones(1, problem_size); 19 | % Initialize the positions of search agents 20 | Positions = initialization(SearchAgents_no,problem_size,ub,lb); 21 | for j = 1:SearchAgents_no 22 | Fitness(j,1) = Function(Positions(j,:)); 23 | end 24 | % Set the best position for leader 25 | [temp_fit, sorted_index] = sort(Fitness, 'ascend'); 26 | X_best = Positions(sorted_index(1),:); 27 | Score_best = temp_fit(1); 28 | % ==================================================== % 29 | P_rate = 20; % The portion rate 30 | Pool.Kappa = 1.5 * SearchAgents_no; % The maximum pool size 31 | Pool.position = zeros(0, problem_size); % The solutions stored in the pool 32 | 33 | Idx0 = (SearchAgents_no - (Pool.Kappa * 0.3)+1); 34 | X_worst = Positions(sorted_index(Idx0: end),:); 35 | Pool = Pooling_Mechanism(Pool,problem_size,X_worst, X_best); 36 | 37 | Convergence = zeros(1,Max_iter); 38 | t = 1; 39 | % Main loop 40 | while t <= Max_iter 41 | 42 | a2 = -1+t*((-1)/Max_iter); 43 | 44 | % Randomly select a P portion of the humpback whales 45 | P_portion = randperm(SearchAgents_no,P_rate); 46 | 47 | Pop_Pool = Pool.position; 48 | [P_rnd1, P_rnd2] = RandIndex(size(Pop_Pool,1), SearchAgents_no); 49 | 50 | %% Probability rate 51 | p = rand(SearchAgents_no, 1); 52 | 53 | %% Cauchy distribution 54 | A = 0.5 + 0.1 * tan(pi * (rand(SearchAgents_no, 1) - 0.5)); 55 | Idx = find(A <= 0); 56 | while ~ isempty(Idx) 57 | A(Idx) = 0.5 + 0.1 * tan(pi * (rand(length(Idx), 1) - 0.5)); 58 | Idx = find(A <= 0); 59 | end 60 | A = min(A, 1); 61 | 62 | for i = 1:size(Positions,1) 63 | if (i ~= P_portion) 64 | C = 2*rand; % Eq. (6) in the paper 65 | b = 1; 66 | for j=1:size(Positions,2) 67 | l=(a2-1)*rand+1; 68 | if p(i) < 0.5 69 | if A(i) < 0.5 % Enriched encircling prey search strategy 70 | rand_leader_index = floor(size(Pop_Pool,1)*rand()+1); % Randomly selected from the matrix Pool 71 | P_rnd3 = Pop_Pool(rand_leader_index, j); 72 | D_prim = abs(C * X_best(j) - P_rnd3); % Eq. (17) 73 | X(i,j) = X_best(j)- A(i)*D_prim; % Eq. (16) 74 | 75 | elseif A(i)>= 0.5 % Preferential selecting search strategy 76 | X(i,j) = Positions(i,j) + A(i)*( C* Pop_Pool(P_rnd1(i),j)- Pop_Pool(P_rnd2(i),j)) ; % Eq. (15) 77 | end 78 | elseif p(i)>=0.5 % Spiral bubble-net attacking 79 | D_prim = abs(X_best(j)- Positions(i,j)); % Eq. (10) 80 | X(i,j)= D_prim * exp(b.*l).*cos(2*pi*l)+ X_best(j);% Eq. (9) 81 | end 82 | end 83 | end 84 | end 85 | %% Migrating search strategy 86 | best_max = max(X_best); 87 | best_min = min(X_best); 88 | P_portion = P_portion'; 89 | X_rnd = rand(size(P_portion,1),problem_size).* (ub - lb) + lb; % Eq.(13) 90 | X_brnd = rand(size(P_portion,1),problem_size).*(best_max - best_min)+ best_min ; % Eq.(14) 91 | X(P_portion, :) = X_rnd - X_brnd; % Eq.(12) 92 | 93 | %% Computing the fitness of whales 94 | for i = 1: size(Positions,1) 95 | X(i,:) = boundConstraint(X(i,:), Positions(i,:), lb,ub); 96 | Fit(i,1) = Function(X(i,:)); 97 | 98 | if Fit(i,1) < Score_best 99 | Score_best = Fit(i,1); 100 | X_best = X(i,:); 101 | end 102 | end 103 | I = (Fitness > Fit); 104 | Ind = find(I == 1); 105 | X_worst = Positions(Ind, :); 106 | % Definition 1. (Pooling mechanism) 107 | Pool = Pooling_Mechanism(Pool, problem_size, X_worst, X_best); 108 | 109 | % Updating the position of whales 110 | Fitness(Ind) = Fit(Ind) ; 111 | Positions(Ind, :) = X(Ind, :); 112 | 113 | Convergence(t) = Score_best; 114 | t = t + 1; 115 | end 116 | end 117 | 118 | function [rnd1,rnd2] = RandIndex(NP1,SearchAgents_no) 119 | warning off 120 | 121 | rnd0 = 1 : SearchAgents_no; 122 | NP0 = length(rnd0); 123 | 124 | % == 1 125 | rnd1 = floor(rand(1, NP0) * NP1) + 1; 126 | Idx = (rnd1 == rnd0); 127 | while sum(Idx) ~= 0 128 | rnd1(Idx) = floor(rand(1, sum(Idx)) * NP1) + 1; 129 | Idx = (rnd1 == rnd0); 130 | end 131 | % == 2 132 | rnd2 = floor(rand(1, NP0) * NP1) + 1; 133 | Idx = ((rnd2 == rnd1) | (rnd2 == rnd0)); 134 | while sum(Idx) ~= 0 135 | rnd2(Idx) = floor(rand(1, sum(Idx)) * NP1) + 1; 136 | Idx = ((rnd2 == rnd1) | (rnd2 == rnd0)); 137 | end 138 | end 139 | 140 | function Pool = Pooling_Mechanism(Pool,problem_size,X_worst, X_best) 141 | 142 | % Definition 1. (Pooling mechanism) 143 | best_max = max(X_best); 144 | best_min = min(X_best); 145 | 146 | B = randi([0 1], size(X_worst,1),size(X_worst,2)); 147 | X_brnd = rand(size(X_worst,1),problem_size).*(best_max - best_min) + best_min ; % Eq.(14) 148 | P = B.* X_brnd + ~B .* X_worst; % Eq.(11) 149 | 150 | %% Store to Pool 151 | PoolCrntSize = size(Pool.position,1); 152 | FreeSpace = abs(Pool.Kappa - PoolCrntSize ) ; 153 | P = unique(P, 'rows'); 154 | if FreeSpace ~= 0 155 | if size (P,1) <= FreeSpace 156 | PopAll = [Pool.position ; P]; 157 | PopAll = unique(PopAll, 'rows'); 158 | Pool.position = PopAll; 159 | else 160 | Pool.position (PoolCrntSize+1:Pool.Kappa,:) = P(1:FreeSpace,:); 161 | Rm = size(P,1) - FreeSpace; 162 | rnd = randi(PoolCrntSize,Rm,1); 163 | Pool.position(rnd,:) = P(FreeSpace+1:end,:); 164 | end 165 | else 166 | rnd = randi(PoolCrntSize,size(P,1),1); 167 | Pool.position(rnd,:) = P; 168 | end 169 | Pool.position = unique(Pool.position, 'rows'); 170 | end 171 | 172 | function Positions=initialization(SearchAgents_no,dim,ub,lb) 173 | Boundary_no= size(ub,2); % numnber of boundaries 174 | % If the boundaries of all variables are equal and user enter a signle 175 | % number for both ub and lb 176 | if Boundary_no==1 177 | Positions=rand(SearchAgents_no,dim).*(ub-lb)+lb; 178 | end 179 | % If each variable has a different lb and ub 180 | if Boundary_no>1 181 | for i=1:dim 182 | ub_i=ub(i); 183 | lb_i=lb(i); 184 | Positions(:,i)=rand(SearchAgents_no,1).*(ub_i-lb_i)+lb_i; 185 | end 186 | end 187 | end 188 | 189 | function X = boundConstraint (X, Positions, lb,ub) 190 | 191 | % if the boundary constraint is violated, set the value to be the middle 192 | % of the previous value and the bound 193 | % 194 | % Version: 1.1 Date: 11/20/2007 195 | % Written by Jingqiao Zhang, jingqiao@gmail.com 196 | lu(1, :) = lb; lu(2, :) = ub; 197 | [NP, ~] = size(Positions); 198 | 199 | %% check the lower bound 200 | X_l = repmat(lu(1, :), NP, 1); 201 | pos = X < X_l; 202 | X(pos) = (Positions(pos) + X_l(pos)) / 2; 203 | 204 | %% check the upper bound 205 | xu = repmat(lu(2, :), NP, 1); 206 | pos = X > xu; 207 | X(pos) = (Positions(pos) + xu(pos)) / 2; 208 | end -------------------------------------------------------------------------------- /Optimizers/FDA.m: -------------------------------------------------------------------------------- 1 | %___________________________________________________________________% 2 | % Flow Direction Algorithm (FDA): source codes version 1.0 % 3 | % % 4 | % Developed in MATLAB R2017b % 5 | % % 6 | % Authors:H Karami, M Valikhan Anaraki, S Farzin, S. Mirjalili % 7 | % programmers: H Karami, M Valikhan Anaraki, S Farzin, S. Mirjalili % 8 | % % 9 | % e-Mails: h.karami@semnan.ac.ir % 10 | % mvalikhan@semnan.ac.ir % 11 | % saeed.farzin@semnan.ac.ir % 12 | % ali.mirjalili@gmail.com % 13 | % seyedali.mirjalili@griffithuni.edu.au % 14 | % % 15 | % Main paper: H Karami, M Valikhan Anaraki, S Farzin, S. Mirjalili% 16 | % Flow Direction Algorithm (FDA): % 17 | % A Novel Optimization Approach for % 18 | % Solving Optimization Problems, % 19 | % Computers & Industrial Engineering % 20 | % % 21 | % DOI: https://doi.org/10.1016/j.cie.2021.107224 % 22 | % % 23 | %___________________________________________________________________% 24 | % 25 | % Flow Direction Algorithm 26 | function [Best_fitness,BestX,ConvergenceCurve]=FDA(maxiter,lb,ub,dim,fobj,alpha,beta) 27 | % Initialize the positions of flows 28 | flow_x=initialization(alpha,dim,ub,lb); 29 | neighbor_x=zeros(beta,dim); 30 | newflow_x=inf(size(flow_x)); 31 | newfitness_flow=inf(size(flow_x,1)); 32 | ConvergenceCurve=zeros(1,maxiter); 33 | fitness_flow=inf.*ones(alpha,1); 34 | fitness_neighbor=inf.*ones(beta,1); 35 | %% calculate fitness function of each flow 36 | for i=1:alpha 37 | fitness_flow(i,:)=fobj(flow_x(i,:));%fitness of each flow 38 | end 39 | %% sort results and select the best results 40 | [~,indx]=sort(fitness_flow); 41 | flow_x=flow_x(indx,:); 42 | fitness_flow=fitness_flow(indx); 43 | Best_fitness=fitness_flow(1); 44 | BestX=flow_x(1,:); 45 | %% Initialize velocity of flows 46 | Vmax=0.1*(ub-lb); 47 | Vmin=-0.1*(ub-lb); 48 | %% Main loop 49 | for iter=1:maxiter 50 | % Update W 51 | W=(((1-1*iter/maxiter+eps)^(2*randn)).*(rand(1,dim).*iter/maxiter).*rand(1,dim)); 52 | % Update the Position of each flow 53 | for i=1:alpha 54 | % Produced the Position of neighborhoods around each flow 55 | for j=1:beta 56 | Xrand=lb+rand(1,dim).*(ub-lb); 57 | delta=W.*(rand*Xrand-rand*flow_x(i,:)).*norm(BestX-flow_x(i,:)); 58 | neighbor_x(j,:)=flow_x(i,:)+randn(1,dim).*delta; 59 | neighbor_x(j,:)=max(neighbor_x(j,:),lb); 60 | neighbor_x(j,:)=min(neighbor_x(j,:),ub); 61 | fitness_neighbor(j)=fobj(neighbor_x(j,:)); 62 | end 63 | % Sort position of neighborhoods 64 | [~,indx]=sort(fitness_neighbor); 65 | % Update position, fitness and velocity of current flow if the fitness of best neighborhood is 66 | % less than of current flow 67 | if fitness_neighbor(indx(1))Vmax 75 | V=-Vmax; 76 | end 77 | %Flow moves to best neighborhood 78 | newflow_x(i,:)=flow_x(i,:)+V.*(neighbor_x(indx(1),:)-flow_x(i,:))./sqrt(norm(neighbor_x(indx(1),:)-flow_x(i,:))); 79 | else 80 | %Generate integer random number (r) 81 | r=randi([1 alpha]); 82 | % Flow moves to r th flow if the fitness of r th flow is less 83 | % than current flow 84 | if fitness_flow(r)<=fitness_flow(i) 85 | newflow_x(i,:)=flow_x(i,:)+randn(1,dim).*(flow_x(r,:)-flow_x(i,:)); 86 | else 87 | newflow_x(i,:)=flow_x(i,:)+randn*(BestX-flow_x(i,:)); 88 | end 89 | end 90 | % Return back the flows that go beyond the boundaries of the search space 91 | newflow_x(i,:)=max(newflow_x(i,:),lb); 92 | newflow_x(i,:)=min(newflow_x(i,:),ub); 93 | % Calculate fitness function of new flow 94 | newfitness_flow(i)=fobj(newflow_x(i,:)); 95 | % Update current flow 96 | if newfitness_flow(i)ub';Tm=GrassHopperPositions(i,:)a)+k.*((-x-a).^m).*(x<(-a)); 345 | end -------------------------------------------------------------------------------- /Optimizers/IGOA.m: -------------------------------------------------------------------------------- 1 | function [TargetFitness,TargetPosition,Convergence_curve,Trajectories,fitness_history, position_history]=IGOA(N, Max_iter, lb,ub, dim, fobj) 2 | 3 | % tic 4 | % disp('GOA is now estimating the global optimum for your problem....') 5 | 6 | flag=0; 7 | if size(ub,2)==1 8 | ub=ones(dim,1)*ub; 9 | lb=ones(dim,1)*lb; 10 | else 11 | ub=ub'; 12 | lb=lb'; 13 | end 14 | 15 | if (rem(dim,2)~=0) % this algorithm should be run with a even number of variables. This line is to handle odd number of variables 16 | dim = dim+1; 17 | % ub = [ub'; 100]; 18 | % lb = [lb'; -100]; 19 | ub(dim)=100; 20 | lb(dim)=-100; 21 | flag=1; 22 | end 23 | 24 | %Initialize the population of grasshoppers 25 | GrassHopperPositions=initialization(N,dim,ub,lb); 26 | GrassHopperFitness = zeros(1,N); 27 | 28 | fitness_history=zeros(N,Max_iter); 29 | position_history=zeros(N,Max_iter,dim); 30 | Convergence_curve=zeros(1,Max_iter); 31 | Trajectories=zeros(N,Max_iter); 32 | 33 | cMax=1; 34 | cMin=0.00004; 35 | %Calculate the fitness of initial grasshoppers 36 | 37 | for i=1:size(GrassHopperPositions,1) 38 | if flag == 1 39 | GrassHopperFitness(1,i)=fobj(GrassHopperPositions(i,1:end-1)); 40 | else 41 | GrassHopperFitness(1,i)=fobj(GrassHopperPositions(i,:)); 42 | end 43 | fitness_history(i,1)=GrassHopperFitness(1,i); 44 | position_history(i,1,:)=GrassHopperPositions(i,:); 45 | Trajectories(:,1)=GrassHopperPositions(:,1); 46 | end 47 | 48 | [sorted_fitness,sorted_indexes]=sort(GrassHopperFitness); 49 | 50 | % Find the best grasshopper (target) in the first population 51 | for newindex=1:N 52 | Sorted_grasshopper(newindex,:)=GrassHopperPositions(sorted_indexes(newindex),:); 53 | end 54 | 55 | TargetPosition=Sorted_grasshopper(1,:); 56 | TargetFitness=sorted_fitness(1); 57 | 58 | % Main loop 59 | l=2; % Start from the second iteration since the first iteration was dedicated to calculating the fitness of antlions 60 | while lub';Tm=GrassHopperPositions(i,:)1 183 | for i=1:dim 184 | high=up(i);low=down(i); 185 | X(:,i)=rand(1,N).*(high-low)+low; 186 | end 187 | end 188 | end 189 | %% 190 | function o=S_func(r) 191 | f=0.5; 192 | l=1.5; 193 | o=f*exp(-r/l)-exp(-r); % Eq. (2.3) in the paper 194 | end -------------------------------------------------------------------------------- /Optimizers/IGWO.m: -------------------------------------------------------------------------------- 1 | 2 | % An Improved Grey Wolf Optimizer for Solving Engineering % 3 | % Problems (I-GWO) source codes version 1.0 % 4 | % % 5 | % Developed in MATLAB R2018a % 6 | % % 7 | % Author and programmer: M. H. Nadimi-Shahraki, S. Taghian, S. Mirjalili % 8 | % % 9 | % e-Mail: nadimi@ieee.org, shokooh.taghian94@gmail.com, ali.mirjalili@gmail.com % 10 | % % 11 | % % 12 | % Homepage: http://www.alimirjalili.com % 13 | % % 14 | % Main paper: M. H. Nadimi-Shahraki, S. Taghian, S. Mirjalili % 15 | % An Improved Grey Wolf Optimizer for Solving % 16 | % Engineering Problems , Expert Systems with % 17 | % Applicationsins, in press, % 18 | % DOI: 10.1016/j.eswa.2020.113917 % 19 | %___________________________________________________________________% 20 | %___________________________________________________________________% 21 | % Grey Wold Optimizer (GWO) source codes version 1.0 % 22 | % % 23 | % Developed in MATLAB R2011b(7.13) % 24 | % % 25 | % Author and programmer: Seyedali Mirjalili % 26 | % % 27 | % e-Mail: ali.mirjalili@gmail.com % 28 | % seyedali.mirjalili@griffithuni.edu.au % 29 | % % 30 | % Homepage: http://www.alimirjalili.com % 31 | % % 32 | % Main paper: S. Mirjalili, S. M. Mirjalili, A. Lewis % 33 | % Grey Wolf Optimizer, Advances in Engineering % 34 | % Software , in press, % 35 | % DOI: 10.1016/j.advengsoft.2013.12.007 % 36 | % % 37 | %___________________________________________________________________% 38 | 39 | % Improved Grey Wolf Optimizer (I-GWO) 40 | function [Alpha_score,Alpha_pos,Convergence_curve]=IGWO(N,Max_iter,lb,ub,dim,fobj) 41 | 42 | 43 | lu = [lb .* ones(1, dim); ub .* ones(1, dim)]; 44 | 45 | 46 | % Initialize alpha, beta, and delta positions 47 | Alpha_pos=zeros(1,dim); 48 | Alpha_score=inf; %change this to -inf for maximization problems 49 | 50 | Beta_pos=zeros(1,dim); 51 | Beta_score=inf; %change this to -inf for maximization problems 52 | 53 | Delta_pos=zeros(1,dim); 54 | Delta_score=inf; %change this to -inf for maximization problems 55 | 56 | % Initialize the positions of wolves 57 | Positions=initialization(N,dim,ub,lb); 58 | Positions = boundConstraint (Positions, Positions, lu); 59 | 60 | % Calculate objective function for each wolf 61 | for i=1:size(Positions,1) 62 | Fit(i) = fobj(Positions(i,:)); 63 | end 64 | 65 | % Personal best fitness and position obtained by each wolf 66 | pBestScore = Fit; 67 | pBest = Positions; 68 | 69 | neighbor = zeros(N,N); 70 | Convergence_curve=zeros(1,Max_iter); 71 | iter = 0;% Loop counter 72 | 73 | %% Main loop 74 | while iter < Max_iter 75 | for i=1:size(Positions,1) 76 | fitness = Fit(i); 77 | 78 | % Update Alpha, Beta, and Delta 79 | if fitnessAlpha_score && fitnessAlpha_score && fitness>Beta_score && fitness1 190 | for i=1:dim 191 | ub_i=ub(i); 192 | lb_i=lb(i); 193 | Positions(:,i)=rand(SearchAgents_no,1).*(ub_i-lb_i)+lb_i; 194 | end 195 | end 196 | end 197 | %This function is used for L-SHADE bound checking 198 | function vi = boundConstraint (vi, pop, lu) 199 | 200 | % if the boundary constraint is violated, set the value to be the middle 201 | % of the previous value and the bound 202 | % 203 | 204 | [NP, D] = size(pop); % the population size and the problem's dimension 205 | 206 | %% check the lower bound 207 | xl = repmat(lu(1, :), NP, 1); 208 | pos = vi < xl; 209 | vi(pos) = (pop(pos) + xl(pos)) / 2; 210 | 211 | %% check the upper bound 212 | xu = repmat(lu(2, :), NP, 1); 213 | pos = vi > xu; 214 | vi(pos) = (pop(pos) + xu(pos)) / 2; 215 | end 216 | -------------------------------------------------------------------------------- /Optimizers/MFO.m: -------------------------------------------------------------------------------- 1 | %______________________________________________________________________________________________ 2 | % Moth-Flame Optimization Algorithm (MFO) 3 | % Source codes demo version 1.0 4 | % 5 | % Developed in MATLAB R2011b(7.13) 6 | % 7 | % Author and programmer: Seyedali Mirjalili 8 | % 9 | % e-Mail: ali.mirjalili@gmail.com 10 | % seyedali.mirjalili@griffithuni.edu.au 11 | % 12 | % Homepage: http://www.alimirjalili.com 13 | % 14 | % Main paper: 15 | % S. Mirjalili, Moth-Flame Optimization Algorithm: A Novel Nature-inspired Heuristic Paradigm, 16 | % Knowledge-Based Systems, DOI: http://dx.doi.org/10.1016/j.knosys.2015.07.006 17 | %_______________________________________________________________________________________________ 18 | % You can simply define your cost in a seperate file and load its handle to fobj 19 | % The initial parameters that you need are: 20 | %__________________________________________ 21 | % fobj = @YourCostFunction 22 | % dim = number of your variables 23 | % Max_iteration = maximum number of generations 24 | % SearchAgents_no = number of search agents 25 | % lb=[lb1,lb2,...,lbn] where lbn is the lower bound of variable n 26 | % ub=[ub1,ub2,...,ubn] where ubn is the upper bound of variable n 27 | % If all the variables have equal lower bound you can just 28 | % define lb and ub as two single number numbers 29 | 30 | % To run MFO: [Best_score,Best_pos,cg_curve]=MFO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj) 31 | %______________________________________________________________________________________________ 32 | 33 | function [Best_flame_score,Best_flame_pos,Convergence_curve]=MFO(N,Max_iteration,lb,ub,dim,fobj) 34 | 35 | % display('MFO is optimizing your problem'); 36 | 37 | %Initialize the positions of moths 38 | Moth_pos=initialization(N,dim,ub,lb); 39 | 40 | Convergence_curve=zeros(1,Max_iteration); 41 | 42 | Iteration=1; 43 | 44 | % Main loop 45 | while Iterationub; 54 | Flag4lb=Moth_pos(i,:)Flame_no % Upaate the position of the moth with respct to one flame 112 | 113 | % Eq. (3.13) 114 | distance_to_flame=abs(sorted_population(i,j)-Moth_pos(i,j)); 115 | b=1; 116 | t=(a-1)*rand+1; 117 | 118 | % Eq. (3.12) 119 | Moth_pos(i,j)=distance_to_flame*exp(b.*t).*cos(t.*2*pi)+sorted_population(Flame_no,j); 120 | end 121 | 122 | end 123 | 124 | end 125 | 126 | Convergence_curve(Iteration)=Best_flame_score; 127 | 128 | % Display the iteration and best optimum obtained so far 129 | % if mod(Iteration,50)==0 130 | % display(['At iteration ', num2str(Iteration), ' the best fitness is ', num2str(Best_flame_score)]); 131 | % end 132 | Iteration=Iteration+1; 133 | end 134 | end 135 | 136 | function X=initialization(SearchAgents_no,dim,ub,lb) 137 | 138 | Boundary_no= size(ub,2); % numnber of boundaries 139 | 140 | % If the boundaries of all variables are equal and user enter a signle 141 | % number for both ub and lb 142 | if Boundary_no==1 143 | X=rand(SearchAgents_no,dim).*(ub-lb)+lb; 144 | end 145 | 146 | % If each variable has a different lb and ub 147 | if Boundary_no>1 148 | for i=1:dim 149 | ub_i=ub(i); 150 | lb_i=lb(i); 151 | X(:,i)=rand(SearchAgents_no,1).*(ub_i-lb_i)+lb_i; 152 | end 153 | end 154 | end 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /Optimizers/MVO.m: -------------------------------------------------------------------------------- 1 | %_______________________________________________________________________________________% 2 | % Multi-Verse Optimizer (MVO) source codes demo version 1.0 % 3 | % % 4 | % Developed in MATLAB R2011b(7.13) % 5 | % % 6 | % Author and programmer: Seyedali Mirjalili % 7 | % % 8 | % e-Mail: ali.mirjalili@gmail.com % 9 | % seyedali.mirjalili@griffithuni.edu.au % 10 | % % 11 | % Homepage: http://www.alimirjalili.com % 12 | % % 13 | % Main paper: % 14 | % % 15 | % S. Mirjalili, S. M. Mirjalili, A. Hatamlou % 16 | % Multi-Verse Optimizer: a nature-inspired algorithm for global optimization % 17 | % Neural Computing and Applications, in press,2015, % 18 | % DOI: http://dx.doi.org/10.1007/s00521-015-1870-7 % 19 | % % 20 | %_______________________________________________________________________________________% 21 | 22 | % You can simply define your cost in a seperate file and load its handle to fobj 23 | % The initial parameters that you need are: 24 | %__________________________________________ 25 | % fobj = @YourCostFunction 26 | % dim = number of your variables 27 | % Max_iteration = maximum number of generations 28 | % SearchAgents_no = number of search agents 29 | % lb=[lb1,lb2,...,lbn] where lbn is the lower bound of variable n 30 | % ub=[ub1,ub2,...,ubn] where ubn is the upper bound of variable n 31 | % If all the variables have equal lower bound you can just 32 | % define lb and ub as two single number numbers 33 | 34 | % To run MVO: [Best_score,Best_pos,cg_curve]=MVO(Universes_no,Max_iteration,lb,ub,dim,fobj) 35 | %__________________________________________ 36 | 37 | function [Best_universe_Inflation_rate,Best_universe,Convergence_curve]=MVO(N,Max_time,lb,ub,dim,fobj) 38 | 39 | %Two variables for saving the position and inflation rate (fitness) of the best universe 40 | Best_universe=zeros(1,dim); 41 | Best_universe_Inflation_rate=inf; 42 | 43 | %Initialize the positions of universes 44 | Universes=initialization(N,dim,ub,lb); 45 | 46 | %Minimum and maximum of Wormhole Existence Probability (min and max in 47 | % Eq.(3.3) in the paper 48 | WEP_Max=1; 49 | WEP_Min=0.2; 50 | 51 | Convergence_curve=zeros(1,Max_time); 52 | 53 | %Iteration(time) counter 54 | Time=1; 55 | 56 | %Main loop 57 | while Timeub; 73 | Flag4lb=Universes(i,:)0.5 121 | Universes(i,j)=Best_universe(1,j)-TDR*((ub-lb)*rand+lb); 122 | end 123 | end 124 | end 125 | 126 | if (size(lb,2)~=1) 127 | %Eq. (3.2) in the paper if the upper and lower bounds are 128 | %different for each variables 129 | r2=rand(); 130 | if r20.5 136 | Universes(i,j)=Best_universe(1,j)-TDR*((ub(j)-lb(j))*rand+lb(j)); 137 | end 138 | end 139 | end 140 | 141 | end 142 | end 143 | 144 | %Update the convergence curve 145 | Convergence_curve(Time)=Best_universe_Inflation_rate; 146 | 147 | %Print the best universe details after every 50 iterations 148 | % if mod(Time,50)==0 149 | % display(['At iteration ', num2str(Time), ' the best universes fitness is ', num2str(Best_universe_Inflation_rate)]); 150 | % end 151 | Time=Time+1; 152 | end 153 | end 154 | 155 | %% 156 | function X=initialization(SearchAgents_no,dim,ub,lb) 157 | 158 | Boundary_no= size(ub,2); % numnber of boundaries 159 | 160 | % If the boundaries of all variables are equal and user enter a signle 161 | % number for both ub and lb 162 | if Boundary_no==1 163 | X=rand(SearchAgents_no,dim).*(ub-lb)+lb; 164 | end 165 | 166 | % If each variable has a different lb and ub 167 | if Boundary_no>1 168 | for i=1:dim 169 | ub_i=ub(i); 170 | lb_i=lb(i); 171 | X(:,i)=rand(SearchAgents_no,1).*(ub_i-lb_i)+lb_i; 172 | end 173 | end 174 | end 175 | %% 176 | function choice = RouletteWheelSelection(weights) 177 | accumulation = cumsum(weights); 178 | p = rand() * accumulation(end); 179 | chosen_index = -1; 180 | for index = 1 : length(accumulation) 181 | if (accumulation(index) > p) 182 | chosen_index = index; 183 | break; 184 | end 185 | end 186 | choice = chosen_index; 187 | end -------------------------------------------------------------------------------- /Optimizers/Main2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VG-TechCenter/Optimizers/a6d3dd5ef762aaa7058fedd06963e36d2223194e/Optimizers/Main2.m -------------------------------------------------------------------------------- /Optimizers/NGO.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | %% 4 | % NGO. 5 | % Northern Goshawk Optimization: A New Swarm-Based Algorithm for Solving Optimization Problems 6 | % Mohammad Dehghani1, Pavel Trojovský1, and Stepan Hubálovský2 7 | % 1Department of Mathematics, Faculty of Science, University of Hradec Králové, 50003 Hradec Králové, Czech Republic 8 | % 2Department of Applied Cybernetics, Faculty of Science, University of Hradec Králové, 50003 Hradec Králové, Czech Republic 9 | 10 | % " Optimizer" 11 | %% 12 | function [Score,Best_pos,NGO_curve]=NGO(Search_Agents,Max_iterations,Lowerbound,Upperbound,dimensions,objective) 13 | tic 14 | 15 | % disp('PLEASE WAIT, The program is running.') 16 | 17 | Lowerbound=ones(1,dimensions).*(Lowerbound); % Lower limit for variables 18 | Upperbound=ones(1,dimensions).*(Upperbound); % Upper limit for variables 19 | 20 | 21 | X=[]; 22 | X_new=[]; 23 | fit=[]; 24 | fit_new=[]; 25 | NGO_curve=zeros(1,Max_iterations); 26 | 27 | 28 | 29 | %% 30 | for i=1:dimensions 31 | X(:,i) = Lowerbound(i)+rand(Search_Agents,1).*(Upperbound(i) -Lowerbound(i)); % Initial population 32 | end 33 | for i =1:Search_Agents 34 | L=X(i,:); 35 | fit(i)=objective(L); % Fitness evaluation (Explained at the top of the page. ) 36 | end 37 | 38 | 39 | for t=1:Max_iterations % algorithm iteration 40 | 41 | %% update: BEST proposed solution 42 | [best , blocation]=min(fit); 43 | 44 | if t==1 45 | xbest=X(blocation,:); % Optimal location 46 | fbest=best; % The optimization objective function 47 | elseif best F_P 63 | X_new(i,:)=X(i,:)+rand(1,dimensions) .* (P-I.*X(i,:)); % Eq. (4) 64 | else 65 | X_new(i,:)=X(i,:)+rand(1,dimensions) .* (X(i,:)-P); % Eq. (4) 66 | end 67 | X_new(i,:) = max(X_new(i,:),Lowerbound);X_new(i,:) = min(X_new(i,:),Upperbound); 68 | 69 | % update position based on Eq (5) 70 | L=X_new(i,:); 71 | fit_new(i)=objective(L); 72 | if(fit_new(i) F_FOOD 48 | X_new=X(i,:)+ rand(1,1).*(X_FOOD-I.* X(i,:)); %Eq(4) 49 | else 50 | X_new=X(i,:)+ rand(1,1).*(X(i,:)-1.*X_FOOD); %Eq(4) 51 | end 52 | X_new= max(X_new,lowerbound);X_new = min(X_new,upperbound); 53 | 54 | % Updating X_i using (5) 55 | f_new = fitness(X_new); 56 | if f_new <= fit (i) 57 | X(i,:) = X_new; 58 | fit (i)=f_new; 59 | end 60 | %% END PHASE 1: Moving towards prey (exploration phase) 61 | 62 | %% PHASE 2: Winging on the water surface (exploitation phase) 63 | X_new=X(i,:)+0.2*(1-t/Max_iterations).*(2*rand(1,dimension)-1).*X(i,:);% Eq(6) 64 | X_new= max(X_new,lowerbound);X_new = min(X_new,upperbound); 65 | 66 | % Updating X_i using (7) 67 | f_new = fitness(X_new); 68 | if f_new <= fit (i) 69 | X(i,:) = X_new; 70 | fit (i)=f_new; 71 | end 72 | %% END PHASE 2: Winging on the water surface (exploitation phase) 73 | end 74 | 75 | best_so_far(t)=fbest; 76 | average(t) = mean (fit); 77 | 78 | end 79 | Best_score=fbest; 80 | Best_pos=Xbest; 81 | POA_curve=best_so_far; 82 | end 83 | %% 84 | 85 | -------------------------------------------------------------------------------- /Optimizers/PSO.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VG-TechCenter/Optimizers/a6d3dd5ef762aaa7058fedd06963e36d2223194e/Optimizers/PSO.m -------------------------------------------------------------------------------- /Optimizers/SA.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VG-TechCenter/Optimizers/a6d3dd5ef762aaa7058fedd06963e36d2223194e/Optimizers/SA.m -------------------------------------------------------------------------------- /Optimizers/SCA.m: -------------------------------------------------------------------------------- 1 | % Sine Cosine Algorithm (SCA) 2 | % 3 | % Source codes demo version 1.0 4 | % 5 | % Developed in MATLAB R2011b(7.13) 6 | % 7 | % Author and programmer: Seyedali Mirjalili 8 | % 9 | % e-Mail: ali.mirjalili@gmail.com 10 | % seyedali.mirjalili@griffithuni.edu.au 11 | % 12 | % Homepage: http://www.alimirjalili.com 13 | % 14 | % Main paper: 15 | % S. Mirjalili, SCA: A Sine Cosine Algorithm for solving optimization problems 16 | % Knowledge-Based Systems, DOI: http://dx.doi.org/10.1016/j.knosys.2015.12.022 17 | %_______________________________________________________________________________________________ 18 | % You can simply define your cost function in a seperate file and load its handle to fobj 19 | % The initial parameters that you need are: 20 | %__________________________________________ 21 | % fobj = @YourCostFunction 22 | % dim = number of your variables 23 | % Max_iteration = maximum number of iterations 24 | % SearchAgents_no = number of search agents 25 | % lb=[lb1,lb2,...,lbn] where lbn is the lower bound of variable n 26 | % ub=[ub1,ub2,...,ubn] where ubn is the upper bound of variable n 27 | % If all the variables have equal lower bound you can just 28 | % define lb and ub as two single numbers 29 | 30 | % To run SCA: [Best_score,Best_pos,cg_curve]=SCA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj) 31 | %______________________________________________________________________________________________ 32 | 33 | 34 | function [Destination_fitness,Destination_position,Convergence_curve]=SCA(N,Max_iteration,lb,ub,dim,fobj) 35 | 36 | % display('SCA is optimizing your problem'); 37 | 38 | %Initialize the set of random solutions 39 | X=initialization(N,dim,ub,lb); 40 | 41 | Destination_position=zeros(1,dim); 42 | Destination_fitness=inf; 43 | 44 | Convergence_curve=zeros(1,Max_iteration); 45 | Objective_values = zeros(1,size(X,1)); 46 | 47 | % Calculate the fitness of the first set and find the best one 48 | for i=1:size(X,1) 49 | Objective_values(1,i)=fobj(X(i,:)); 50 | if i==1 51 | Destination_position=X(i,:); 52 | Destination_fitness=Objective_values(1,i); 53 | elseif Objective_values(1,i)ub; 95 | Flag4lb=X(i,:)1 132 | for i=1:dim 133 | ub_i=ub(i); 134 | lb_i=lb(i); 135 | X(:,i)=rand(SearchAgents_no,1).*(ub_i-lb_i)+lb_i; 136 | end 137 | end 138 | end -------------------------------------------------------------------------------- /Optimizers/SO.m: -------------------------------------------------------------------------------- 1 | %___________________________________________________________________% 2 | % Snake Optimizer (SO) source codes version 1.0 % 3 | % % 4 | % Developed in MATLAB R2021b % 5 | % % 6 | % Author and programmer: Fatma Hashim & Abdelazim G. Hussien % 7 | % % 8 | % e-Mail: fatma_hashim@h-eng.helwan.edu.eg % 9 | % abdelazim.hussien@liu.se % 10 | % aga08@fayoum.edu.eg % 11 | % % 12 | % % 13 | % Main paper: Fatma Hashim & Abdelazim G. Hussien % 14 | % Knowledge-based Systems % 15 | % in press, % 16 | % DOI: 10.1016/j.knosys.2022.108320 % 17 | % % 18 | %___________________________________________________________________% 19 | function [fval,Xfood,gbest_t] = SO(N,T, lb,ub,dim,fobj) 20 | %initial 21 | vec_flag=[1,-1]; 22 | Threshold=0.25; 23 | Thresold2= 0.6; 24 | C1=0.5; 25 | C2=.05; 26 | C3=2; 27 | if length(lb)<2 28 | X=lb+rand(N,dim)*(ub-lb); 29 | else 30 | X=repmat(lb,N,1)+rand(N,dim).*repmat((ub-lb),N,1); 31 | end 32 | for i=1:N 33 | fitness(i)=fobj(X(i,:)); 34 | end 35 | [GYbest, gbest] = min(fitness); 36 | Xfood = X(gbest,:); 37 | %Diving the swarm into two equal groups males and females 38 | Nm=round(N/2);%eq.(2&3) 39 | Nf=N-Nm; 40 | Xm=X(1:Nm,:); 41 | Xf=X(Nm+1:N,:); 42 | fitness_m=fitness(1:Nm); 43 | fitness_f=fitness(Nm+1:N); 44 | [fitnessBest_m, gbest1] = min(fitness_m); 45 | Xbest_m = Xm(gbest1,:); 46 | [fitnessBest_f, gbest2] = min(fitness_f); 47 | Xbest_f = Xf(gbest2,:); 48 | for t = 1:T 49 | Temp=exp(-((t)/T)); %eq.(4) 50 | Q=C1*exp(((t-T)/(T)));%eq.(5) 51 | if Q>1 Q=1; end 52 | % Exploration Phase (no Food) 53 | if QThresold2 %hot 76 | for i=1:Nm 77 | flag_index = floor(2*rand()+1); 78 | Flag=vec_flag(flag_index); 79 | for j=1:1:dim 80 | Xnewm(i,j)=Xfood(j)+C3*Flag*Temp*rand*(Xfood(j)-Xm(i,j));%eq.(10) 81 | end 82 | end 83 | for i=1:Nf 84 | flag_index = floor(2*rand()+1); 85 | Flag=vec_flag(flag_index); 86 | for j=1:1:dim 87 | Xnewf(i,j)=Xfood(j)+Flag*C3*Temp*rand*(Xfood(j)-Xf(i,j));%eq.(10) 88 | end 89 | end 90 | else %cold 91 | if rand>0.6 %fight 92 | for i=1:Nm 93 | for j=1:1:dim 94 | FM=exp(-(fitnessBest_f)/(fitness_m(i)+eps));%eq.(13) 95 | Xnewm(i,j)=Xm(i,j) +C3*FM*rand*(Q*Xbest_f(j)-Xm(i,j));%eq.(11) 96 | 97 | end 98 | end 99 | for i=1:Nf 100 | for j=1:1:dim 101 | FF=exp(-(fitnessBest_m)/(fitness_f(i)+eps));%eq.(14) 102 | Xnewf(i,j)=Xf(i,j)+C3*FF*rand*(Q*Xbest_m(j)-Xf(i,j));%eq.(12) 103 | end 104 | end 105 | else%mating 106 | for i=1:Nm 107 | for j=1:1:dim 108 | Mm=exp(-fitness_f(i)/(fitness_m(i)+eps));%eq.(17) 109 | Xnewm(i,j)=Xm(i,j) +C3*rand*Mm*(Q*Xf(i,j)-Xm(i,j));%eq.(15 110 | end 111 | end 112 | for i=1:Nf 113 | for j=1:1:dim 114 | Mf=exp(-fitness_m(i)/(fitness_f(i)+eps));%eq.(18) 115 | Xnewf(i,j)=Xf(i,j) +C3*rand*Mf*(Q*Xm(i,j)-Xf(i,j));%eq.(16) 116 | end 117 | end 118 | flag_index = floor(2*rand()+1); 119 | egg=vec_flag(flag_index); 120 | if egg==1; 121 | [GYworst, gworst] = max(fitness_m); 122 | Xnewm(gworst,:)=lb+rand*(ub-lb);%eq.(19) 123 | [GYworst, gworst] = max(fitness_f); 124 | Xnewf(gworst,:)=lb+rand*(ub-lb);%eq.(20) 125 | end 126 | end 127 | end 128 | end 129 | for j=1:Nm 130 | Flag4ub=Xnewm(j,:)>ub; 131 | Flag4lb=Xnewm(j,:)ub; 144 | Flag4lb=Xnewf(j,:)N/2 && iub';Tm=SalpPositions(i,:)1 120 | for i=1:dim 121 | ub_i=ub(i); 122 | lb_i=lb(i); 123 | X(:,i)=rand(SearchAgents_no,1).*(ub_i-lb_i)+lb_i; 124 | end 125 | end 126 | end 127 | -------------------------------------------------------------------------------- /Optimizers/SSA.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | function [fMin , bestX,Convergence_curve ] = SSA(pop, M,c,d,dim,fobj ) 4 | 5 | P_percent = 0.2; % The population size of producers accounts for "P_percent" percent of the total population size 6 | %生产者占所有种群的0.2 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | pNum = round( pop * P_percent ); % The population size of the producers 9 | %生产者数量取整 10 | 11 | lb= c.*ones( 1,dim ); % Lower limit/bounds/ a vector 约束上限 12 | ub= d.*ones( 1,dim ); % Upper limit/bounds/ a vector 约束下限 13 | %Initialization 14 | for i = 1 : pop 15 | x( i, : ) = lb + (ub - lb) .* rand( 1, dim ); %随机初始化n个种群 16 | fit( i ) = fobj( x( i, : ) ) ; %计算所有群体的适应情况,如果求最小值的,越小代表适应度越好 17 | end 18 | % 以下找到最小值对应的麻雀群 19 | pFit = fit; 20 | pX = x; % The individual's best position corresponding to the pFit 21 | [ fMin, bestI ] = min( fit ); % fMin denotes the global optimum fitness value 22 | bestX = x( bestI, : ); % bestX denotes the global optimum position corresponding to fMin 23 | 24 | % Start updating the solutions. 25 | for t = 1 : M 26 | 27 | [ ans, sortIndex ] = sort( pFit );% Sort. 28 | 29 | [fmax,B]=max( pFit ); 30 | worse= x(B,:); %找到最差的个体 31 | 32 | r2=rand(1); %产生随机数 感觉没有啥科学依据,就是随机数 33 | %大概意思就是在0.8概率内原来种群乘一个小于1的数,种群整体数值缩小了 34 | %大概意思就是在0.2概率内原来种群乘一个小于1的数,种群整体数值+1 35 | %变化后种群的数值还是要限制在约束里面 36 | %对前pNum适应度最好的进行变化 ,即生产者进行变化,可见生产者是挑最好的 37 | if(r2<0.8) 38 | for i = 1 : pNum % Equation (3) 39 | r1=rand(1); 40 | x( sortIndex( i ), : ) = pX( sortIndex( i ), : )*exp(-(i)/(r1*M)); %将种群按适应度排序后更新 41 | x( sortIndex( i ), : ) = Bounds( x( sortIndex( i ), : ), lb, ub ); %将种群限制在约束范围内 42 | fit( sortIndex( i ) ) = fobj( x( sortIndex( i ), : ) ); 43 | end 44 | else 45 | for i = 1 : pNum 46 | x( sortIndex( i ), : ) = pX( sortIndex( i ), : )+randn(1)*ones(1,dim); 47 | x( sortIndex( i ), : ) = Bounds( x( sortIndex( i ), : ), lb, ub ); 48 | fit( sortIndex( i ) ) = fobj( x( sortIndex( i ), : ) ); 49 | end 50 | end 51 | %把经过变化后最好的种群记录下来 52 | [ fMMin, bestII ] = min( fit ); 53 | bestXX = x( bestII, : ); 54 | 55 | %下面是乞讨者 56 | for i = ( pNum + 1 ) : pop % Equation (4) 57 | A=floor(rand(1,dim)*2)*2-1; %产生1和-1的随机数 58 | 59 | if( i>(pop/2)) 60 | %如果i>种群的一半,代表遍历到适应度靠后的一段,代表这些序列的种群可能在挨饿 61 | x( sortIndex(i ), : )=randn(1)*exp((worse-pX( sortIndex( i ), : ))/(i)^2); 62 | %适应度不好的,即靠后的麻雀乘了一个大于1的数,向外拓展 63 | else 64 | x( sortIndex( i ), : )=bestXX+(abs(( pX( sortIndex( i ), : )-bestXX)))*(A'*(A*A')^(-1))*ones(1,dim); 65 | %这是适应度出去介于生产者之后,又在种群的前半段的,去竞争生产者的食物,在前面最好种群的基础上 66 | %再进行变化一次,在原来的基础上减一些值或者加一些值 67 | end 68 | x( sortIndex( i ), : ) = Bounds( x( sortIndex( i ), : ), lb, ub ); %更新后种群的限制在变量范围 69 | fit( sortIndex( i ) ) = fobj( x( sortIndex( i ), : ) ); %更新过后重新计算适应度 70 | end 71 | %在全部种群中找可以意识到危险的麻雀 72 | c=randperm(numel(sortIndex)); 73 | b=sortIndex(c(1:20)); 74 | for j = 1 : length(b) % Equation (5) 75 | if( pFit( sortIndex( b(j) ) )>(fMin) ) 76 | %如果适应度比最开始最小适应度差的话,就在原来的最好种群上增长一部分值 77 | x( sortIndex( b(j) ), : )=bestX+(randn(1,dim)).*(abs(( pX( sortIndex( b(j) ), : ) -bestX))); 78 | 79 | else 80 | %如果适应度达到开始最小的适应度值,就在原来的最好种群上随机增长或减小一部分 81 | x( sortIndex( b(j) ), : ) =pX( sortIndex( b(j) ), : )+(2*rand(1)-1)*(abs(pX( sortIndex( b(j) ), : )-worse))/ ( pFit( sortIndex( b(j) ) )-fmax+1e-50); 82 | 83 | end 84 | x( sortIndex(b(j) ), : ) = Bounds( x( sortIndex(b(j) ), : ), lb, ub ); 85 | 86 | fit( sortIndex( b(j) ) ) = fobj( x( sortIndex( b(j) ), : ) ); 87 | end 88 | for i = 1 : pop 89 | %如果哪个种群适应度好了,就把变化的替换掉原来的种群 90 | if ( fit( i ) < pFit( i ) ) 91 | pFit( i ) = fit( i ); 92 | pX( i, : ) = x( i, : ); 93 | end 94 | 95 | if( pFit( i ) < fMin ) %最优值以及最优值位置看是否变化 96 | fMin= pFit( i ); 97 | bestX = pX( i, : ); 98 | 99 | 100 | end 101 | end 102 | 103 | Convergence_curve(t)=fMin; 104 | 105 | end 106 | 107 | 108 | % Application of simple limits/bounds 109 | function s = Bounds( s, Lb, Ub) 110 | % Apply the lower bound vector 111 | temp = s; 112 | I = temp < Lb; 113 | temp(I) = Lb(I); 114 | 115 | % Apply the upper bound vector 116 | J = temp > Ub; 117 | temp(J) = Ub(J); 118 | % Update this new move 119 | s = temp; 120 | 121 | %--------------------------------------------------------------------------------------------------------------------------- 122 | -------------------------------------------------------------------------------- /Optimizers/WOA.m: -------------------------------------------------------------------------------- 1 | %_________________________________________________________________________% 2 | % Whale Optimization Algorithm (WOA) source codes demo 1.0 % 3 | % % 4 | % Developed in MATLAB R2011b(7.13) % 5 | % % 6 | % Author and programmer: Seyedali Mirjalili % 7 | % % 8 | % e-Mail: ali.mirjalili@gmail.com % 9 | % seyedali.mirjalili@griffithuni.edu.au % 10 | % % 11 | % Homepage: http://www.alimirjalili.com % 12 | % % 13 | % Main paper: S. Mirjalili, A. Lewis % 14 | % The Whale Optimization Algorithm, % 15 | % Advances in Engineering Software , in press, % 16 | % DOI: http://dx.doi.org/10.1016/j.advengsoft.2016.01.008 % 17 | % % 18 | %_________________________________________________________________________% 19 | 20 | % The Whale Optimization Algorithm 21 | function [Leader_score,Leader_pos,Convergence_curve]=WOA(SearchAgents_no,Max_iter,lb,ub,dim,fobj) 22 | 23 | % initialize position vector and score for the leader 24 | Leader_pos=zeros(1,dim); 25 | Leader_score=inf; %change this to -inf for maximization problems 26 | 27 | 28 | %Initialize the positions of search agents 29 | Positions=initialization(SearchAgents_no,dim,ub,lb); 30 | 31 | Convergence_curve=zeros(1,Max_iter); 32 | 33 | t=0;% Loop counter 34 | 35 | % Main loop 36 | while tub; 41 | Flag4lb=Positions(i,:) for maximization problem 49 | Leader_score=fitness; % Update alpha 50 | Leader_pos=Positions(i,:); 51 | end 52 | 53 | end 54 | 55 | a=2-t*((2)/Max_iter); % a decreases linearly fron 2 to 0 in Eq. (2.3) 56 | 57 | % a2 linearly dicreases from -1 to -2 to calculate t in Eq. (3.12) 58 | a2=-1+t*((-1)/Max_iter); 59 | 60 | % Update the Position of search agents 61 | for i=1:size(Positions,1) 62 | r1=rand(); % r1 is a random number in [0,1] 63 | r2=rand(); % r2 is a random number in [0,1] 64 | 65 | A=2*a*r1-a; % Eq. (2.3) in the paper 66 | C=2*r2; % Eq. (2.4) in the paper 67 | 68 | 69 | b=1; % parameters in Eq. (2.5) 70 | l=(a2-1)*rand+1; % parameters in Eq. (2.5) 71 | 72 | p = rand(); % p in Eq. (2.6) 73 | 74 | for j=1:size(Positions,2) 75 | 76 | if p<0.5 77 | if abs(A)>=1 78 | rand_leader_index = floor(SearchAgents_no*rand()+1); 79 | X_rand = Positions(rand_leader_index, :); 80 | D_X_rand=abs(C*X_rand(j)-Positions(i,j)); % Eq. (2.7) 81 | Positions(i,j)=X_rand(j)-A*D_X_rand; % Eq. (2.8) 82 | 83 | elseif abs(A)<1 84 | D_Leader=abs(C*Leader_pos(j)-Positions(i,j)); % Eq. (2.1) 85 | Positions(i,j)=Leader_pos(j)-A*D_Leader; % Eq. (2.2) 86 | end 87 | 88 | elseif p>=0.5 89 | 90 | distance2Leader=abs(Leader_pos(j)-Positions(i,j)); 91 | % Eq. (2.5) 92 | Positions(i,j)=distance2Leader*exp(b.*l).*cos(l.*2*pi)+Leader_pos(j); 93 | 94 | end 95 | 96 | end 97 | end 98 | t=t+1; 99 | Convergence_curve(t)=Leader_score; 100 | [t Leader_score]; 101 | end 102 | 103 | function Positions=initialization(SearchAgents_no,dim,ub,lb) 104 | 105 | Boundary_no= size(ub,2); % numnber of boundaries 106 | 107 | % If the boundaries of all variables are equal and user enter a signle 108 | % number for both ub and lb 109 | if Boundary_no==1 110 | Positions=rand(SearchAgents_no,dim).*(ub-lb)+lb; 111 | end 112 | 113 | % If each variable has a different lb and ub 114 | if Boundary_no>1 115 | for i=1:dim 116 | ub_i=ub(i); 117 | lb_i=lb(i); 118 | Positions(:,i)=rand(SearchAgents_no,1).*(ub_i-lb_i)+lb_i; 119 | end 120 | end 121 | 122 | -------------------------------------------------------------------------------- /Optimizers/WSO.m: -------------------------------------------------------------------------------- 1 | 2 | %% White Shark Optimizer (WSO) source codes version 1.0 3 | % 4 | % Developed in MATLAB R2018a 5 | % 6 | % Programmer: Malik Braik 7 | % 8 | % e-Mail: mbraik@bau.edu.jo 9 | % 10 | 11 | % Main paper: 12 | % Malik Braik, Abdelaziz Hammouri, Jaffar Atwan, Mohammed Azmi Al-Betar, Mohammed A.Awadallah 13 | 14 | % White Shark Optimizer: A novel bio-inspired meta-heuristic algorithm for global optimization problems 15 | % Knowledge-Based Systems 16 | % DOI: https://doi.org/10.1016/j.knosys.2022.108457 17 | 18 | function [fmin0,gbest,ccurve]=WSO(whiteSharks,itemax,lb,ub,dim,fobj) 19 | 20 | %% Convergence curve 21 | ccurve=zeros(1,itemax); 22 | 23 | %%% Show the convergence curve 24 | % figure (1); 25 | % set(gcf,'color','w'); 26 | % hold on 27 | % xlabel('Iteration','interpreter','latex','FontName','Times','fontsize',10) 28 | % ylabel('fitness value','interpreter','latex','FontName','Times','fontsize',10); 29 | % grid; 30 | 31 | %% Start the WSO Algorithm 32 | % Generation of initial solutions 33 | WSO_Positions=initialization(whiteSharks,dim,ub,lb);% Initial population 34 | 35 | % initial velocity 36 | v=0.0*WSO_Positions; 37 | 38 | %% Evaluate the fitness of the initial population 39 | fit=zeros(whiteSharks,1); 40 | 41 | for i=1:whiteSharks 42 | fit(i,1)=fobj(WSO_Positions(i,:)); 43 | end 44 | 45 | %% Initalize the parameters of WSO 46 | fitness=fit; % Initial fitness of the random positions of the WSO 47 | 48 | [fmin0,index]=min(fit); 49 | 50 | wbest = WSO_Positions; % Best position initialization 51 | gbest = WSO_Positions(index,:); % initial global position 52 | 53 | %% WSO Parameters 54 | fmax=0.75; % Maximum frequency of the wavy motion 55 | fmin=0.07; % Minimum frequency of the wavy motion 56 | tau=4.11; 57 | 58 | mu=2/abs(2-tau-sqrt(tau^2-4*tau)); 59 | 60 | pmin=0.5; 61 | pmax=1.5; 62 | a0=6.250; 63 | a1=100; 64 | a2=0.0005; 65 | %% Start the iterative process of WSO 66 | for ite=1:itemax 67 | 68 | mv=1/(a0+exp((itemax/2.0-ite)/a1)); 69 | s_s=abs((1-exp(-a2*ite/itemax))) ; 70 | 71 | p1=pmax+(pmax-pmin)*exp(-(4*ite/itemax)^2); 72 | p2=pmin+(pmax-pmin)*exp(-(4*ite/itemax)^2); 73 | 74 | %% Update the speed of the white sharks in water 75 | nu=floor((whiteSharks).*rand(1,whiteSharks))+1; 76 | 77 | for i=1:size(WSO_Positions,1) 78 | rmin=1; rmax=3.0; 79 | rr=rmin+rand()*(rmax-rmin); 80 | wr=abs(((2*rand()) - (1*rand()+rand()))/rr); 81 | v(i,:)= mu*v(i,:) + wr *(wbest(nu(i),:)-WSO_Positions(i,:)); 82 | %% or 83 | 84 | % v(i,:)= mu*(v(i,:)+ p1*(gbest-WSO_Positions(i,:))*rand+.... 85 | % + p2*(wbest(nu(i),:)-WSO_Positions(i,:))*rand); 86 | end 87 | 88 | %% Update the white shark position 89 | for i=1:size(WSO_Positions,1) 90 | 91 | f =fmin+(fmax-fmin)/(fmax+fmin); 92 | 93 | a=sign(WSO_Positions(i,:)-ub)>0; 94 | b=sign(WSO_Positions(i,:)-lb)<0; 95 | 96 | wo=xor(a,b); 97 | 98 | % locate the prey based on its sensing (sound, waves) 99 | if rand=lb & WSO_Positions(i,:)<=ub% 130 | % Find the fitness 131 | fit(i)=fobj(WSO_Positions(i,:)); 132 | 133 | % Evaluate the fitness 134 | if fit(i)1 179 | for i=1:dim 180 | ubi=ub_(i); 181 | lbi=lb_(i); 182 | pos(:,i)=rand(whiteSharks,1).*(ubi-lbi)+lbi; 183 | end 184 | end 185 | end -------------------------------------------------------------------------------- /Optimizers/color_list.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VG-TechCenter/Optimizers/a6d3dd5ef762aaa7058fedd06963e36d2223194e/Optimizers/color_list.mat -------------------------------------------------------------------------------- /Optimizers/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VG-TechCenter/Optimizers/a6d3dd5ef762aaa7058fedd06963e36d2223194e/Optimizers/main.m -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Optimizers 2 | 麻雀,鲸鱼,正余弦,北方苍鹰,遗传,粒子群,灰狼,蜻蜓,蝗虫,多元宇宙等优化算法.
3 | Optimizers, Optimization algorithms such as sparrow, whale, sine and cosine, northern goshawk, genetic, particle swarm, gray wolf, dragonfly, locust, multiverse, etc.
4 | 17 | 18 |

19 | Fig.1. Test function
20 | Fig.1. Test function
21 | Fig.2. Convergence speed
22 | Fig.2. Convergence speed
23 | Fig.3. Object value
24 | Fig.3. Object value
25 | Fig.4. Consumed Time
26 | Fig.4. Consumed Time
27 |

28 | -------------------------------------------------------------------------------- /Results/1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VG-TechCenter/Optimizers/a6d3dd5ef762aaa7058fedd06963e36d2223194e/Results/1.bmp -------------------------------------------------------------------------------- /Results/2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VG-TechCenter/Optimizers/a6d3dd5ef762aaa7058fedd06963e36d2223194e/Results/2.bmp -------------------------------------------------------------------------------- /Results/3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VG-TechCenter/Optimizers/a6d3dd5ef762aaa7058fedd06963e36d2223194e/Results/3.bmp -------------------------------------------------------------------------------- /Results/4.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VG-TechCenter/Optimizers/a6d3dd5ef762aaa7058fedd06963e36d2223194e/Results/4.bmp --------------------------------------------------------------------------------