File Exchange

image thumbnail

Grey Wolf Optimizer (GWO)

version 1.6 (1.85 MB) by Seyedali Mirjalili
GWO is a novel meta-heuristic algorithm for global optimization

164 Downloads

Updated 22 May 2018

View License

The GWO algorithm mimics the leadership hierarchy and hunting mechanism of grey wolves in nature. Four types of grey wolves such as alpha, beta, delta, and omega are employed for simulating the leadership hierarchy. In addition, three main steps of hunting, searching for prey, encircling prey, and attacking prey, are implemented to perform optimization.
This is the source codes of the paper: S. Mirjalili, S. M. Mirjalili, A. Lewis, Grey Wolf Optimizer, Advances in Engineering Software, Volume 69, March 2014, Pages 46-61, ISSN 0965-9978, http://dx.doi.org/10.1016/j.advengsoft.2013.12.007.
More information can be found in: http://www.alimirjalili.com/GWO.html
You can find the Grey Wolf optimizer Toolbox here: http://www.mathworks.com/matlabcentral/fileexchange/47258-grey-wolf-optimizer-toolbox
Other relevant submissions: https://au.mathworks.com/matlabcentral/fileexchange/49772-grey-wolf-optimizer-for-training-multi-layer-perceptrons
I have a number of relevant courses in this area. You can enrol via the following links with 95% discount:

*******************************************************************************************************************************************
A course on “Optimization Problems and Algorithms: how to understand, formulation, and solve optimization problems”:
https://www.udemy.com/optimisation/?couponCode=MATHWORKSREF

A course on “Introduction to Genetic Algorithms: Theory and Applications”
https://www.udemy.com/geneticalgorithm/?couponCode=MATHWORKSREF
*******************************************************************************************************************************************

Cite As

Seyedali Mirjalili (2020). Grey Wolf Optimizer (GWO) (https://www.mathworks.com/matlabcentral/fileexchange/44974-grey-wolf-optimizer-gwo), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (40)

Surbhi Rai

Check out my github, I implemented this algorithm in Python (Numpy) for better performance.
https://github.com/thieunguyen5991/metaheuristics

abrha hiluf

hey my dear how can i use the GWO for micro grid optimization please if you can send the source code than for your support

Wenhao Che

how to put constraint in this program

Hi Sir,
Can we apply GWO in Image fusion (Frequency dmain), If so how to tailor?

seven z

hello,Sir

Why is the result of Best_pos different every time I run the program? I am looking forward to your reply!

seven z

hello,Sir

Why is the result of Best_pos different every time I run the program? I am looking forward to your reply!

clear all
clc

SearchAgents_no=20; % Number of search agents

func_name='DG1'; % Name of the test function that can be from F1 to F23 (Table 1,2,3 in the paper)

Max_iteration=100; % Maximum number of iterations

% Load details of the selected benchmark function
[lb,ub,dim,fobj]=Get_Functions_details('DG1');

[Best_score,Best_pos,GWO_cg_curve]=GWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);

figure('Position',[500 500 660 290])
%Draw search space
subplot(1,2,1);
% func_plot(func_name);
title('Parameter space')
xlabel('x_1');
ylabel('x_2');
zlabel([func_name,'( x_1 , x_2 )'])
%
% %Draw objective space
% subplot(1,2,2);
% semilogy(GWO_cg_curve,'Color','r')
% title('Objective space')
% xlabel('Iteration');
% ylabel('Best score obtained so far');

% axis tight
% grid on
% box on
% legend('GWO')

display(['The best solution obtained by GWO is : ', num2str(Best_pos)]);
display(['The best optimal value of the objective funciton found by GWO is : ', num2str(Best_score,'%10.9e\n')]);
it's error line # 47 can anybody tell me

Hi,
I'm working in IEEE-14,33 & 69 bus system and i want apply in GWO can anybody tell me how can put values GWO in mat-lab

check out hybrid GWO & PSO code at https://in.mathworks.com/matlabcentral/fileexchange/68776-hybrid-gwopso-optimization for better performance

Taief Alaa

Hello sir,
please, I would like to use GWo to select the optimum RBF (sigma,c) parameter for the SVM classifier.
but I don't know how to change the code to solve my problem.

please, can you give me any hints or the code?
my regards.

hello all
i have applied this GWO technique in LFC problem.
iam geeting the error as
??? Subscript indices must either be real positive integers or logicals.

Error in ==> GWO at 50
fitness=fobj(Positions(i,:));
can any one resolve my error so that it will be helpful for me

I used GWO but I want to add constaint that sum of all variables sgould be one ...I am not getting how to implement constraint in GWO?

Hi Seyedali, can you apply GWO on offshore structure optimization? If so, how do you tailor it?

Immad Shams

Dear the GWO main matlab file doesnt take fobj. what is that? is it 'F1','F2' .....?

eric githua

eric githua

hello
I want the code for the Grey Wolves algorithm written in a language MATLAB , please.

syed ali

Sir how to input objective function

how can we compute the x_p of prey in GWO. as well as, what the role of x_p in GWO.

hello seyedali sir, thanks for the code, i want to incorporate equality constraint ,for an example, if demand pd=100 MW, generation should be 100 MW, can you kindly provide solution to this problem.Thanks sir, i will wait for your reply.

wallace liu

hi sir, can this GWO solve Economic Dispatch problem? are thier any matlab code for this??

NANCY SIDHU

