├── BOA.m ├── Get_Functions_details.m ├── initialization.m └── main.m /BOA.m: -------------------------------------------------------------------------------- 1 | %_____________________________________________________________________________________________ % 2 | % Butterfly Optimization Algorithm (BOA) source codes demo V1.0 % 3 | % % 4 | % Author and programmer: Sankalap Arora % 5 | % % 6 | % e-Mail: sankalap.arora@gmail.com % 7 | % % 8 | % Main paper: Sankalap Arora, Satvir Singh % 9 | % Butterfly optimization algorithm: a novel approach for global optimization % 10 | % Soft Computing, in press, % 11 | % DOI: https://doi.org/10.1007/s00500-018-3102-4 % 12 | %___________________________________________________________________________________________ % 13 | % 14 | function [fmin,best_pos,Convergence_curve]=BOA(n,N_iter,Lb,Ub,dim,fobj) 15 | 16 | % n is the population size 17 | % N_iter represnets total number of iterations 18 | p=0.8; % probabibility switch 19 | power_exponent=0.1; 20 | sensory_modality=0.01; 21 | 22 | %Initialize the positions of search agents 23 | Sol=initialization(n,dim,Ub,Lb); 24 | 25 | for i=1:n, 26 | Fitness(i)=fobj(Sol(i,:)); 27 | end 28 | 29 | % Find the current best_pos 30 | [fmin,I]=min(Fitness); 31 | best_pos=Sol(I,:); 32 | S=Sol; 33 | 34 | % Start the iterations -- Butterfly Optimization Algorithm 35 | for t=1:N_iter, 36 | 37 | for i=1:n, % Loop over all butterflies/solutions 38 | 39 | %Calculate fragrance of each butterfly which is correlated with objective function 40 | Fnew=fobj(S(i,:)); 41 | FP=(sensory_modality*(Fnew^power_exponent)); 42 | 43 | %Global or local search 44 | if rand
Ub; 89 | ns_tmp(J)=Ub; 90 | % Update this new move 91 | s=ns_tmp; 92 | 93 | 94 | function y=sensory_modality_NEW(x,Ngen) 95 | y=x+(0.025/(x*Ngen)); 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /Get_Functions_details.m: -------------------------------------------------------------------------------- 1 | %_____________________________________________________________________________________________ % 2 | % Butterfly Optimization Algorithm (BOA) source codes demo V1.0 % 3 | % % 4 | % Author and programmer: Sankalap Arora % 5 | % % 6 | % e-Mail: sankalap.arora@gmail.com % 7 | % % 8 | % Main paper: Sankalap Arora, Satvir Singh % 9 | % Butterfly optimization algorithm: a novel approach for global optimization % 10 | % Soft Computing, in press, % 11 | % DOI: https://doi.org/10.1007/s00500-018-3102-4 % 12 | %___________________________________________________________________________________________ % 13 | % 14 | % lb is the lower bound 15 | % up is the uppper bound 16 | % dim is the number of variables 17 | function [lb,ub,dim,fobj] = Get_Functions_details(F) 18 | 19 | switch F 20 | case 'F1' 21 | fobj = @F1; 22 | lb=-100; 23 | ub=100; 24 | dim=30; 25 | end 26 | 27 | end 28 | 29 | function o = F1(x) 30 | o=sum(x.^2); 31 | end 32 | 33 | 34 | -------------------------------------------------------------------------------- /initialization.m: -------------------------------------------------------------------------------- 1 | %_____________________________________________________________________________________________ % 2 | % Butterfly Optimization Algorithm (BOA) source codes demo V1.0 % 3 | % % 4 | % Author and programmer: Sankalap Arora % 5 | % % 6 | % e-Mail: sankalap.arora@gmail.com % 7 | % % 8 | % Main paper: Sankalap Arora, Satvir Singh % 9 | % Butterfly optimization algorithm: a novel approach for global optimization % 10 | % Soft Computing, in press, % 11 | % DOI: https://doi.org/10.1007/s00500-018-3102-4 % 12 | %___________________________________________________________________________________________ % 13 | % 14 | 15 | % This function randomly initializes the position of agents in the search space. 16 | function [X]=initialization(N,dim,up,down) 17 | 18 | if size(up,1)==1 19 | X=rand(N,dim).*(up-down)+down; 20 | end 21 | if size(up,1)>1 22 | for i=1:dim 23 | high=up(i);low=down(i); 24 | X(:,i)=rand(1,N).*(high-low)+low; 25 | end 26 | end -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | %_____________________________________________________________________________________________ % 2 | % Butterfly Optimization Algorithm (BOA) source codes demo V1.0 % 3 | % % 4 | % Author and programmer: Sankalap Arora % 5 | % % 6 | % e-Mail: sankalap.arora@gmail.com % 7 | % % 8 | % Main paper: Sankalap Arora, Satvir Singh % 9 | % Butterfly optimization algorithm: a novel approach for global optimization % 10 | % Soft Computing, in press, % 11 | % DOI: https://doi.org/10.1007/s00500-018-3102-4 % 12 | %___________________________________________________________________________________________ % 13 | % 14 | 15 | clear all 16 | clc 17 | warning off all 18 | 19 | SearchAgents_no=30; % Number of search agents 20 | Max_iteration=500; % Maximum number of iterations 21 | 22 | Function_name='F1'; 23 | 24 | [lb,ub,dim,fobj]=Get_Functions_details(Function_name); 25 | 26 | [Best_score,Best_pos,cg_curve]=BOA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj); 27 | 28 | semilogy(cg_curve,'Color','r') 29 | title('Convergence curve') 30 | xlabel('Iteration'); 31 | ylabel('Best score obtained so far'); 32 | 33 | axis tight 34 | grid off 35 | box on 36 | legend('BOA') 37 | 38 | display(['The best solution obtained by BOA is : ', num2str(Best_pos)]); 39 | display(['The best optimal value of the objective funciton found by BOA is : ', num2str(Best_score)]); 40 | 41 | 42 | --------------------------------------------------------------------------------