├── BBBC ├── BBBC.m ├── fitnessFunc.m └── limiter.m ├── BBKH ├── BBKH.m ├── fitnessFunc.m ├── limiter.m └── sortPop.m ├── DE ├── DE.m ├── fitnessFunc.m └── limiter.m ├── FA ├── FA.m ├── alpha_new.m ├── fitnessFunc.m ├── limiter.m └── move.m ├── GA ├── GA.m ├── crossover.m ├── fitnessFunc.m ├── limiter.m └── mutate.m ├── GWO ├── GWO.m ├── fitnessFunc.m └── limiter.m ├── IWD ├── IWD.m ├── fitnessFunc.m └── limiter.m ├── LICENSE ├── MBO ├── MBO.m ├── fitnessFunc.m └── limiter.m ├── PSO ├── PSO.m ├── fitnessFunc.m └── limiter.m ├── README.md ├── SBO ├── Roulette.m ├── SBO.m ├── fitnessFunc.m └── limiter.m ├── SOS ├── SOS.m ├── fitnessFunc.m └── limiter.m └── WEO ├── WEO.m ├── calcJ.m ├── fitnessFunc.m └── limiter.m /BBBC/BBBC.m: -------------------------------------------------------------------------------- 1 | %Big Bang Big Crunch Algorithm 2 | %----------------------------- 3 | clc 4 | clear 5 | close all 6 | 7 | % Problem Statement 8 | Npar = 3; 9 | VarLow=[-5.12 -5.12 -5.12]; 10 | VarHigh = [5.12 5.12 5.12]; 11 | 12 | %BBBC parameters 13 | N=100; %number of candidates 14 | MaxIter=100; %number of iterations 15 | 16 | % initialize a random value as best value 17 | XBest = rand(1,Npar).* (VarHigh - VarLow) + VarLow; 18 | FBest=fitnessFunc(XBest); 19 | GB=FBest; 20 | t = cputime; 21 | 22 | %intialize solutions and memory 23 | X = zeros(N, Npar); 24 | F = zeros(N, 1); 25 | 26 | for ii = 1:N 27 | X(ii,:) = rand(1,Npar).* (VarHigh - VarLow) + VarLow; 28 | 29 | % calculate the fitness of solutions 30 | F(ii) = fitnessFunc(X(ii,:)); 31 | end 32 | 33 | %Main Loop 34 | for it=1:MaxIter 35 | 36 | %Find the centre of mass 37 | %----------------------- 38 | 39 | %numerator term 40 | num=zeros(1,Npar); 41 | for ii=1:N 42 | for jj=1:Npar 43 | num(jj)=num(jj)+(X(ii,jj)/F(ii)); 44 | end 45 | end 46 | 47 | %denominator term 48 | den=sum(1./F); 49 | 50 | %centre of mass 51 | Xc=num/den; 52 | 53 | %generate new solutions 54 | %---------------------- 55 | for ii=1:N 56 | 57 | %new solution from centre of mass 58 | for jj=1:Npar 59 | New=X(ii,:); 60 | New(jj)=Xc(jj)+((VarHigh(jj)*rand)/it^2); 61 | end 62 | 63 | %boundary constraints 64 | New=limiter(New,VarHigh,VarLow); 65 | %new fitness 66 | newFit=fitnessFunc(New); 67 | 68 | %check whether the solution is better than previous solution 69 | if newFitVarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i)VarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i)VarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i)VarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i)Lighto(j) % Brighter and more attractive 18 | % Update moves 19 | beta0=1; 20 | beta=(beta0-betamin)*exp(-gamma*r.^2)+betamin; 21 | tmpf=alpha.*(rand(1,d)-0.5).*scale; 22 | ns(i,:)=ns(i,:).*(1-beta)+nso(j,:).*beta+tmpf; 23 | end 24 | end 25 | 26 | end 27 | 28 | end 29 | -------------------------------------------------------------------------------- /GA/GA.m: -------------------------------------------------------------------------------- 1 | % Genetic Algorithm 2 | %------------------ 3 | clc 4 | clear 5 | close all 6 | 7 | % Problem Statement 8 | Npar = 3; 9 | VarLow=[-5.12 -5.12 -5.12]; 10 | VarHigh = [5.12 5.12 5.12]; 11 | 12 | % parameters 13 | N = 100; % population size 14 | G = 100; % Number of generations 15 | cx = 0.5; %Crossover length 16 | Pmut = 0.12; %probability of mutation 17 | res = 3; %resolution of the problem (10^-res) 18 | 19 | % calculate bias if the lower range is less than 0 20 | off = zeros(1,Npar); 21 | for ii = 1:Npar 22 | if VarLow(ii) <0 23 | off(ii) = 0 - VarLow(ii); 24 | end 25 | end 26 | 27 | % calculate the ideal genome length 28 | gg = zeros(1,Npar); 29 | for ii = 1:Npar 30 | gg(ii) = length(dec2bin((VarHigh(ii)+off(ii))*(10^res))); 31 | end 32 | genl = max(gg); 33 | 34 | % initialize a random value as best value 35 | best = rand(1,Npar).* (VarHigh - VarLow) + VarLow; 36 | bestVal = fitnessFunc(best); 37 | GB = bestVal; 38 | t = cputime; 39 | 40 | 41 | % Initialization of a random population and memory 42 | pop = zeros(N, Npar); 43 | fitness = zeros(N, 1); 44 | for ii=1:N 45 | pop(ii,:) = rand(1,Npar).*(VarHigh - VarLow) + VarLow; 46 | 47 | % calulate the fitness of the population 48 | fitness(ii,:) = fitnessFunc(pop(ii,:)); 49 | end 50 | 51 | %Sorting the population according to their fitness 52 | [fitness,sortind] = sort(fitness); 53 | pop = pop(sortind, :); 54 | 55 | %Generations Loop 56 | for k = 1:G 57 | 58 | % crossover 59 | for i = 1:N 60 | if rand>(i/N) % higher fitness get better chance to mate 61 | j = randperm(N,1); % choose a random member 62 | 63 | % perfrom crossover 64 | offspring = crossover(pop(i,:),pop(j,:),genl,cx,res,off); 65 | 66 | % limit the range within constraints 67 | offspring = limiter(offspring,VarHigh,VarLow); 68 | 69 | % calculate the fitness 70 | fitnessoff = fitnessFunc(offspring); 71 | 72 | % add the offspring to the population 73 | pop=cat(1,pop,offspring); 74 | fitness=cat(1,fitness,fitnessoff); 75 | end 76 | end 77 | 78 | % Mutation 79 | for i = 1:N 80 | if randVarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i)VarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i)0 48 | gsoil(ii,j)=soil(ii,j)-min(soil(:,j)); 49 | else 50 | gsoil(ii,j)=soil(ii,j); 51 | end 52 | end 53 | 54 | %calculate fsoil 55 | es=0.001; 56 | for j=1:Npar 57 | fsoil(ii,j)=1/(es + gsoil(ii,j)); 58 | end 59 | 60 | %calculate probability 61 | for j=1:Npar 62 | p(j)=fsoil(ii,j)/sum(fsoil(ii,:)); 63 | end 64 | 65 | %calculate Velocity 66 | for j=1:Npar 67 | Viwd(j)=av/(bv +cv +(soil(ii,j))^2); 68 | end 69 | 70 | HUD=abs(mean(soil)-soil(ii,:)); 71 | 72 | time=HUD./Viwd; 73 | 74 | %calculate delsoil 75 | delsoil=as./(bs+(cs*time)); 76 | 77 | %update the soil postion 78 | soil(ii,:)=soil(ii,:) + delsoil; 79 | 80 | %check constraints 81 | soil(ii,:)=limiter(soil(ii,:),VarHigh,VarLow); 82 | 83 | %find fitness 84 | F(ii)=fitnessFunc(soil(ii,:)); 85 | 86 | %check for optimality 87 | if F(ii)VarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i)VarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i)VarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i) 0 49 | F(ii) = 1/(1+Fit(ii)); 50 | else 51 | F(ii) = 1 + abs(Fit(ii)); 52 | end 53 | end 54 | Fsum=sum(F); % sum of F 55 | 56 | % calculate probability of each bower 57 | prob = F/sum(F); 58 | 59 | oldpop = pop; 60 | oldfit = Fit; 61 | 62 | %deterministic changes 63 | for ii=1:nb 64 | for k = 1:Npar 65 | %select a target bower 66 | target = Roulette(prob); 67 | 68 | % calculate step size 69 | lambda = alpha/(1+prob(ii)); 70 | 71 | % update bower 72 | pop(ii,k) = pop(ii,k) + lambda*(((pop(target,k) + BestSol(k))/2) - pop(ii,k)); 73 | 74 | %mutation 75 | if randVarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i)VarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i)VarHigh(i) 9 | newP(i)=VarHigh(i); 10 | elseif newP(i)