View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Bat algorithm (demo)

4.5 | 13 ratings Rate this file 106 Downloads (last 30 days) File Size: 2.9 KB File ID: #37582 Version: 1.0

Bat algorithm (demo)


Xin-She Yang (view profile)


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

| Watch this File

File Information

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

Required Products MATLAB
MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (27)
16 Feb 2017 Mahima j

I want a solution matlab code modified bat algorithm

Comment only
29 Dec 2016 asharani belanke

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

Comment only
23 Dec 2016 ronit agarwal

i want bat algorithm and code for clustering in java.........

21 Dec 2016 Adore Ruzvidzo

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

13 Dec 2016 zhen li

dear prof
I am very interested in bat algorithm.
can you send the bat algorithm code to me?

thank you

Comment only
04 Oct 2016 dalia elkashef

dear prof

can you help me with chaotic bat algorithm code ??

thanks in advance

06 Jun 2016 yi'xing wang

25 Mar 2016 payam baban

28 Feb 2016 Shramana GS

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

Comment only
27 Jan 2016 Sindhuja J

22 Jan 2016 baibhav bishal

14 Oct 2015 karim

karim (view profile)

@ 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),
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.

Comment only
27 Sep 2015 Eric

Eric (view profile)

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

1. Line 79

should be replaced with

2. Similar to what @Frank said
Line 83

should be replaced with
and moved to Line 89 (*before* %Evaluate Evaluate new solutions)

3. Line 87

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

Comment only
29 Jul 2015 leoc

leoc (view profile)


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.

19 Nov 2014 Amon

Amon (view profile)

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.

Comment only
25 Jun 2014 acharab

It is good.

Comment only
15 May 2014 Frank

Frank (view profile)

Would this line of code in bat_algorithm.m:

% Apply simple bounds/limits

be moved to just above the line of
% Evaluate new solutions

and be modified to:

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

Comment only
03 Apr 2014 hui

hui (view profile)

Easy to understand...

25 Mar 2014 Al Algo

Very easy to understand but works magic.

13 Nov 2013 peng

peng (view profile)

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

08 Aug 2013 godwin tgn

simple and easy of use.... thanks

02 Jun 2013 sehrish

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

Comment only
27 Apr 2013 sehrish

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

Comment only
26 Oct 2012 d g

d g (view profile)

also how to get graphs for bat algorithm..?

Comment only
26 Oct 2012 d g

d g (view profile)

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

Comment only
31 Jul 2012 teroy tman

It is very good.

Comment only
22 Jul 2012 Q Q

Q Q (view profile)

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

Contact us