version 1.0.0.0 (2.9 KB) by
Xin-She Yang

This is a demo for Bat Algorithm, developed by Xin-She Yang (2010).

This is a short demo for the popular, nature-inspired/metaheuristic,

bat algorithm (BA), which can deal with nonlinear, global optimization problems.

Bat algorithm has the advantages of simplicity, flexility and stability.

It can also automatically switch from global exploration to

local exploitation by fine-tuning its parameters: A and r.

The paper can be downloaded at

http://arxiv.org/abs/1004.4170

Xin-She Yang (2021). Bat algorithm (demo) (https://www.mathworks.com/matlabcentral/fileexchange/37582-bat-algorithm-demo), MATLAB Central File Exchange. Retrieved .

Created with
R14

Compatible with any release

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.

Taha ButtHello Yang, in your file what does rand(1,d) implies? i think it is the population that you set to 1 in n=input(1) . you told in the code to write the population between 20 to 40 but, why you didnt write it by yourself? i am trying yo write the population 20 instead of 1 but it would not let me.

Haydar KhayouThank you very much Dr. Yang, but I've been trying to write a Matlab code following the steps provided by your book, and I have found that the rate of pulse emission should increase with iterations, but it's decreasing in the code!!!

another important thing is why to link the choosing of new better solution with a decreasing probability!!

Iran Cidadedjim djimhello,

The BAT algorithm Source Code , do not converge for any benchMark function!!

djim djimwenbin Leonjianlu huMohamed KamelAbhishek GuptaThe complete implementation of BAT algorithm is available at https://in.mathworks.com/matlabcentral/fileexchange/68981-bat-optimization-algorithm

SAID ZAKARIA SAIDHello Prof Xin-She Yang

How to hybridize BAT algorithm with Moth-Flame Optimization Algorithm if you have them in different scripts.

email: djiddosaid@gmail.com

Thank you so much

Adda Saffiedear proffesor,

I am very interested in bat algorithm and decided to use it in my final year project for improvement in global optimazation problems.

can you send the bat algorithm code to me so that i could study it. Thank you.

email: suhadasaffie95@gmail.com

upendra bajpaiplease someone explain why we have chosen here dimension d & what it indicates.

Pranay Rayanahello,

I did not understand this code. Can't we create an environment and view the shortest path like in Probabilistic Road Map (PRM)?

And what does the dimension mean in this code?

Please help me..

mingzhu zhangif (Fnew<=Fitness(i)) & (rand<A) ,

Sol(i,:)=S(i,:);

Fitness(i)=Fnew

end

Why accept a better solution with a certain probability? And This probability becomes smaller and smaller as the number of iterations increases

wanghu wanghuThank you for your share of Dr. Yang.

Yang Liif (rand < Ai & f(xi) < f(x))

Accept the new solutions

Increase ri and reduce Ai

end if

in the article of Dr. Yang, but the code is different. I need a great code of Matlab . Thank you! 263211434@qq.com

Luis LopezjkthinkI noticed that problem as well. Your solution seems to work, though it would have been great if Dr. Yang could provide with a formal solution. 835441346@qq.com

Mahima jI want a solution matlab code modified bat algorithm

asharani belankeHello..can u plz help to write a code for minimize the total cost.actually my Ain is allocation of battery in microgrid.and I am extremely new in MATLAB.

ronit agarwali want bat algorithm and code for clustering in java.........

Adore RuzvidzoDear Prof

Im a maths student an I have found Bat algorithm to interesting would like so much to know if the Bat Inspired algorithm can be of any use in the fields of Electrical distribution and Transmission.

Email:2016sors@gmail.com

akradore@gmail.com

zhen lidear prof

I am very interested in bat algorithm.

can you send the bat algorithm code to me?

e-mail

zhenli_ysu@126.com

thank you

dalia elkashefdear prof

can you help me with chaotic bat algorithm code ??

e-mail

eng.daliaarafa@gmail.com

thanks in advance

yi'xing wangpayam babanShramana GSI Have a Question. Everytime I run this algorithm, I get different sets of solutions every time. Why is it so? Shouldn't there be a unique solution for a given problem? Plz Help.

Sindhuja Jbaibhav bishalkarimHello

@ Eric : In the article published by Dr. Yang, he did not specify that “epsilon” must be a uniform random number.

Comparing the proposed demo and the pseudo-code presented in the article of Dr. Yang, I noticed this:

In the article: if (rand < Ai & f(xi) < f(x*)) and x* is the current global best location (solution) which is located after comparing all the solutions among all the n bats. But, in the demo,

if (Fnew<=Fitness(i)) & (rand<A),

Sol(i,:)=S(i,:);

Fitness(i)=Fnew;

end

I understand from this that for each bat, we do a comparaison between the new calculated fitness values against the previous one, not against the global best. Then, each bat memorises his "individual" best location and update it according to the condition mentionned above. I hope that i will have clarification about this.

EricThere are three discrepancies in this code (compared to the published algorithm)

1. Line 79

Q(i)=Qmin+(Qmin-Qmax)*rand;

should be replaced with

Q(i)=Qmin+(Qmax-Qmin)*rand;

2. Similar to what @Frank said

Line 83

Sol(i,:)=simplebounds(Sol(i,:),Lb,Ub);

should be replaced with

S(i,:)=simplebounds(S(i,:),Lb,Ub);

and moved to Line 89 (*before* %Evaluate Evaluate new solutions)

3. Line 87

S(i,:)=best+0.001*randn(1,d);

The 2010 paper "A New Metaheuristic Bat-Inspired Algorithm" seems to suggest that 0.001 should be the variable "A" and that randn(1,d) should actually be 1-2*rand(1,d)... that is a uniformly distributed random number bounded by [-1,1].

leoc@Frank,

I noticed that problem as well. Your solution seems to work, though it would have been great if Dr. Yang could provide with a formal solution.

AmonHello

I have my Objective function and constraint, anyone can help me to guide me on how implement it.

Actually mu purpose is reduce electric distribution loss.

acharabIt is good.

FrankWould this line of code in bat_algorithm.m:

% Apply simple bounds/limits

Sol(i,:)=simplebounds(Sol(i,:),Lb,Ub);

be moved to just above the line of

% Evaluate new solutions

and be modified to:

S(i,:)=simplebounds(S(i,:),Lb,Ub);

so that we may not have solutions outside the lower and upper bound?

huiEasy to understand...

Al AlgoVery easy to understand but works magic.

pengIt is easy to understand, and it works magic. Excellent!

winsimple and easy of use.... thanks

sehrishI am interest in your optimization algorithm. May i know is there a 'train' function coded because I would want to use it to train neural network.

Thank you.

sehrishHi plz anyone can guide how to train Neural Network using Bat algorithm????

d galso how to get graphs for bat algorithm..?

d ghey i want to compare cuckoo search and bat algorithm.. can you tell me on what parameters should i compare them..

teroy tmanIt is very good.

Q QIt is easy to understand, and it works magic. Excellent!