├── ACO.m ├── CHGSA.m ├── CPSOGSA.m ├── DE.m ├── GA.m ├── GSA.m ├── GWO.m ├── Gconstant.m ├── Geinitialization.m ├── Gfield.m ├── Main.m ├── ReadMe ├── RouletteWheelSelection.m ├── SCA.m ├── SSA.m ├── Scatter_Plot.m ├── bbo.m ├── benchmark_functions.m ├── benchmark_functions_details.m ├── chaos.m ├── crossover_continious.m ├── elitism.m ├── evaluateF.m ├── initialization.m ├── initializationGWO.m ├── initializationSCA.m ├── initializationSSA.m ├── massCalculation.m ├── move.m ├── mutation_continious.m ├── pso.m ├── selection.m └── space_bound.m /ACO.m: -------------------------------------------------------------------------------- 1 | %The code has been taken from: 2 | % Copyright (c) 2015, Yarpiz (www.yarpiz.com) 3 | 4 | function [BestSolACO,BestAnt,BestCostACO] = ACO(Benchmark_Function_ID, N, Max_Iteration,Q,tau0,alpha,rho) 5 | [down,up,dim]=benchmark_functions_details(Benchmark_Function_ID); 6 | % %% ACO Parameters 7 | % MaxIt=500; % Maximum Number of Iterations 8 | % nAnt=50; % Number of Ants (Population Size) 9 | % Q=1; 10 | % tau0=10; % Initial Phromone 11 | % alpha=0.3; % Phromone Exponential Weight 12 | % rho=0.1; % Evaporation Rate 13 | %% Initialization 14 | tau=tau0*ones(dim,dim); 15 | % Empty Ant 16 | empty_ant.Tour=[]; 17 | empty_ant.Cost=[]; 18 | 19 | if size(up,1)>1 20 | for i=1:dim 21 | high=up(i);ll=down(i); 22 | end 23 | end 24 | % Ant Colony Matrix 25 | ant=repmat(empty_ant,N,1); 26 | for i=1:N 27 | % ant(i).tour=unifrnd(ll,high,dim); 28 | ant(i).tour=rand(1,N).*(high-ll)+ll; 29 | ant(i).Cost=benchmark_functions(ant(i).tour,Benchmark_Function_ID,dim); 30 | 31 | % if ant(i).Cost : maximization 67 | Fbest=best;Lbest=X(:,best_X); 68 | end 69 | 70 | BestChart=[BestChart Fbest]; 71 | MeanChart=[MeanChart mean(fitness)]; 72 | 73 | %Calculation of M. eq.14-20 74 | [M]=massCalculation(fitness,min_flag); 75 | 76 | %Calculation of Gravitational constant. eq.13. 77 | G=Gconstant(iteration,Max_Iteration); 78 | %G=chaos(3,iteration,max_it,10); 79 | switch chaosIndex 80 | case 1 81 | G=Gconstant(iteration,Max_Iteration); 82 | case 2 83 | G=G+chaos(chaosIndex-1,iteration,Max_Iteration,chValue); 84 | case 3 85 | G=G+chaos(chaosIndex-1,iteration,Max_Iteration,chValue); 86 | case 4 87 | G=G+chaos(chaosIndex-1,iteration,Max_Iteration,chValue); 88 | case 5 89 | G=G+chaos(chaosIndex-1,iteration,Max_Iteration,chValue); 90 | case 6 91 | G=G+chaos(chaosIndex-1,iteration,Max_Iteration,chValue); 92 | case 7 93 | G=G+chaos(chaosIndex-1,iteration,Max_Iteration,chValue); 94 | case 8 95 | G=G+chaos(chaosIndex-1,iteration,Max_Iteration,chValue); 96 | case 9 97 | G=G+chaos(chaosIndex-1,iteration,Max_Iteration,chValue); 98 | case 10 99 | G=G+chaos(chaosIndex-1,iteration,Max_Iteration,chValue); 100 | case 11 101 | G=G+chaos(chaosIndex-1,iteration,Max_Iteration,chValue); 102 | end 103 | G_History(iteration)=G; 104 | test_G(iteration)=G; 105 | if iteration==99 106 | alisop=0; 107 | end 108 | %Calculation of accelaration in gravitational field. eq.7-10,21. 109 | a=Gfield(M,X,G,Rnorm,Rpower,ElitistCheck,iteration,Max_Iteration); 110 | 111 | %Agent movement. eq.11-12 112 | [X,V]=move(X,a,V); 113 | 114 | 115 | end %iteration 116 | 117 | -------------------------------------------------------------------------------- /CPSOGSA.m: -------------------------------------------------------------------------------- 1 | % 2 | 3 | 4 | % Chaotic GSA for Engineering Design Problems 5 | % 6 | % E-Mail: sajad.win8@gmail.com 7 | % 8 | % Homepage: https://github.com/SajadAHMAD1. 9 | % 10 | % Main paper: R.A., Rather, P.S., Bala, 11 | % Department of Computer Science and Engineering 12 | % School of Engineering and Technology 13 | % Pondicherry University- 605014, India 14 | % 15 | 16 | % Programmer: Sajad Ahmad Rather 17 | % Developed in MATLAB R2013a 18 | 19 | 20 | 21 | 22 | %-------------------------------------------% 23 | % Evaluate the population % 24 | %-------------------------------------------% %--% 25 | %%% Variables %%% 26 | 27 | %current_position: Position of particles 28 | %velocity: Velocity 29 | %force: The gravitational force between the particles 30 | %acceleration: Acceleration 31 | %mass: Mass 32 | %dim: Dimension of test functions 33 | %n: Number of particles 34 | %G0 Gravitational constant 35 | %low: The lower bound of the search space 36 | %up: The higher bound of the search space 37 | 38 | 39 | function [gBestScore,gBest,GlobalBestCost]=CPSOGSA(Benchmark_Function_ID,n,iteration) 40 | 41 | [low,up,dim]=benchmark_functions_details(Benchmark_Function_ID);%define the boundary and dimension of the benchmark function 42 | %%%% 43 | % % Constriction Coefficients 44 | phi1=2.05; 45 | phi2=2.05; 46 | phi=phi1+phi2; 47 | chi=2/(phi-2+sqrt(phi^2-4*phi)); 48 | w=chi; % Inertia Weight 49 | wdamp=1; % Inertia Weight Damping Ratio 50 | C1=chi*phi1; % Personal Learning Coefficient 51 | C2=chi*phi2; % Global Learning Coefficient 52 | 53 | %%%% 54 | current_fitness =zeros(n,1); 55 | gBest=zeros(1,dim); 56 | gBestScore=inf; 57 | % w=1; 58 | % wdamp=0.99; 59 | % VelMax=0.1*(up-low); 60 | % VelMin=-up; 61 | 62 | for i=1:n 63 | pBestScore(i)=inf; 64 | end 65 | pBest=zeros(n,dim); 66 | 67 | G0=1; % gravitational constant 68 | if size(up,1)==1 69 | current_position=rand(dim,n).*(up-low)+low; 70 | end 71 | if size(up,1)>1 72 | for i=1:dim 73 | high=up(i);ll=low(i); 74 | current_position(i,:)=rand(1,n).*(high-ll)+ll; 75 | VelMax=0.1*(high-ll); 76 | VelMin=-high; 77 | end 78 | end 79 | % current_position = rand(n,dim).*(up-low)+low; %initial positions in the problem's boundary 80 | velocity = .3*randn(dim,n) ; 81 | acceleration=zeros(dim,n); 82 | mass(n)=0; 83 | force=zeros(dim,n); 84 | 85 | %C1=0.5; %C1 in Equation (9) 86 | % C2=1.5; %C2 in Equation (9) 87 | 88 | %%main loop 89 | iter = 0 ; % Iterations’ counter 90 | while ( iter < iteration ) 91 | 92 | G=G0*exp(-23*iter/iteration); %Equation (4) 93 | iter = iter + 1; 94 | iter; 95 | force=zeros(dim,n); 96 | mass(n)=0; 97 | acceleration=zeros(dim,n); 98 | [dim,n]=size(current_position); 99 | for i = 1:n 100 | 101 | % %///Bound the search Space/// 102 | Tp=current_position(:,i)>up; 103 | Tm=current_position(:,i)up;Tm=X(i,:)up;Tm=current_position(i,:)fitness) 122 | pBestScore(i)=fitness; 123 | pBest(i,:)=current_fitness(i,:); 124 | end 125 | if(gBestScore>fitness) 126 | gBestScore=fitness; 127 | gBest=current_position(:,i)'; 128 | end 129 | 130 | end 131 | 132 | best=min(current_fitness); 133 | % AVE=mean(current_fitness); 134 | % STD=std(current_fitness); 135 | worst=max(current_fitness); 136 | 137 | GlobalBestCost(iter)=gBestScore; 138 | GlobalBestCost(iter); 139 | best; 140 | 141 | % AverageCost(iter)=gBestScore; 142 | % AverageCost(iter); 143 | % AVE; 144 | % 145 | % StandardDCost(iter)=gBestScore; 146 | % StandardDCost(iter); 147 | % STD; 148 | 149 | 150 | for pp=1:n 151 | if current_fitness(pp)==best 152 | break; 153 | end 154 | 155 | end 156 | 157 | bestIndex=pp; 158 | 159 | for pp=1:dim 160 | best_fit_position(iter,1)=best; 161 | best_fit_position(iter,pp+1)=current_position(pp,bestIndex); 162 | end 163 | 164 | % disp(['Iteration ' num2str(iter) ': GlobalBestCost = ' num2str(GlobalBestCost)]); 165 | %-------------------% 166 | % Calculate Mass % 167 | %-------------------% 168 | for i=1:n 169 | mass(i)=(current_fitness(i)-0.99*worst)/(best-worst); 170 | end 171 | 172 | for i=1:n 173 | mass(i)=mass(i)*5/sum(mass); 174 | 175 | end 176 | 177 | %-------------------% 178 | % Force update % 179 | %-------------------% 180 | 181 | for i=1:n 182 | for j=1:dim 183 | for k=1:n 184 | if(current_position(j,k)~=current_position(j,i)) 185 | % Equation (3) 186 | force(j,i)=force(j,i)+ rand()*G*mass(k)*mass(i)*(current_position(j,k)-current_position(j,i))/abs(current_position(j,k)-current_position(j,i)); 187 | 188 | end 189 | end 190 | end 191 | end 192 | %------------------------------------% 193 | % Accelations $ Velocities UPDATE % 194 | %------------------------------------% 195 | 196 | for i=1:n 197 | for j=1:dim 198 | if(mass(i)~=0) 199 | %Equation (6) 200 | acceleration(j,i)=force(j,i)/mass(i); 201 | end 202 | end 203 | end 204 | 205 | for i=1:n 206 | for j=1:dim 207 | %Equation(9) 208 | velocity(j,i)=w*rand()*velocity(j,i)+C1*rand()*acceleration(j,i) + C2*rand()*(gBest(j)-current_position(j,i)); 209 | % size(velocity) 210 | % Apply Velocity Limits 211 | % velocity(j,i) = max(velocity(j,i),VelMin); 212 | % velocity(j,i) = min(velocity(j,i),VelMax); 213 | end 214 | 215 | 216 | end 217 | %--------------------------% 218 | % positions UPDATE % 219 | %--------------------------% 220 | 221 | %Equation (10) 222 | current_position = current_position + velocity ; 223 | 224 | % Velocity Mirror Effect 225 | % IsOutside=(current_positionhigh); 226 | % velocity(IsOutside)=-velocity(IsOutside); 227 | % % Apply Position Limits 228 | % current_position = max(current_position,ll); 229 | % current_position = min(current_position,high); 230 | w=w*wdamp; 231 | % Show Iteration Information 232 | % disp(['Iteration ' num2str(iter) ': GlobalBestCost = ' num2str(GlobalBestCost)]); 233 | end 234 | end 235 | 236 | 237 | -------------------------------------------------------------------------------- /DE.m: -------------------------------------------------------------------------------- 1 | % The code has been taken from: 2 | % Project Code: YPEA107 3 | % Project Title: Implementation of Differential Evolution (DE) in MATLAB 4 | % Publisher: Yarpiz (www.yarpiz.com) 5 | % 6 | % Developer: S. Mostapha Kalami Heris (Member of Yarpiz Team) 7 | 8 | %% Problem Definition 9 | 10 | % CostFunction=@(x) Sphere(x); % Cost Function 11 | % 12 | % nVar=20; % Number of Decision Variables 13 | % 14 | % VarSize=[1 nVar]; % Decision Variables Matrix Size 15 | % 16 | % VarMin=-5; % Lower Bound of Decision Variables 17 | % VarMax= 5; % Upper Bound of Decision Variables 18 | 19 | %% DE Parameters 20 | 21 | % MaxIt=1000; % Maximum Number of Iterations 22 | 23 | % nPop=50; % Population Size 24 | 25 | % beta_min=0.2; % Lower Bound of Scaling Factor 26 | % beta_max=0.8; % Upper Bound of Scaling Factor 27 | % 28 | % pCR=0.2; % Crossover Probability 29 | function [BestSolDE,DBestSol,BestCostDE] = DE(Benchmark_Function_ID, N, Max_Iteration,beta_min,beta_max,pCR) 30 | 31 | [low,up,dim]=benchmark_functions_details(Benchmark_Function_ID);%define the boundary and dimension of the benchmark function 32 | 33 | % % pop(i).Position=unifrnd(low,up,dim); 34 | % if size(up,1)>1 35 | % for i=1:dim 36 | % high=up(i);ll=low(i); 37 | % pop(i).Position=rand(1,N).*(high-ll)+ll; 38 | % end 39 | % end 40 | %% Initialization 41 | 42 | empty_individual.Position=[]; 43 | empty_individual.Cost=[]; 44 | 45 | BestSolDE.Cost=inf; 46 | 47 | pop=repmat(empty_individual,N,1); 48 | if size(up,1)>1 49 | for i=1:dim 50 | high=up(i);ll=low(i); 51 | end 52 | end 53 | for i=1:N 54 | pop(i).Position=rand(1,dim).*(high-ll)+ll; 55 | pop(i).Cost=benchmark_functions(pop(i).Position,Benchmark_Function_ID,dim); 56 | 57 | % if pop(i).Costup'; 46 | Flag4down=Positions(i,:)Alpha_score && fitnessAlpha_score && fitness>Beta_score && fitnessup'; 95 | Flag4down=X(i,:)N/2 && iup'; 89 | Tm=SalpPositions(i,:)1 42 | for i=1:dim 43 | high=up(i);ll=down(i); 44 | sigma=0.02*(high-ll); 45 | end 46 | end 47 | % Empty Habitat 48 | habitat.Position=[]; 49 | habitat.Cost= []; 50 | % benchmark_functions(currentX,Benchmark_Function_ID,dim); 51 | 52 | % Create Habitats Array 53 | pop=repmat(habitat,N,1); 54 | 55 | % Initialize Habitats 56 | for i=1:N 57 | pop(i).Position= (high-ll).* rand(1,dim) + ll; 58 | % pop(i).Position=unifrnd(down,up,VarSize); 59 | % pop(i).Position=unifrnd(ll,high,VarSize); 60 | pop(i).Cost=benchmark_functions(pop(i).Position,Benchmark_Function_ID,dim); 61 | end 62 | 63 | % Sort Population 64 | [~, SortOrder]=sort([pop.Cost]); 65 | pop=pop(SortOrder); 66 | 67 | % Best Solution Ever Found 68 | BestSol=pop(1); 69 | 70 | % Array to Hold Best Costs 71 | BestCost=zeros(Max_Iteration,1); 72 | 73 | %% BBO Main Loop 74 | 75 | for it=1:Max_Iteration 76 | 77 | newpop=pop; 78 | for i=1:N 79 | for k=1:dim 80 | % Migration 81 | if rand<=lambda(i) 82 | % Emmigration Probabilities 83 | EP=mu; 84 | EP(i)=0; 85 | EP=EP/sum(EP); 86 | 87 | % Select Source Habitat 88 | j=RouletteWheelSelection(EP); 89 | 90 | % Migration 91 | newpop(i).Position(k)=pop(i).Position(k) ... 92 | +alpha*(pop(j).Position(k)-pop(i).Position(k)); 93 | 94 | end 95 | 96 | % Mutation 97 | if rand<=pMutation 98 | newpop(i).Position(k)=newpop(i).Position(k)+sigma*randn; 99 | end 100 | end 101 | 102 | % Apply Lower and Upper Bound Limits 103 | % newpop(i).Position = max(newpop(i).Position, down); 104 | % newpop(i).Position = min(newpop(i).Position, up); 105 | % % Apply Lower and Upper Bound Limits 106 | newpop(i).Position = max(newpop(i).Position, ll); 107 | newpop(i).Position = min(newpop(i).Position, high); 108 | 109 | % Evaluation 110 | newpop(i).Cost=benchmark_functions(newpop(i).Position,Benchmark_Function_ID,dim); 111 | end 112 | 113 | % Sort New Population 114 | [~, SortOrder]=sort([newpop.Cost]); 115 | newpop=newpop(SortOrder); 116 | 117 | % Select Next Iteration Population 118 | pop=[pop(1:nKeep) 119 | newpop(1:nNew)]; 120 | 121 | % Sort Population 122 | [~, SortOrder]=sort([pop.Cost]); 123 | pop=pop(SortOrder); 124 | 125 | % Update Best Solution Ever Found 126 | BestSol=pop(1); 127 | 128 | % Store Best Cost Ever Found 129 | BestCost(it)=BestSol.Cost; 130 | 131 | % % Show Iteration Information 132 | % disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(BestCost(it))]); 133 | 134 | end 135 | 136 | % %% Results 137 | % 138 | % figure; 139 | % %plot(BestCost,'LineWidth',2); 140 | % semilogy(BestCost,'LineWidth',2); 141 | % xlabel('Iteration'); 142 | % ylabel('Best Cost'); 143 | % grid on; 144 | 145 | 146 | -------------------------------------------------------------------------------- /benchmark_functions.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | % Chaotic GSA for Engineering Design Problems 4 | % 5 | % E-Mail: sajad.win8@gmail.com 6 | % 7 | % Homepage: https://github.com/SajadAHMAD1. 8 | % 9 | % Main paper: R.A., Rather, P.S., Bala, 10 | % Department of Computer Science and Engineering 11 | % School of Engineering and Technology 12 | % Pondicherry University- 605014, India 13 | % 14 | % Programmer: Sajad Ahmad Rather 15 | % Developed in MATLAB R2013a 16 | 17 | 18 | % This function calculates the value of objective function. 19 | function PHI=benchmark_functions(x,Benchmark_Function_ID,dim) 20 | 21 | %You can insert your own objective function with a new Benchmark_Function_ID. 22 | % dim=30; 23 | if Benchmark_Function_ID==1 24 | PHI=sum(x.^2); 25 | end 26 | 27 | if Benchmark_Function_ID==2 28 | PHI=sum(abs(x))+prod(abs(x)); 29 | end 30 | 31 | if Benchmark_Function_ID==3 32 | PHI=0; 33 | for i=1:dim 34 | PHI=PHI+sum(x(1:i))^2; 35 | end 36 | end 37 | 38 | if Benchmark_Function_ID==4 39 | PHI=max(abs(x)); 40 | end 41 | 42 | if Benchmark_Function_ID==5 43 | PHI=sum(100*(x(2:dim)-(x(1:dim-1).^2)).^2+(x(1:dim-1)-1).^2); 44 | end 45 | 46 | if Benchmark_Function_ID==6 47 | PHI=sum(abs((x+.5)).^2); 48 | end 49 | 50 | if Benchmark_Function_ID==7 51 | PHI=sum([1:dim].*(x.^4))+rand; 52 | end 53 | 54 | if Benchmark_Function_ID==8 55 | PHI=sum(-x.*sin(sqrt(abs(x)))); 56 | end 57 | 58 | if Benchmark_Function_ID==9 59 | PHI=sum(x.^2-10*cos(2*pi.*x))+10*dim; 60 | end 61 | 62 | if Benchmark_Function_ID==10 63 | PHI=-20*exp(-.2*sqrt(sum(x.^2)/dim))-exp(sum(cos(2*pi.*x))/dim)+20+exp(1); 64 | end 65 | 66 | if Benchmark_Function_ID==11 67 | PHI=sum(x.^2)/4000-prod(cos(x./sqrt([1:dim])))+1; 68 | end 69 | 70 | if Benchmark_Function_ID==12 71 | PHI=(pi/dim)*(10*((sin(pi*(1+(x(1)+1)/4)))^2)+sum((((x(1:dim-1)+1)./4).^2).*... 72 | (1+10.*((sin(pi.*(1+(x(2:dim)+1)./4)))).^2))+((x(dim)+1)/4)^2)+sum(Ufun(x,10,100,4)); 73 | end 74 | if Benchmark_Function_ID==13 75 | PHI=.1*((sin(3*pi*x(1)))^2+sum((x(1:dim-1)-1).^2.*(1+(sin(3.*pi.*x(2:dim))).^2))+... 76 | ((x(dim)-1)^2)*(1+(sin(2*pi*x(dim)))^2))+sum(Ufun(x,5,100,4)); 77 | end 78 | 79 | if Benchmark_Function_ID==14 80 | aS=[-32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32;,... 81 | -32 -32 -32 -32 -32 -16 -16 -16 -16 -16 0 0 0 0 0 16 16 16 16 16 32 32 32 32 32]; 82 | for j=1:25 83 | bS(j)=sum((x'-aS(:,j)).^6); 84 | end 85 | PHI=(1/500+sum(1./([1:25]+bS))).^(-1); 86 | end 87 | 88 | if Benchmark_Function_ID==15 89 | aK=[.1957 .1947 .1735 .16 .0844 .0627 .0456 .0342 .0323 .0235 .0246]; 90 | bK=[.25 .5 1 2 4 6 8 10 12 14 16];bK=1./bK; 91 | PHI=sum((aK-((x(1).*(bK.^2+x(2).*bK))./(bK.^2+x(3).*bK+x(4)))).^2); 92 | end 93 | 94 | if Benchmark_Function_ID==16 95 | PHI=4*(x(1)^2)-2.1*(x(1)^4)+(x(1)^6)/3+x(1)*x(2)-4*(x(2)^2)+4*(x(2)^4); 96 | end 97 | 98 | if Benchmark_Function_ID==17 99 | PHI=(x(2)-(x(1)^2)*5.1/(4*(pi^2))+5/pi*x(1)-6)^2+10*(1-1/(8*pi))*cos(x(1))+10; 100 | end 101 | 102 | if Benchmark_Function_ID==18 103 | PHI=(1+(x(1)+x(2)+1)^2*(19-14*x(1)+3*(x(1)^2)-14*x(2)+6*x(1)*x(2)+3*x(2)^2))*... 104 | (30+(2*x(1)-3*x(2))^2*(18-32*x(1)+12*(x(1)^2)+48*x(2)-36*x(1)*x(2)+27*(x(2)^2))); 105 | end 106 | 107 | if Benchmark_Function_ID==19 108 | aH=[3 10 30;.1 10 35;3 10 30;.1 10 35];cH=[1 1.2 3 3.2]; 109 | pH=[.3689 .117 .2673;.4699 .4387 .747;.1091 .8732 .5547;.03815 .5743 .8828]; 110 | PHI=0; 111 | for i=1:4 112 | PHI=PHI-cH(i)*exp(-(sum(aH(i,:).*((x-pH(i,:)).^2)))); 113 | end 114 | end 115 | 116 | if Benchmark_Function_ID==20 117 | aH=[10 3 17 3.5 1.7 8;.05 10 17 .1 8 14;3 3.5 1.7 10 17 8;17 8 .05 10 .1 14]; 118 | cH=[1 1.2 3 3.2]; 119 | pH=[.1312 .1696 .5569 .0124 .8283 .5886;.2329 .4135 .8307 .3736 .1004 .9991;... 120 | .2348 .1415 .3522 .2883 .3047 .6650;.4047 .8828 .8732 .5743 .1091 .0381]; 121 | PHI=0; 122 | for i=1:4 123 | PHI=PHI-cH(i)*exp(-(sum(aH(i,:).*((x-pH(i,:)).^2)))); 124 | end 125 | end 126 | 127 | aSH=[4 4 4 4;1 1 1 1;8 8 8 8;6 6 6 6;3 7 3 7;2 9 2 9;5 5 3 3;8 1 8 1;6 2 6 2;7 3.6 7 3.6]; 128 | cSH=[.1 .2 .2 .4 .4 .6 .3 .7 .5 .5]; 129 | 130 | if Benchmark_Function_ID==21 131 | PHI=0; 132 | for i=1:5 133 | PHI=PHI-((x-aSH(i,:))*(x-aSH(i,:))'+cSH(i))^(-1); 134 | end 135 | end 136 | 137 | if Benchmark_Function_ID==22 138 | PHI=0; 139 | for i=1:7 140 | PHI=PHI-((x-aSH(i,:))*(x-aSH(i,:))'+cSH(i))^(-1); 141 | end 142 | end 143 | 144 | if Benchmark_Function_ID==23 145 | PHI=0; 146 | for i=1:10 147 | PHI=PHI-((x-aSH(i,:))*(x-aSH(i,:))'+cSH(i))^(-1); 148 | end 149 | end 150 | if Benchmark_Function_ID==24 %welded design 151 | % fit=PrWf(L); 152 | %% WELDED BEAM DESIGN PROBLEM DEFINITION (all units are in british system) 153 | P = 6000; % APPLIED TIP LOAD 154 | E = 30e6; % YOUNGS MODULUS OF BEAM 155 | G = 12e6; % SHEAR MODULUS OF BEAM 156 | tem = 14; % LENGTH OF CANTILEVER PART OF BEAM 157 | PCONST = 100000; % PENALTY FUNCTION CONSTANT 158 | TAUMAX = 13600; % MAXIMUM ALLOWED SHEAR STRESS 159 | SIGMAX = 30000; % MAXIMUM ALLOWED BENDING STRESS 160 | DELTMAX = 0.25; % MAXIMUM ALLOWED TIP DEFLECTION 161 | M = P*(tem+x(2)/2); % BENDING MOMENT AT WELD POINT 162 | R = sqrt((x(2)^2)/4+((x(1)+x(3))/2)^2); % SOME CONSTANT 163 | J = 2*(sqrt(2)*x(1)*x(2)*((x(2)^2)/4+((x(1)+x(3))/2)^2)); % POLAR MOMENT OF INERTIA 164 | PHI = 1.10471*x(1)^2*x(2)+0.04811*x(3)*x(4)*(14+x(2)); % OBJECTIVE FUNCTION 165 | SIGMA = (6*P*tem)/(x(4)*x(3)^2); % BENDING STRESS 166 | DELTA = (4*P*tem^3)/(E*x(3)^3*x(4)); % TIP DEFLECTION 167 | PC = 4.013*E*sqrt((x(3)^2*x(4)^6)/36)*(1-x(3)*sqrt(E/(4*G))/(2*tem))/(tem^2); % BUCKLING LOAD 168 | TAUP = P/(sqrt(2)*x(1)*x(2)); % 1ST DERIVATIVE OF SHEAR STRESS 169 | TAUPP = (M*R)/J; % 2ND DERIVATIVE OF SHEAR STRESS 170 | TAU = sqrt(TAUP^2+2*TAUP*TAUPP*x(2)/(2*R)+TAUPP^2); % SHEAR STRESS 171 | G1 = TAU-TAUMAX; % MAX SHEAR STRESS CONSTRAINT 172 | G2 = SIGMA-SIGMAX; % MAX BENDING STRESS CONSTRAINT 173 | %G3 = L(1)-L(4); % WELD COVERAGE CONSTRAINT 174 | G3=DELTA-DELTMAX; 175 | G4=x(1)-x(4); 176 | G5=P-PC; 177 | G6=0.125-x(1); 178 | %G4 = 0.10471*L(1)^2+0.04811*L(3)*L(4)*(14+L(2))-5; % MAX COST CONSTRAINT 179 | %G5 = 0.125-L(1); % MAX WELD THICKNESS CONSTRAINT 180 | %G6 = DELTA-DELTMAX; % MAX TIP DEFLECTION CONSTRAINT 181 | %G7 = P-PC; % BUCKLING LOAD CONSTRAINT 182 | G7=1.10471*x(1)^2+0.04811*x(3)*x(4)*(14+x(2))-5; 183 | PHI = PHI + PCONST*(max(0,G1)^2+max(0,G2)^2+... 184 | max(0,G3)^2+max(0,G4)^2+max(0,G5)^2+... 185 | max(0,G6)^2+max(0,G7)^2); % PENALTY FUNCTION 186 | end 187 | 188 | if Benchmark_Function_ID==25 %Spring design 189 | 190 | %% TENSION/COMPRESSION SPRING DESIGN PROBLEM DEFINITION (all units are in british system) 191 | 192 | PCONST = 100; % PENALTY FUNCTION CONSTANT 193 | 194 | fit=(x(3)+2)*x(2)*(x(1)^2); 195 | G1=1-(x(2)^3*x(3))/(71785*x(1)^4); 196 | G2=(4*x(2)^2-x(1)*x(2))/(12566*(x(2)*x(1)^3-x(1)^4))+1/(5108*x(1)^2); 197 | G3=1-(140.45*x(1))/(x(2)^2*x(3)); 198 | G4=((x(1)+x(2))/1.5)-1; 199 | 200 | PHI = fit + PCONST*(max(0,G1)^2++max(0,G2)^2+... 201 | max(0,G3)^2+max(0,G4)^2); % PENALTY FUNCTION 202 | end 203 | 204 | if Benchmark_Function_ID==26 %Pressure vessel design 205 | %% Pressure Vessel design 206 | 207 | PCONST=10000; % PENALTY FUNCTION CONSTANT 208 | fit= 0.6224*x(1)*x(3)*x(4)+ 1.7781*x(2)*x(3)^2 + 3.1661 *x(1)^2*x(4) + 19.84 * x(1)^2*x(3); 209 | G1= -x(1)+ 0.0193*x(3); 210 | G2= -x(3) + 0.00954* x(3); 211 | G3= -pi*x(3)^2*x(4)-(4/3)* pi*x(3)^3 +1296000; 212 | G4= x(4) - 240; 213 | PHI =fit + PCONST*(max(0,G1)^2+max(0,G2)^2+... 214 | max(0,G3)^2+max(0,G4)^2); % PENALTY FUNCTION 215 | end 216 | if Benchmark_Function_ID==27 %Speed Reducer design 217 | %% Speed Reducer design 218 | PCONST=10000; % PENALTY FUNCTION CONSTANT 219 | fit=0.7854*x(1)*x(2)^2*(3.3333*x(3)^2-14.9334*x(3)-43.0934)-1.508*x(1)*(x(6)^2+x(7)^2)+7.4777*(x(6)^3+x(7)^3)+0.7854*(x(4)*x(6)^2+x(5)*x(7)^2); 220 | G1=27/(x(1)*x(2)^2*x(3))-1; 221 | G2=397.5/(x(1)*x(2)^2*x(3)^2); 222 | G3=1.93*x(4)^3/(x(2)*x(3)*x(6)^4); 223 | G4=1.93*x(5)^3/(x(2)*x(3)*x(7)^4); 224 | G5=1.0/(110*x(6)^3)*((745.0*x(4)/x(2)*x(3))^2+16.9*(10)^6)^(1/2)-1; 225 | G6=1.0/(85*x(7)^3)*((745.0*x(5)/x(2)*x(3))^2+157.5*(10)^6)^1/2-1; 226 | G7=x(2)*x(3)/40; 227 | G8=5*x(2)/(x(1))-1; 228 | G9=x(1)/(12*x(2))-1; 229 | G10=(1.5*x(6)+1.9)/(x(4))-1; 230 | G11=(1.1*x(7)+1.9)/(x(5))-1; 231 | PHI =fit+ PCONST*(max(0,G1)^2+max(0,G2)^2+... 232 | max(0,G3)^2+max(0,G4)^2+max(0,G5)^2+max(0,G6)^2+max(0,G7)^2+max(0,G8)^2+max(0,G9)^2+max(0,G10)^2+max(0,G11)^2); % PENALTY FUNCTION 233 | end 234 | if Benchmark_Function_ID==28 %Gear Train design 235 | %% gear train design 236 | %PCONST=10000; % PENALTY FUNCTION CONSTANT 237 | fit=((1/6.931)- floor (x(1))*floor (x(2))/floor (x(3))*floor (x(4)))^2; 238 | PHI=fit; 239 | end 240 | 241 | if Benchmark_Function_ID==29 %Himmelblau's Problem 242 | %% Himmelblau's Problem 243 | PCONST=10000; % PENALTY FUNCTION CONSTANT 244 | fit= 5.3578547* x(3)^2 + 0.8356891 *x(1)*x(5)+ 37.293239*x(1)-40792.141; 245 | G1= 85.334407 +0.0056858*x(1)*x(5)+0.0006262*x(1)*x(4)-0.0022053*x(3)*x(5); 246 | G2= 80.51249+ 0.0071317*x(2)*x(5)+0.0029955*x(1)*x(2)-0.0021813*x(3)^2; 247 | G3= 9.300961+0.0047026*x(3)*x(5)+0.0012547*x(1)*x(3)-0.0019085*x(3)*x(4); 248 | PHI =fit + PCONST*(max(0,G1)^2+max(0,G2)^2+ max(0,G3)^2); 249 | end 250 | if Benchmark_Function_ID==30 %Three Bar Truss Design 251 | %% Three Bar Truss Design 252 | PCONST=10000; % PENALTY FUNCTION CONSTANT 253 | P=2; 254 | RU=2; 255 | L=100; 256 | fit=(2*(2*x(1))^1/2+x(2))*L; 257 | G1=((2)^1/2*x(1)+ x(2))/ ((2)^1/2*x(1)^2+ 2*x(1)*x(2))*P-RU; 258 | G2= (x(2))/ ((2)^1/2*x(1)^2+2*x(1)*x(2))*P-RU; 259 | G3= (1)/(x(1)+ (2)^1/2*x(2))*P-RU; 260 | PHI =fit + PCONST*(max(0,G1)^2+max(0,G2)^2+ max(0,G3)^2); 261 | 262 | end 263 | if Benchmark_Function_ID==31 %Stepped Cantilever Beam Design 264 | %% Stepped Cantilever Beam Design 265 | PCONST=10000; % PENALTY FUNCTION CONSTANT 266 | L=100; 267 | P=50000; 268 | E=2*107; 269 | fit=(x(1)*x(6)+x(2)*x(7)+x(3)*x(8)+x(4)*x(9)+x(5)*x(10))*L; 270 | G1= ((600*P)/(x(5)*x(10)^2))-14000; 271 | G2= ((6*P*2*L)/(x(4)*x(9)^2))-14000; 272 | G3= ((6*P*3*L)/(x(3)*x(8)^2))-14000; 273 | G4= ((6*P*4*L)/(x(2)*x(7)^2))-14000; 274 | G5= ((6*P*5*L)/(x(1)*x(6)^2))-14000; 275 | G6= (((P*L^3)/(3*E))*(125/L))-2.7; 276 | G7=(x(10)/x(5))-20; 277 | G8=(x(9)/x(4))-20; 278 | G9=(x(8)/x(3))-20; 279 | G10=(x(7)/x(2))-20; 280 | G11=(x(6)/x(1))-20; 281 | PHI =fit + PCONST*(max(0,G1)^2+max(0,G2)^2+... 282 | max(0,G3)^2+max(0,G4)^2+max(0,G5)^2+max(0,G6)^2+max(0,G7)^2+max(0,G8)^2+max(0,G9)^2+max(0,G10)^2+max(0,G11)^2); % PENALTY FUNCTION 283 | 284 | end 285 | if Benchmark_Function_ID==32 %Multiple Disc Clutch Brake Design 286 | %% Multiple Disc Clutch Brake Design 287 | PCONST=100000; % PENALTY FUNCTION CONSTANT 288 | DR=20; 289 | % T=3; 290 | L=30; 291 | % Z=10; 292 | VSR=10; 293 | MU=0.5; 294 | S=1.5; 295 | MS=40; 296 | MF=3; 297 | n=250; 298 | P=1; 299 | I=55; 300 | T=15; 301 | % F=1000; 302 | % RI=80; 303 | % % RO=110; 304 | MH=(2/3)*MU*x(4)*x(5)*((x(2)^3-x(1)^3)/(x(2)^2-x(1)^2)); 305 | PRZ=x(4)/pi*(x(2)^2-x(1)^2); 306 | VSR1= (2/90)*pi*n*((x(2)^3-x(1)^3)/(x(2)^2-x(1)^2)); 307 | T1= (I*pi*n)/(30*(MH+MF)); 308 | fit=pi*x(3)*( x(2)^2-x(1)^2)*(x(5)+1)*8*P; 309 | G1= x(2)-x(1)-DR; 310 | G2= L-(x(5)+1)*x(3); 311 | G3= P-PRZ; 312 | G4= P*VSR-PRZ*VSR; 313 | G5=VSR-VSR1; 314 | G6= T-T1; 315 | G7= MH-S*MS; 316 | G8= T1; 317 | PHI =fit + PCONST*(max(0,G1)^2+max(0,G2)^2+... 318 | max(0,G3)^2+max(0,G4)^2+max(0,G5)^2+max(0,G6)^2+max(0,G7)^2+max(0,G8)^2); 319 | end 320 | if Benchmark_Function_ID==33 %Hydrodynamic Thrust Bearing Design 321 | %% Hydrodynamic Thrust Bearing Design 322 | PCONST=100000; % PENALTY FUNCTION CONSTANT 323 | WS=101000; 324 | PMAX=1000; 325 | DTM=50; 326 | HM=0.001; 327 | Y=0.0307; 328 | C=0.5; 329 | C1=10.04; 330 | n=-3.55; 331 | Ne=750; 332 | Ge=386.4; 333 | P= (log10(log10(8.1222*1e6*x(3)+0.8)-C1))/n; 334 | DT= 2*(10^P-560); 335 | EF= 9336* x(4)*Y*C*DT; 336 | H= ((2*pi*Ne)/60)^2*((2*pi*x(3))/EF)*((x(1)^4/4)-((x(2)^4)/4)); 337 | P0= (6*x(3)*x(4)/pi*H^3)* log(x(1)/x(2)); 338 | W=((pi*P0)/2)*((x(1)^2*x(2)^2)/log(x(1)/x(2))); 339 | fit=((x(4)*P0)/0.7)+EF; 340 | G1= W-WS; 341 | G2=PMAX-P0; 342 | G3= DTM-DT; 343 | G4= H-HM; 344 | G5=x(1)-x(2); 345 | G6= 0.001- (Y/(Ge*P0))*(x(4)/2*pi*x(1)*H); 346 | G7= 5000- W/(pi*(x(1)^2*x(2)^2)); 347 | PHI =fit + PCONST*(max(0,G1)^2+max(0,G2)^2+... 348 | max(0,G3)^2+max(0,G4)^2+max(0,G5)^2+max(0,G6)^2+max(0,G7)^2); 349 | end 350 | % function y=Ufun(x,a,k,m) 351 | % y=k.*((x-a).^m).*(x>a)+k.*((-x-a).^m).*(x<(-a)); 352 | % return 353 | -------------------------------------------------------------------------------- /benchmark_functions_details.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | % Chaotic GSA for Engineering Design Problems 4 | % 5 | % E-Mail: sajad.win8@gmail.com 6 | % 7 | % Homepage: https://github.com/SajadAHMAD1. 8 | % 9 | % Main paper: R.A., Rather, P.S., Bala, 10 | % Department of Computer Science and Engineering 11 | % School of Engineering and Technology 12 | % Pondicherry University- 605014, India 13 | % 14 | % Programmer: Sajad Ahmad Rather 15 | % Developed in MATLAB R2013a 16 | 17 | 18 | 19 | % This function gives boundaries and dimension of search space for test functions. 20 | function [down,up,dim]=benchmark_functions_details(Benchmark_Function_ID) 21 | 22 | %If lower bounds of dimensions are the same, then 'down' is a value. 23 | %Otherwise, 'down' is a vector that shows the lower bound of each dimension. 24 | %This is also true for upper bounds of dimensions. 25 | 26 | %Insert your own boundaries with a new Benchmark_Function_ID. 27 | 28 | dim=30; 29 | if Benchmark_Function_ID==1 30 | down=-100;up=100; 31 | end 32 | 33 | if Benchmark_Function_ID==2 34 | down=-10;up=10; 35 | end 36 | 37 | if Benchmark_Function_ID==3 38 | down=-100;up=100; 39 | end 40 | 41 | if Benchmark_Function_ID==4 42 | down=-100;up=100; 43 | end 44 | 45 | if Benchmark_Function_ID==5 46 | down=-30;up=30; 47 | end 48 | 49 | if Benchmark_Function_ID==6 50 | down=-100;up=100; 51 | end 52 | 53 | if Benchmark_Function_ID==7 54 | down=-1.28;up=1.28; 55 | end 56 | 57 | if Benchmark_Function_ID==8 58 | down=-500;up=500; 59 | end 60 | 61 | if Benchmark_Function_ID==9 62 | down=-5.12;up=5.12; 63 | end 64 | 65 | if Benchmark_Function_ID==10 66 | down=-32;up=32; 67 | end 68 | 69 | if Benchmark_Function_ID==11 70 | down=-600;up=600; 71 | end 72 | 73 | if Benchmark_Function_ID==12 74 | down=-50;up=50; 75 | end 76 | 77 | if Benchmark_Function_ID==13 78 | down=-50;up=50; 79 | end 80 | 81 | if Benchmark_Function_ID==14 82 | down=-65.536;up=65.536;dim=2; 83 | end 84 | 85 | if Benchmark_Function_ID==15 86 | down=-5;up=5;dim=4; 87 | end 88 | 89 | if Benchmark_Function_ID==16 90 | down=-5;up=5;dim=2; 91 | end 92 | 93 | if Benchmark_Function_ID==17 94 | down=[-5;0];up=[10;15];dim=2; 95 | end 96 | 97 | if Benchmark_Function_ID==18 98 | down=-2;up=2;dim=2; 99 | end 100 | 101 | if Benchmark_Function_ID==19 102 | down=0;up=1;dim=3; 103 | end 104 | 105 | if Benchmark_Function_ID==20 106 | down=0;up=1;dim=6; 107 | end 108 | 109 | if Benchmark_Function_ID==21 110 | down=0;up=10;dim=4; 111 | end 112 | 113 | if Benchmark_Function_ID==22 114 | down=0;up=10;dim=4; 115 | end 116 | 117 | if Benchmark_Function_ID==23 118 | down=0;up=10;dim=4; 119 | end 120 | if Benchmark_Function_ID==24 %Welded Design 121 | down=[0.10;0.10;0.10;0.10]; 122 | up=[2;10;10;2]; 123 | dim=4; 124 | end 125 | if Benchmark_Function_ID==25 %Spring Design 126 | down=[0.05;0.25;2.00]; 127 | up=[2.00;1.30;15.0]; 128 | dim=3; 129 | 130 | end 131 | if Benchmark_Function_ID==26 %Pressure vessel 132 | 133 | down=[0;0;10;10]; % Lower Bound of Variables 134 | up= [99;99;200;200]; % Upper Bound of Variables 135 | dim=4; 136 | end 137 | if Benchmark_Function_ID==27 %Speed Reducer design 138 | down=[2.6;0.7;17;7.3;7.8;2.9;5]; % Lower Bound of Variables 139 | up= [3.6;0.8;28;8.3;8.3;3.9;5.5]; % Upper Bound of Variables 140 | dim=7; 141 | end 142 | if Benchmark_Function_ID==28 %Gear Train design 143 | down=[12;12;12;12]; % Lower Bound of Variables 144 | up=[60;60;60;60]; % Upper Bound of Variables 145 | dim=4; 146 | end 147 | if Benchmark_Function_ID==29 %Himmelblau's Problem 148 | down=[78;33;27;27;27]; % Lower Bound of Variables 149 | up=[102;45;45;45;45]; % Upper Bound of Variables 150 | dim=5; 151 | end 152 | if Benchmark_Function_ID==30 % Three Bar Truss Design 153 | down=[0;0]; % Lower Bound of Variables 154 | up=[1;1]; % Upper Bound of Variables 155 | dim=2; 156 | end 157 | if Benchmark_Function_ID==31 % Stepped Cantilever Beam Design 158 | down=[1;1;1;1;1;30;30;30;30;30]; % Lower Bound of Variables 159 | up=[5;5;5;5;5;65;65;65;65;65]; % Upper Bound of Variables 160 | dim=10; 161 | end 162 | if Benchmark_Function_ID==32 % Multiple Disc Clutch Brake Design 163 | down=[60;90;1.5;600;2]; % Lower Bound of Variables 164 | up=[80;110;3;1000;9]; % Upper Bound of Variables 165 | dim=5; 166 | end 167 | if Benchmark_Function_ID==33 % Hydrodynamic Thrust Bearing Design 168 | down=[1;1;1e6;1]; % Lower Bound of Variables 169 | up=[16;16;16e6;16]; % Upper Bound of Variables 170 | dim=4; 171 | end 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /chaos.m: -------------------------------------------------------------------------------- 1 | %The code has been taken from: 2 | % % 3 | % Homepage: http://www.alimirjalili.com % 4 | % % 5 | 6 | 7 | function O=chaos(index,curr_iter,Max_Iteration,Value) 8 | 9 | x(1)=0.7; 10 | switch index 11 | %Chebyshev map 12 | case 1 13 | for i=1:Max_Iteration 14 | x(i+1)=cos(i*acos(x(i))); 15 | G(i)=((x(i)+1)*Value)/2; 16 | end 17 | case 2 18 | %Circle map 19 | a=0.5; 20 | b=0.2; 21 | for i=1:Max_Iteration 22 | x(i+1)=mod(x(i)+b-(a/(2*pi))*sin(2*pi*x(i)),1); 23 | G(i)=x(i)*Value; 24 | end 25 | case 3 26 | %Gauss/mouse map 27 | for i=1:Max_Iteration 28 | if x(i)==0 29 | x(i+1)=0; 30 | else 31 | x(i+1)=mod(1/x(i),1); 32 | end 33 | G(i)=x(i)*Value; 34 | end 35 | case 4 36 | %Iterative map 37 | a=0.7; 38 | for i=1:Max_Iteration 39 | x(i+1)=sin((a*pi)/x(i)); 40 | G(i)=((x(i)+1)*Value)/2; 41 | end 42 | case 5 43 | %Logistic map 44 | a=4; 45 | for i=1:Max_Iteration 46 | x(i+1)=a*x(i)*(1-x(i)); 47 | G(i)=x(i)*Value; 48 | end 49 | case 6 50 | %Piecewise map 51 | P=0.4; 52 | for i=1:Max_Iteration 53 | if x(i)>=0 && x(i)

