-
Notifications
You must be signed in to change notification settings - Fork 7
/
BOA.m
98 lines (77 loc) · 3.49 KB
/
BOA.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
%_____________________________________________________________________________________________ %
% Butterfly Optimization Algorithm (BOA) source codes demo V1.0 %
% %
% Author and programmer: Sankalap Arora %
% %
% e-Mail: [email protected] %
% %
% Main paper: Sankalap Arora, Satvir Singh %
% Butterfly optimization algorithm: a novel approach for global optimization %
% Soft Computing, in press, %
% DOI: https://doi.org/10.1007/s00500-018-3102-4 %
%___________________________________________________________________________________________ %
%
function [fmin,best_pos,Convergence_curve]=BOA(n,N_iter,Lb,Ub,dim,fobj)
% n is the population size
% N_iter represnets total number of iterations
p=0.8; % probabibility switch
power_exponent=0.1;
sensory_modality=0.01;
%Initialize the positions of search agents
Sol=initialization(n,dim,Ub,Lb);
for i=1:n,
Fitness(i)=fobj(Sol(i,:));
end
% Find the current best_pos
[fmin,I]=min(Fitness);
best_pos=Sol(I,:);
S=Sol;
% Start the iterations -- Butterfly Optimization Algorithm
for t=1:N_iter,
for i=1:n, % Loop over all butterflies/solutions
%Calculate fragrance of each butterfly which is correlated with objective function
Fnew=fobj(S(i,:));
FP=(sensory_modality*(Fnew^power_exponent));
%Global or local search
if rand<p,
dis = rand * rand * best_pos - Sol(i,:); %Eq. (2) in paper
S(i,:)=Sol(i,:)+dis*FP;
else
% Find random butterflies in the neighbourhood
epsilon=rand;
JK=randperm(n);
dis=epsilon*epsilon*Sol(JK(1),:)-Sol(JK(2),:);
S(i,:)=Sol(i,:)+dis*FP; %Eq. (3) in paper
end
% Check if the simple limits/bounds are OK
S(i,:)=simplebounds(S(i,:),Lb,Ub);
% Evaluate new solutions
Fnew=fobj(S(i,:)); %Fnew represents new fitness values
% If fitness improves (better solutions found), update then
if (Fnew<=Fitness(i)),
Sol(i,:)=S(i,:);
Fitness(i)=Fnew;
end
% Update the current global best_pos
if Fnew<=fmin,
best_pos=S(i,:);
fmin=Fnew;
end
end
Convergence_curve(t,1)=fmin;
%Update sensory_modality
sensory_modality=sensory_modality_NEW(sensory_modality, N_iter);
end
% Boundary constraints
function s=simplebounds(s,Lb,Ub)
% Apply the lower bound
ns_tmp=s;
I=ns_tmp<Lb;
ns_tmp(I)=Lb;
% Apply the upper bounds
J=ns_tmp>Ub;
ns_tmp(J)=Ub;
% Update this new move
s=ns_tmp;
function y=sensory_modality_NEW(x,Ngen)
y=x+(0.025/(x*Ngen));