hello sir, first of all, congratulations! For this awesome technique. One question: when i use my objective function in this code. The global best score does not changes with iterations. For eg, if i have taken 100 iterations the value at 1st iteration, in between iterations and last iteration remain same. Any suggestions sir?

hi sir
the source code is not updated yet
please I need it as soon as possible

Hi . Sir

i want to ask you about code of GWO-EPD?

Hafiz

hi sir, can this GWO solve Economic Load Dispatch problem?

Hi Amr Hessan,

My thanks for identifying this issue. You are right. Every time alpha updates, we have to update beta and delta and well. I will consider this and update the files soon.

Amr Hassan

Hi, Thanks for your code. good job
just have one concern. and please correct me if I was wrong. when updating Alpha, Beta and Delta Positions and score
[quote]
fitness=fobj(Positions(i,:)); %Amr: best_tour = calculate tour length in tsp
% Update Alpha, Beta, and Delta
if fitness<Alpha_score
Alpha_score=fitness; % Update alpha
Alpha_pos=Positions(i,:);
end
if fitness>Alpha_score && fitness<Beta_score
Beta_score=fitness; % Update beta
Beta_pos=Positions(i,:);
end
if fitness>Alpha_score && fitness>Beta_score && fitness<Delta_score
Delta_score=fitness; % Update delta
Delta_pos=Positions(i,:);
end
[/quote]
this doesn't correctly update Beta and Delta. consider this scenario:
for example, after 3rd iteration alpha_score=1000, Beta_score=1200, Delta_score=1500
if the fitness of 4th iteration is 800 then alpha_score will be updated and beta_score will remain 1200 while it should be 1000 and the same for delta_score
proposed correction,

[quote]
fitness=fobj(Positions(i,:)); %Amr: best_tour = calculate tour length in tsp
% Update Alpha, Beta, and Delta
if fitness<Alpha_score
Beta_score=Alpha_score;
Beta_pos=Alpha_pos;
Alpha_score=fitness; % Update alpha
Alpha_pos=Positions(i,:);
end
if fitness>Alpha_score && fitness<Beta_score
Delta_score=Beta_score;
Delta_pos=Beta_pos;
Beta_score=fitness; % Update beta
Beta_pos=Positions(i,:);
end
if fitness>Alpha_score && fitness>Beta_score && fitness<Delta_score
Delta_score=fitness; % Update delta
Delta_pos=Positions(i,:);
end
[/quote]

iman

Ander Biguri

An heuritic algorthm based on Grey wolf behavior. WOW. Just WOW.

Hi Dalia,

This problem originates from your F5 function.

o=(100*(x(2:dim)-(x(1:dim-1).^2)).^2+(1-x(1:dim-1)).^2) returns a vector, while there should be a single fitness value for each search agent.
The formula for the F5 function has a sum in front of the expression as follows:
o=sum(100*(x(2:dim)-(x(1:dim-1).^2)).^2+(x(1:dim-1)-1).^2);

Generally speaking, each search agent should be assigned with only one fitness value.

Change your F5 function so that it returns a single value for each input vector, give it a try, and let me know.

Ali

i try to solve this eq
function o = F5(x)
dim=size(x,2);
o=(100*(x(2:dim)-(x(1:dim-1).^2)).^2+(1-x(1:dim-1)).^2);
end

case 'F5'
fobj = @F5;
lb=-[-1.5,-2];
ub=[2,2];
dim=2;
give me error

Operands to the || and && operators must be convertible to logical scalar values.

Error in GWO (line 51)
if fitness>Alpha_score && fitness<Beta_score

Error in main (line 45)
[Best_score,Best_pos,GWO_cg_curve]=GWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
pls help me

Daniil,

You are right, some search agents may go beyond the boundaries of the search space in the last iteration and there is no more chance for them to be returned back to the search space. I moved position boundary checking to the end of the second for loop (right after updating the positions). I have also updated the source file accordingly.

Thanks for that and please let me know if there was any other issue.

Daniil

Ali, when you enter the loop for a 1st run, your data is in the bounds apriori (because it is just generated). And when you did the _last_ loop iteration you may have some search agents not in the bounds, so when you look in the final Positions, you may find incorrect data.
I found this when I tried to work with search agents with integer values: my bounds were 1..10, but after the last loop iteration I got few agents with 0's. Maybe for real values it will be not so significant.

Hi Daniil,

Thanks for your compliment and comment. I think the current codes work correctly because it is important to return back the search agents that go beyond the boundaries when you want to calculate their "fitnesses". I agree with you that we can do this at the end of the second for loop where the positions are updated or at the top of the firs for loop. However, the important issue here is that the boundary checking should be done right before updating the fitnesses. I hope these make sense. Once again, thanks for your vigilance and pointing out this matter.

Regards,
Ali

Daniil

Hi. Great optimizer. Thank you.
I found one issue: we need to do "Return back the particles that go beyond the boundaries of the search" at the bottom of "for" loop, but not at the top.

Updates

1.6

Links added:
https://www.udemy.com/optimisation/?couponCode=MATHWORKSREF
https://www.udemy.com/geneticalgorithm/?couponCode=MATHWORKSREF

1.6.0.0

typo

1.6.0.0

A link has been added to the description

1.5.0.0

This submission is now available as a Toolbox file in R2014b.

1.4.0.0

Typo fixed

1.3.0.0

The paper has been included in the submission.

1.2.0.0

A link to the GWO toolbox was added.

1.1.0.0

An issue in boundary checking was resolved and the source filed have been updated.

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux