version 1.6 (1.85 MB) by
Seyedali Mirjalili

GWO is a novel meta-heuristic algorithm for global optimization

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

*******************************************************************************************************************************************

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

Created with
R2011b

Compatible with any release

**Inspired:**
A new MATLAB optimization toolbox, Multi-Objective Grey Wolf Optimizer (MOGWO), Constrained GWO-pressure vessel design optimization

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!Create scripts with code, output, and formatted text in a single executable document.

Sophia OwaisHi can you please help me with the code for Optimal Power Flow for a 30 Bus system?

I have the data and finding some difficulty in interrelating,I would be thankful

email: sophiaowaisbhatti@gmail.com

Sophia Owaissophiaowaisbhatti@gmail.com

aarthi arunagirihi sir,i can you please help me with the code for dynamic load dispatch for a simple 3 or 5 generator plant sir?

i got the data and finding some coding difficulty sir,I would be thankful

email:aarthiarunnaga@gmail.com

Flynn MosellySir i wana Grey Wolf Optimization MATLAB CODE please

Email: flynnmoselly@yahoo.fr

RAJESH PALAPARTHISir

Gray wolf optimization technique matlab code

Email : palaparthirajesh351@gmail.com

cy yangHi, how to set the optimal parameter selected by the gray wolf algorithm to an integer, because the input of the objective function is an integer. Thank you.

mahesh parimalaDear sir, Can you please explain how to create search history plot which is given in the paper.

E-Mail: g.sravan278@gmail.com

king wexiai wonder if it can apply to the robot path planning, but i havent found the code yet

Surbhi RaiNguyen ThieuCheck out my github, I implemented this algorithm in Python (Numpy) for better performance.

https://github.com/thieunguyen5991/metaheuristics

abrha hilufhey 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 Cheaayush shrivastavahow to put constraint in this program

Ratheesh P MHi Sir,

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

seven zhello,Sir

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

seven zhello,Sir

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

Muhammad Ansariclear 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

Muhammad AnsariHi,

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

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

Taief AlaaHello 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.

V S R PAVAN KUMAR NEELIhello 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

maria tamoorI 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?

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

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

eric githuaeric githuaEkhlad Altaiihello

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

Kamalova Albinasyed aliSir how to input objective function

mohamed abu eitahow can we compute the x_p of prey in GWO. as well as, what the role of x_p in GWO.

Ajay Bhardwajhello 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.

Ajay Bhardwajwallace liuenas malkawihi sir, can this GWO solve Economic Dispatch problem? are thier any matlab code for this??

NANCY SIDHUhello 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?

marwa marwanhi sir

the source code is not updated yet

please I need it as soon as possible

dalia elkashefHi . Sir

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

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

Seyedali MirjaliliHi 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 HassanHi, 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]

imanAnder BiguriAn heuritic algorthm based on Grey wolf behavior. WOW. Just WOW.

Seyedali MirjaliliHi 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

dalia elkashefi 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

Seyedali MirjaliliDaniil,

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.

DaniilAli, 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.

Seyedali MirjaliliHi 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

DaniilHi. 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.