Skip to content

Commit addb3d0

Browse files
authored
Add files via upload
0 parents  commit addb3d0

File tree

7 files changed

+696
-0
lines changed

7 files changed

+696
-0
lines changed

GWO.m

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
%___________________________________________________________________%
2+
% Grey Wolf Optimizer (GWO) source codes version 1.0 %
3+
% %
4+
% Developed in MATLAB R2011b(7.13) %
5+
% %
6+
% Author and programmer: Seyedali Mirjalili %
7+
% %
8+
% e-Mail: [email protected] %
9+
10+
% %
11+
% Homepage: http://www.alimirjalili.com %
12+
% %
13+
% Main paper: S. Mirjalili, S. M. Mirjalili, A. Lewis %
14+
% Grey Wolf Optimizer, Advances in Engineering %
15+
% Software , in press, %
16+
% DOI: 10.1016/j.advengsoft.2013.12.007 %
17+
% %
18+
%___________________________________________________________________%
19+
20+
% Grey Wolf Optimizer
21+
function [Alpha_score,Alpha_pos,Convergence_curve]=GWO(SearchAgents_no,Max_iter,lb,ub,dim,fobj)
22+
23+
% initialize alpha, beta, and delta_pos
24+
Alpha_pos=zeros(1,dim);
25+
Alpha_score=inf; %change this to -inf for maximization problems
26+
27+
Beta_pos=zeros(1,dim);
28+
Beta_score=inf; %change this to -inf for maximization problems
29+
30+
Delta_pos=zeros(1,dim);
31+
Delta_score=inf; %change this to -inf for maximization problems
32+
33+
%Initialize the positions of search agents
34+
Positions=initialization(SearchAgents_no,dim,ub,lb);
35+
36+
Convergence_curve=zeros(1,Max_iter);
37+
38+
l=0;% Loop counter
39+
40+
% Main loop
41+
while l<Max_iter
42+
for i=1:size(Positions,1)
43+
44+
% Return back the search agents that go beyond the boundaries of the search space
45+
Flag4ub=Positions(i,:)>ub;
46+
Flag4lb=Positions(i,:)<lb;
47+
Positions(i,:)=(Positions(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;
48+
49+
% Calculate objective function for each search agent
50+
fitness=fobj(Positions(i,:));
51+
52+
% Update Alpha, Beta, and Delta
53+
if fitness<Alpha_score
54+
Alpha_score=fitness; % Update alpha
55+
Alpha_pos=Positions(i,:);
56+
end
57+
58+
if fitness>Alpha_score && fitness<Beta_score
59+
Beta_score=fitness; % Update beta
60+
Beta_pos=Positions(i,:);
61+
end
62+
63+
if fitness>Alpha_score && fitness>Beta_score && fitness<Delta_score
64+
Delta_score=fitness; % Update delta
65+
Delta_pos=Positions(i,:);
66+
end
67+
end
68+
69+
70+
a=2-l*((2)/Max_iter); % a decreases linearly fron 2 to 0
71+
72+
% Update the Position of search agents including omegas
73+
for i=1:size(Positions,1)
74+
for j=1:size(Positions,2)
75+
76+
r1=rand(); % r1 is a random number in [0,1]
77+
r2=rand(); % r2 is a random number in [0,1]
78+
79+
A1=2*a*r1-a; % Equation (3.3)
80+
C1=2*r2; % Equation (3.4)
81+
82+
D_alpha=abs(C1*Alpha_pos(j)-Positions(i,j)); % Equation (3.5)-part 1
83+
X1=Alpha_pos(j)-A1*D_alpha; % Equation (3.6)-part 1
84+
85+
r1=rand();
86+
r2=rand();
87+
88+
A2=2*a*r1-a; % Equation (3.3)
89+
C2=2*r2; % Equation (3.4)
90+
91+
D_beta=abs(C2*Beta_pos(j)-Positions(i,j)); % Equation (3.5)-part 2
92+
X2=Beta_pos(j)-A2*D_beta; % Equation (3.6)-part 2
93+
94+
r1=rand();
95+
r2=rand();
96+
97+
A3=2*a*r1-a; % Equation (3.3)
98+
C3=2*r2; % Equation (3.4)
99+
100+
D_delta=abs(C3*Delta_pos(j)-Positions(i,j)); % Equation (3.5)-part 3
101+
X3=Delta_pos(j)-A3*D_delta; % Equation (3.5)-part 3
102+
103+
Positions(i,j)=(X1+X2+X3)/3;% Equation (3.7)
104+
105+
end
106+
end
107+
l=l+1;
108+
Convergence_curve(l)=Alpha_score;
109+
end
110+
111+
112+

GWO.png

375 KB
Loading

GWO_finalVersion.pdf

1.67 MB
Binary file not shown.

0 commit comments

Comments
 (0)