=P && x(i)<0.5 57 | x(i+1)=(x(i)-P)/(0.5-P); 58 | end 59 | if x(i)>=0.5 && x(i)<1-P 60 | x(i+1)=(1-P-x(i))/(0.5-P); 61 | end 62 | if x(i)>=1-P && x(i)<1 63 | x(i+1)=(1-x(i))/P; 64 | end 65 | G(i)=x(i)*Value; 66 | end 67 | 68 | case 7 69 | %Sine map 70 | for i=1:Max_Iteration 71 | x(i+1) = sin(pi*x(i)); 72 | G(i)=(x(i))*Value; 73 | end 74 | case 8 75 | %Singer map 76 | u=1.07; 77 | for i=1:Max_Iteration 78 | x(i+1) = u*(7.86*x(i)-23.31*(x(i)^2)+28.75*(x(i)^3)-13.302875*(x(i)^4)); 79 | G(i)=(x(i))*Value; 80 | end 81 | case 9 82 | %Sinusoidal map 83 | for i=1:Max_Iteration 84 | x(i+1) = 2.3*x(i)^2*sin(pi*x(i)); 85 | G(i)=(x(i))*Value; 86 | end 87 | 88 | case 10 89 | %Tent map 90 | x(1)=0.6; 91 | for i=1:Max_Iteration 92 | if x(i)<0.7 93 | x(i+1)=x(i)/0.7; 94 | end 95 | if x(i)>=0.7 96 | x(i+1)=(10/3)*(1-x(i)); 97 | end 98 | G(i)=(x(i))*Value; 99 | end 100 | end 101 | O=G(curr_iter); -------------------------------------------------------------------------------- /crossover_continious.m: -------------------------------------------------------------------------------- 1 | 2 | function [child1 , child2] = crossover_continious(parent1 , parent2, Pc, Benchmark_Function_ID,dim,up,low) 3 | 4 | child1.Gene = zeros(1,dim); 5 | child2.Gene = zeros(1,dim); 6 | for k = 1 : dim 7 | beta = rand(); 8 | child1.Gene(k) = beta .* parent1.Gene(k) + (1-beta)*parent2.Gene(k); 9 | child2.Gene(k) = (1-beta) .* parent1.Gene(k) + beta*parent2.Gene(k); 10 | 11 | if child1.Gene(k) > up(k) 12 | child1.Gene(k) = up(k); 13 | end 14 | if child1.Gene(k) < low(k) 15 | child1.Gene(k) = low(k); 16 | end 17 | 18 | if child2.Gene(k) > up(k) 19 | child2.Gene(k) = up(k); 20 | end 21 | 22 | if child2.Gene(k) < low(k) 23 | child2.Gene(k) = low(k); 24 | end 25 | end 26 | 27 | R1 = rand(); 28 | 29 | if R1 <= Pc 30 | child1 = child1; 31 | else 32 | child1 = parent1; 33 | end 34 | 35 | R2 = rand(); 36 | 37 | if R2 <= Pc 38 | child2 = child2; 39 | else 40 | child2 = parent2; 41 | end 42 | 43 | end -------------------------------------------------------------------------------- /elitism.m: -------------------------------------------------------------------------------- 1 | 2 | function [ newPopulation2 ] = elitism(population , newpopulation, Er) 3 | 4 | M = length(newpopulation.Chromosomes); % number of individuals 5 | Elite_no = round(M * Er); 6 | 7 | [max_val , indx] = sort([ population.Chromosomes(:).fitness ] , 'descend'); 8 | 9 | 10 | 11 | for k = 1 : Elite_no 12 | newPopulation2.Chromosomes(k).Gene = population.Chromosomes(indx(k)).Gene; 13 | newPopulation2.Chromosomes(k).fitness = population.Chromosomes(indx(k)).fitness; 14 | end 15 | 16 | for k = Elite_no + 1 : length(newpopulation.Chromosomes) 17 | newPopulation2.Chromosomes(k).Gene = newpopulation.Chromosomes(k).Gene; 18 | newPopulation2.Chromosomes(k).fitness = newpopulation.Chromosomes(k).fitness; 19 | end 20 | 21 | end -------------------------------------------------------------------------------- /evaluateF.m: -------------------------------------------------------------------------------- 1 | 2 | function fitness=evaluateF(X,Benchmark_Function_ID) 3 | 4 | [dim,N]=size(X); 5 | for i=1:N 6 | L=X(:,i)'; 7 | %calculation of objective function 8 | fitness(i)=benchmark_functions(L,Benchmark_Function_ID,dim); 9 | end -------------------------------------------------------------------------------- /initialization.m: -------------------------------------------------------------------------------- 1 | 2 | %This function initializes the position of the agents in the search space, randomly. 3 | function [X]=initialization(dim,N,up,down) 4 | 5 | if size(up,1)==1 6 | X=rand(dim,N).*(up-down)+down; 7 | end 8 | if size(up,1)>1 9 | for i=1:dim 10 | high=up(i);low=down(i); 11 | X(i,:)=rand(1,N).*(high-low)+low; 12 | end 13 | end -------------------------------------------------------------------------------- /initializationGWO.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | % This function initialize the first population of search agents 4 | function Positions=initializationGWO(N,dim,up,down) 5 | 6 | Boundary_no= size(up,1); % numnber of boundaries 7 | 8 | % If the boundaries of all variables are equal and user enter a signle 9 | % number for both ub and lb 10 | if Boundary_no==1 11 | Positions=rand(N,dim).*(up-down)+down; 12 | end 13 | 14 | % If each variable has a different lb and ub 15 | if Boundary_no>1 16 | for i=1:dim 17 | ub_i=up(i); 18 | lb_i=down(i); 19 | Positions(:,i)=rand(N,1).*(ub_i-lb_i)+lb_i; 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /initializationSCA.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | % This function creates the first random population of moths 4 | 5 | function X=initializationSCA(N,dim,up,down) 6 | 7 | Boundary_no= size(up,1); % numnber of boundaries 8 | 9 | % If the boundaries of all variables are equal and user enter a signle 10 | % number for both ub and lb 11 | if Boundary_no==1 12 | X=rand(N,dim).*(up-down)+down; 13 | end 14 | 15 | % If each variable has a different lb and ub 16 | if Boundary_no>1 17 | for i=1:dim 18 | ub_i=up(i); 19 | lb_i=down(i); 20 | X(:,i)=rand(N,1).*(ub_i-lb_i)+lb_i; 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /initializationSSA.m: -------------------------------------------------------------------------------- 1 | __________________________________________________________ 2 | 3 | 4 | % This function initialize the first population of search agents 5 | function Positions=initializationSSA(N,dim,up,down) 6 | 7 | Boundary_no= size(up,1); % numnber of boundaries 8 | 9 | % If the boundaries of all variables are equal and user enter a signle 10 | % number for both ub and lb 11 | if Boundary_no==1 12 | Positions=rand(N,dim).*(up-down)+down; 13 | end 14 | 15 | % If each variable has a different lb and ub 16 | if Boundary_no>1 17 | for i=1:dim 18 | up_i=up(i); 19 | down_i=down(i); 20 | Positions(:,i)=rand(N,1).*(up_i-down_i)+down_i; 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /massCalculation.m: -------------------------------------------------------------------------------- 1 | 2 | function [M]=massCalculation(fit,min_flag); 3 | %%%%here, make your own function of 'mass calculation' 4 | 5 | Fmax=max(fit); Fmin=min(fit); Fmean=mean(fit); 6 | [i N]=size(fit); 7 | 8 | if Fmax==Fmin 9 | M=ones(N,1); 10 | else 11 | 12 | if min_flag==1 %for minimization 13 | best=Fmin;worst=Fmax; %eq.17-18. 14 | else %for maximization 15 | best=Fmax;worst=Fmin; %eq.19-20. 16 | end 17 | 18 | M=(fit-worst)./(best-worst); %eq.15, 19 | 20 | end 21 | 22 | M=M./sum(M); %eq. 16. -------------------------------------------------------------------------------- /move.m: -------------------------------------------------------------------------------- 1 | %This function updates the velocity and position of agents. 2 | function [X,V]=move(X,a,V) 3 | 4 | %movement. 5 | [dim,N]=size(X); 6 | V=rand(dim,N).*V+a; %eq. 11. 7 | X=X+V; %eq. 12. -------------------------------------------------------------------------------- /mutation_continious.m: -------------------------------------------------------------------------------- 1 | 2 | function [child] = mutation_continious(child, Pm, Benchmark_Function_ID,up,low) 3 | 4 | Gene_no = length(child.Gene); 5 | 6 | for k = 1: Gene_no 7 | R = rand(); 8 | if R < Pm 9 | child.Gene(k) = (up(k) - low(k)) * rand() +low(k); 10 | end 11 | end 12 | 13 | end -------------------------------------------------------------------------------- /pso.m: -------------------------------------------------------------------------------- 1 | % 2 | 3 | 4 | % Chaotic GSA for Engineering Design Problems 5 | % 6 | % E-Mail: sajad.win8@gmail.com 7 | % 8 | % Homepage: https://github.com/SajadAHMAD1. 9 | % 10 | % Main paper: R.A., Rather, P.S., Bala, 11 | % Department of Computer Science and Engineering 12 | % School of Engineering and Technology 13 | % Pondicherry University- 605014, India 14 | % 15 | % Programmer: Sajad Ahmad Rather 16 | % Developed in MATLAB R2013a 17 | 18 | 19 | 20 | function [cgCurve,GBEST] = pso( Benchmark_Function_ID, N, Max_Iteration) 21 | 22 | 23 | % dim=30; 24 | 25 | 26 | % Define the details of the objective function 27 | %get allowable range and dimension of the test function. 28 | [down,up,dim]=benchmark_functions_details(Benchmark_Function_ID); 29 | % PSO parameters 30 | % noP = 5; 31 | % maxIter = 100; 32 | % visFlag = 0; 33 | % 34 | % RunNo = 30; 35 | % 36 | % 37 | % for k = [ 1 : 1 : RunNo ] 38 | % fit=benchmark_functions(currentX,Benchmark_Function_ID,dim); 39 | 40 | % PSO 1 41 | % [ GBEST , cgcurve1] = PSO( Benchmark_Function_ID, N, Max_Iteration) ; 42 | % BestSolutions1(k) = GBEST.O; 43 | % 44 | % disp(['Run # ' , num2str(k), 'GBEST.O: ' , num2str( GBEST.O)]); 45 | % end 46 | % % Define the details of the objective function 47 | % %get allowable range and dimension of the test function. 48 | % [down,up,dim]=benchmark_functions_details(Benchmark_Function_ID); 49 | 50 | 51 | % Define the PSO's paramters 52 | wMax = 0.9; 53 | wMin = 0.2; 54 | c1 = 2; 55 | c2 = 2; 56 | if size(up,1)==1 57 | current_position=rand(dim,N).*(up-down)+down; 58 | VelMax=0.1*(up-down); 59 | VelMin=-up; 60 | end 61 | if size(up,1)>1 62 | for i=1:dim 63 | high=up(i);ll=down(i); 64 | current_position(i,:)=rand(1,N).*(high-ll)+ll; 65 | VelMax=0.1*(high-ll); 66 | VelMin=-high; 67 | end 68 | end 69 | vMax = (up - down) .* 0.2; 70 | vMin = -vMax; 71 | 72 | 73 | % The PSO algorithm 74 | 75 | % Initialize the particles 76 | for k = 1 :N 77 | % Swarm.Particles(k).X = (up-down) .* rand(1,dim) + down; 78 | Swarm.Particles(k).X = (high-ll) .* rand(1,dim) + ll; 79 | 80 | Swarm.Particles(k).V = zeros(1, dim); 81 | Swarm.Particles(k).PBEST.X = zeros(1,dim); 82 | Swarm.Particles(k).PBEST.O = inf; 83 | 84 | Swarm.GBEST.X = zeros(1,dim); 85 | Swarm.GBEST.O = inf; 86 | end 87 | 88 | 89 | % Main loop 90 | for t = 1 : Max_Iteration 91 | 92 | % Calcualte the objective value 93 | for k = 1 : N 94 | currentX = Swarm.Particles(k).X; 95 | Swarm.Particles(k).O = benchmark_functions(currentX,Benchmark_Function_ID,dim); 96 | 97 | % Update the PBEST 98 | if Swarm.Particles(k).O < Swarm.Particles(k).PBEST.O 99 | Swarm.Particles(k).PBEST.X = currentX; 100 | Swarm.Particles(k).PBEST.O = Swarm.Particles(k).O; 101 | end 102 | 103 | % Update the GBEST 104 | if Swarm.Particles(k).O < Swarm.GBEST.O 105 | Swarm.GBEST.X = currentX; 106 | Swarm.GBEST.O = Swarm.Particles(k).O; 107 | end 108 | end 109 | 110 | % Update the X and V vectors 111 | w = wMax - t .* ((wMax - wMin) / Max_Iteration); 112 | 113 | for k = 1 : N 114 | Swarm.Particles(k).V = w .* Swarm.Particles(k).V + c1 .* rand(1,dim) .* (Swarm.Particles(k).PBEST.X - Swarm.Particles(k).X) ... 115 | + c2 .* rand(1,dim) .* (Swarm.GBEST.X - Swarm.Particles(k).X); 116 | 117 | % Apply Velocity Limits 118 | Swarm.Particles(k).V= max(Swarm.Particles(k).V,VelMin); 119 | Swarm.Particles(k).V = min(Swarm.Particles(k).V,VelMax); 120 | % % Check velocities 121 | % index1 = find(Swarm.Particles(k).V > vMax); 122 | % index2 = find(Swarm.Particles(k).V < vMin); 123 | % % 124 | % Swarm.Particles(k).V(index1) = vMax(index1); 125 | % Swarm.Particles(k).V(index2) = vMin(index2); 126 | 127 | Swarm.Particles(k).X = Swarm.Particles(k).X + Swarm.Particles(k).V; 128 | % Velocity Mirror Effect 129 | % IsOutside=(Swarm.Particles(k).Xup); 130 | % Swarm.Particles(k).V (IsOutside)=-Swarm.Particles(k).V (IsOutside); 131 | % Velocity Mirror Effect 132 | IsOutside=(Swarm.Particles(k).Xhigh); 133 | Swarm.Particles(k).V (IsOutside)=-Swarm.Particles(k).V (IsOutside); 134 | % % Apply Position Limits 135 | Swarm.Particles(k).X = max(Swarm.Particles(k).X,ll); 136 | Swarm.Particles(k).X= min(Swarm.Particles(k).X,high); 137 | % % Apply Position Limits 138 | % Swarm.Particles(k).X = max(Swarm.Particles(k).X,down); 139 | % Swarm.Particles(k).X= min(Swarm.Particles(k).X,up); 140 | % Check positions 141 | % index1 = find(Swarm.Particles(k).X > high); 142 | % index2 = find(Swarm.Particles(k).X < ll); 143 | % 144 | % Swarm.Particles(k).X(index1) = high(index1); 145 | % Swarm.Particles(k).X(index2) = ll(index2); 146 | % 147 | end 148 | 149 | % if dataVis == 1 150 | % outmsg = ['Iteration# ', num2str(t) , ' Swarm.GBEST.O = ' , num2str(Swarm.GBEST.O)]; 151 | % disp(outmsg); 152 | % end 153 | % 154 | cgCurve(t) = Swarm.GBEST.O; 155 | end 156 | 157 | GBEST = Swarm.GBEST; 158 | 159 | % if dataVis == 1 160 | % semilogy(cgCurve); 161 | % xlabel('Iteration#') 162 | % ylabel('Weight') 163 | % end 164 | -------------------------------------------------------------------------------- /selection.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | function [parent1, parent2] = selection(population) 4 | 5 | N = length(population.Chromosomes(:)); 6 | 7 | if any([population.Chromosomes(:).fitness] < 0 ) 8 | % Fitness scaling in case of negative values scaled(f) = a * f + b 9 | a = 1; 10 | b = abs( min( [population.Chromosomes(:).fitness] ) ); 11 | Scaled_fitness = a * [population.Chromosomes(:).fitness] + b; 12 | 13 | normalized_fitness = [Scaled_fitness] ./ sum([Scaled_fitness]); 14 | else 15 | normalized_fitness = [population.Chromosomes(:).fitness] ./ sum([population.Chromosomes(:).fitness]); 16 | end 17 | 18 | 19 | [sorted_fintness_values , sorted_idx] = sort(normalized_fitness , 'descend'); 20 | 21 | for i = 1 : length(population.Chromosomes) 22 | temp_population.Chromosomes(i).Gene = population.Chromosomes(sorted_idx(i)).Gene; 23 | temp_population.Chromosomes(i).fitness = population.Chromosomes(sorted_idx(i)).fitness; 24 | temp_population.Chromosomes(i).normalized_fitness = normalized_fitness(sorted_idx(i)); 25 | end 26 | 27 | 28 | cumsum = zeros(1 , N); 29 | 30 | for i = 1 : N 31 | for j = i : N 32 | cumsum(i) = cumsum(i) + temp_population.Chromosomes(j).normalized_fitness; 33 | end 34 | end 35 | 36 | 37 | R = rand(); % in [0,1] 38 | parent1_idx = N; 39 | for i = 1: length(cumsum) 40 | if R > cumsum(i) 41 | parent1_idx = i - 1; 42 | break; 43 | end 44 | end 45 | 46 | parent2_idx = parent1_idx; 47 | while_loop_stop = 0; % to break the while loop in rare cases where we keep getting the same index 48 | while parent2_idx == parent1_idx 49 | while_loop_stop = while_loop_stop + 1; 50 | R = rand(); % in [0,1] 51 | if while_loop_stop > 20 52 | break; 53 | end 54 | for i = 1: length(cumsum) 55 | if R > cumsum(i) 56 | parent2_idx = i - 1; 57 | break; 58 | end 59 | end 60 | end 61 | 62 | parent1 = temp_population.Chromosomes(parent1_idx); 63 | parent2 = temp_population.Chromosomes(parent2_idx); 64 | 65 | end -------------------------------------------------------------------------------- /space_bound.m: -------------------------------------------------------------------------------- 1 | 2 | %This function checks the search space boundaries for agents. 3 | function X=space_bound(X,up,low); 4 | 5 | [dim,mass_num]=size(X); 6 | for i=1:mass_num 7 | Tp=X(:,i)>up;Tm=X(:,i)