4.4 | 18 ratings Rate this file 293 Downloads (last 30 days) File Size: 8.84 KB File ID: #29809 Version: 1.3

Cuckoo Search (CS) Algorithm


Xin-She Yang (view profile)


22 Dec 2010 (Updated )

A standard Cuckoo Search is implemented, which is very efficient. There are three versions now.

| Watch this File

File Information

A new metaheuristic optimization algorithm, called Cuckoo Search (CS), is fully implemented, and the vectorized version is given here. This code demonstrates how CS works for unconstrained optimization, which can easily be extended to solve various global optimization problems efficiently.

Three versions are provided:
Cuckoo_search.m is for a given tolerance.
Cuckoo_search_new.m is for a fixed number of iterations.
Cuckoo_search_spring.m is constrained optimization for designing a spring.


This file inspired Acs Cs(L,F,Met).

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 (68)
06 Nov 2015 Denizhan lermi  
28 Oct 2015 Xuhong Yang  
28 Oct 2015 loukil sana

Hello,Xin-She Yang
I am Loukil Sana, a Tunisien student of optimisation engineering.Now i am doing a work on thesis. I have needed your help in it. Can u please tell me how we can implement Cuckoo search in a food traceability problem, exactaly in a batch dispersion problem applied in the Dupuy model (2005).Can you guide me.
My mail id is loukil.sanaa@gmail.com
Many thanks,
Best ragards.

Comment only
19 Aug 2015 noha samir

I would like to know either this cuckoo search can get the optimal values of this function with multiple variable such as this one and what is the boundaries of it.
plesae email me necessary on "eng.noha_on_the_net@hotmail.com"

Maximize Z= 4x1+6x2-2x1^2-2x1x2-2x2^2

subject to x1+2x2<=2

Many thanks for you

23 Jul 2015 Sri Akshaya

Respected Sir we saw ur cuckoo search algorithm for optimization...we r planning to use it in medical field...for feature selection...in identifying the disease with less parameters...can yu please help us in implementing cuckoo search algorithm in feature selection? Can yu please tell us how give the input? And how to use this in xl? And which parameter shud v use sir? Cuckoo's nest or egg or the number of cuckoos?can we use this matlab code as it is or? Please help us with the modified matlab code sir? We will be so thankful sir :)

Comment only
27 Jun 2015 mohamed abu eita

Could any one provide me by CS matlab code for clustering data.txt

Comment only
19 Jun 2015 Mohammad Shehab

Dear Sir, Could I have implementation of Cuckoo Search on White matter fiber tracking, please if it is possible send it through my email
thanks to you

Comment only
13 Jun 2015 Mudasir Ahmed

Dear sir

i want to optimize the distance of three variables from target. here, i take three numbers [10,81,20] and they reach at target 50, mean at the end of iteration all values will be [50,50,50] using cuckoo search algorithm. but unfortunately i didn't find correct response. kindly look at the code and tell me at which step i did wrong, i will be highly thankful to you.


for i=1:50
hold on
grid on
axis([0 100 0 100])
A=[r1 r2 r3];
B=[p1 p2 p3];
[m1 n1]=size(B);
for y=1:n1
if A(1,y)== J;

09 Jun 2015 Chen U-an  
04 Jun 2015 RAHUL SAHU

sir, i am working on a 'Design of a Low Pass FIR filter using Genetic Algorithm & Different optimization technique viz. Particle swarm optimization, Ant colony(ABC) & cuckoo search algorithm" but i don't get any help for PSO & ant colony please sir , anyone give the the PSO .m file or ABC .m file plz help....
my email id: er.rahulmtech@gmail.com

18 May 2015 hu pengfei

Dear Sir
I am a graduate student from xiang tan university in hunan province China, my major focus on the evoultion algorithm, such as Particle swarm optimization (pso). Now, I read some paper about Cuckoo Search (CS) Algorithm, it is an excellent algorithm. At the same time, I want to study improved the Cuckoo Search (CS) Algorithm and combined the CS algorithm with other evoultion algorithm,But I cann't get help from my friends because none of one knows CS algorithm, so could you provide me some matlab code like imporved CS algorithm or Hybrid CS algorithm? In the future, I want to learn deeply CS algorithm and apply it with other production's area, So can you tell me the newest study's direction in CS algorithm? think you. my email is hanwex@163.com

Comment only
01 Apr 2015 mj

mj (view profile)

Dear Sir
I am trying to get a code for binary cuckoo search. is it the same coding with what you are given or differ with that one? where should I modify so that i can insert my data. My project is feature selection on spam detection using cuckoo search algorithm.please help me and email me in maznifarahin@yahoo.com

Comment only
31 Mar 2015 Bolan Nobosse Tafem

Dear sir
I am trying to get a code of CS_New to solve a problem of optimizationin power system.my problem is that i dont know how to define my bounded limits and how to bound the value of capacitor compensators on the algorithm. Also will you please help me by show me how and where to insert my objective function.
please answer me inbox my email is:nobossetafembolan@yahoo.fr

Comment only
27 Mar 2015 kishan yadav

Dear sir,
I am a student of MIET ,Meerut. I would like to implement cuckoo search on the optimization problem.So please help me and send me code on my email id kky999954@gmail.com.

Comment only
23 Nov 2014 rajat sood

Sir,how to link .xls and .xml database to the Matlab program.What is the coding part for this?I will be very thankful if you can solve my problem as I have not been able to do this from many days.

Comment only
16 Nov 2014 badr

badr (view profile)

25 Oct 2014 Shunmugesh

Dear sir,
I am a Ph.D. student at NIT. I would like to implement cuckoo search on the drilling optimization problem.I have regression equation, lower and upper bound of 4 variables and 3 objective functions. Can u please provide me code cuckoo search optimization algorithm for the above,if possible send to my emailid shunmugesh@gmail.com

Comment only
11 Sep 2014 Sijie

Sijie (view profile)

14 Aug 2014 Ghazwan Alsoufi

Dear sir,
I am a Ph.D. student at university of Essex. I would like to implement cuckoo search on the scheduling problem. Just I do not know the possibility of using cuckoo search in my problem. By using CPLEX I could solve small scale of problems. Note that I have a mathematical model with more than 15 variables and some of these variables are binary and 32 constraints. Please could you let me know if I can use cuckoo search to solve these type of problems.
Many thanks.

22 Jul 2014 suman arora

Dear Sir,
I m Ph.D student , can u please help me
I want to apply Cuckoo search after the applying SOM(Self Organizing MAP) in data mining

Comment only
17 Jun 2014 satyendra singh

dear sir can u please provide me code cuckoo search optimization algorithm for job shop scheduling,if possible send me to my emailid satyendra.gla@gmail.com

24 Apr 2014 milad

milad (view profile)

Dear sir
can you please upload cuckoo search code for phase equilibrium calculation.
if possible can you please send it to my mail id : m.abbasi.pche@gmail.com

12 Apr 2014 anu

anu (view profile)

Dear sir,
Can you please upload cuckoo search code for tuning PID controller gain parameters with ITAE objective function.
if possible can u please send it to my mail id: chandu76522@gmail.com

08 Apr 2014 lithika

Can I use the same code for the PID controller gain parameters tuning using cuckoo algorithm?
(previously I tried the same problem using GA,with the objective function as IAE.)

Comment only
08 Jan 2014 madiha

madiha (view profile)

hi! what would be upper and lower bounds if we define it in case of 2d image? what upper lower bounds telling? nd how cann we choose that??
would be grateful for your response ..

04 Jan 2014 Adel

Adel (view profile)

Dear Sir,

Could I have implementation of Cuckoo Search on Edge Detection, please.

if it is possible send it through my email

Yours Sincerely,
Thank you.


Comment only
24 Oct 2013 Harinee T

hi sir
i need modified cuckoo search algorithm code.

Comment only
24 Oct 2013 Harinee T

i need cuckoo search algorithm code. can i have?

Comment only
03 Jul 2013 research scholor

hi sir is it possible to apply cuckoo search in clustering if yes means how to initialize objects and centroids in cuckoo search

Comment only
14 Jun 2013 pengfei Wang

Hi Dr.Yang,
I am a PhD student from Durham University. I am trying to apply your Cuckoo Search algorithm in power system analysis. It works quite well in the initial study.
I am wondering if it is possible that you can explain more about eggs, cuckoos and nests. For example, how will the algorithm work if there are multiple eggs in one nest?
Many thanks!
Best regards,

Comment only
05 Jun 2013 Gurpreet

Hello,Xin-She Yang
I am Gurpreet Singh, student of M.tech Computer science.Now i am doing a work on thesis. I have needed your help in it. Can u please tell me that how we can implement Cuckoo search in a Vehicle Routung Problem.Can you guide me.
My mail id is gurujaswal@gmail.com

Comment only
02 Jun 2013 sehrish

I am interest in your Cuckoo 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
30 Apr 2013 Xin-She Yang

Xin-She Yang (view profile)

Thanks. The fraction (pa) is checked by using the line (find this line in the code):
which provides a vectorized implementation. That is, for n nests, you can check this in one go.

If the condition is true, then you update/replace the solutions by generating new solutions.

Comment only
24 Apr 2013 Zeltni

Zeltni (view profile)

24 Apr 2013 Zeltni

Zeltni (view profile)

Hello, thank you for submetting code
I want to know more about A fraction (pa) of worse nests are abandoned and new ones are built.

Comment only
31 Mar 2013 Saeid

Saeid (view profile)

I want to know if it is possible to use binary or integer decision variables in the objective function or not?

Comment only
16 Jan 2013 SWETHA

SWETHA (view profile)

Hello sir,
I need to implement face recognition based on cuckoo search algorithm for my academic purpose. So please can you help to implement.

10 Jan 2013 setareh

hello sir
i need the multi-objective cuckoo search MOCS matlab codes for my thesies

can you put these codes in internet?

Comment only
06 Dec 2012 setareh

hello sir

can i use the cuckoo search algorithm for routing problem in computers network?

Comment only
04 Nov 2012 hema

hema (view profile)

can this program be used to find min and max of an objective function

Comment only
04 Nov 2012 hema

hema (view profile)

hello sir,
i want to know if this program works for constrained objective function.
please help

Comment only
31 Oct 2012 Ken Kueh

Has anyone tried to implement this algorithm into 'train' function in neural network; eg. 'trainpso' of particle swarm

Comment only
30 Oct 2012 Lucky

Lucky (view profile)

Hello sir,
i'm actually trying to apply CS to design digital FIR filter. My objective function gives values in a 60*60 matrices. I've changed value of n & nd to 60. but i'm still not sure how to attach my objective function to CS (in line 175) in order to get optimized result. as in your code it takes 1 row at a time and applies 'sum' to get 1 value which is further compared with fitness. but in my problem how am i supposed to get just 1 value to return from 'fobj'. as it doesn't contain 'sum' or any else function. how can i get best value in 1 row to compare to fitness for the optimization of my 60*60 matrices according to CS.
kindly help me, i'll be highly obliged.
Thank You.

Comment only
05 Oct 2012 Xin-She Yang

Xin-She Yang (view profile)

Thanks. Yes, of course, you can use any linear constraints. Strictly speaking, you can use both linear and nonlinear constraints in the lines where the nonlinear function is defined.

Comment only
05 Oct 2012 Nur

Nur (view profile)


Can i used this algorithm for linear equatiom or it only works with non linear equation?

Comment only
24 Jul 2012 Luc

Luc (view profile)

I had an optimal control problem with 56 control parameters for
an industrial applications. After trying PSO and other algorithms,
I tried cuckoo search, and found that, among the 4 methods I tried,
cuckoo search obtained the best results. Well done!

22 Jul 2012 Q Q

Q Q (view profile)

Downloaded it, tried it, and it's very efficient!

05 Jul 2012 Dedy Suwandi


I'm want to ask about Cuckoo Search implementation in Discrete Optimization Problem...

I'm now trying to implement it in a TSP (Traveling Salesman Problem)

Right now, i'm representing edge in TSP using a fuzzy matrices...
I'm using levy flights as random step for the probability change (but it's too big), first i try to normalize it, but it makes the probability value has a chance to become zero, it's caused by large difference from one value to other in the matrices produced, but if i'm not normalizing it then the it'll stack in local optima and of course the value will bigger than 1...

In converting from fuzzy matrices to a path, i'm using Max Number Method in fuzzy matrices...

Beside that i'm a little afraid of wrong implementation in cuckoo search itself...

Can you give me suggestion/idea about this ? i'm really confused about this...

Comment only
05 Jul 2012 Xin-She Yang

Xin-She Yang (view profile)

Thanks. That's a good question. The demo implementation uses
a given tolerance, but you can easily change it into a given
number of iteration by replacing the line "while (fmin>Tol)"
with the following two lines

for t=1:N_numEval,

and remove the line "N_iter=N_iter+n" because it becomes irrelevant.
Now the new stopping criterion should allow you to do things
more flexibly. Of course, to get better accuracy, you need to
increase N_numEval from 1000 to even 10000 or higher.

Comment only
05 Jul 2012 Nur

Nur (view profile)


I'm curious about something. Supposed the cuckoo search can be use as an optimization technique which means we can either find the maximum or the minimum.

but after I tested it with several objective functions, i found that we have to know the tolerance in order to find the best solutions. which mean i have to know what gives the maximum or minimum value for the function.

supposed the cuckoo search have to find what the max or min value isn't it.?

but what i found, when I change the tolerance, the min value will be change which mean, the min value depends on the tolerance.

so, that mean this cuckoo search didn't find the minimum value, instead we have to know what is the value of tolerance to give the minimum value. isn't it?

can you explain about this? i'm really confuse about this matter.

Comment only
18 Jun 2012 Xin-She Yang

Xin-She Yang (view profile)

Thanks. Of course, cuckoo search can solve that sort of problem. In fact, it has been designed to solve nonlinear problems in higher dimensions (nd) where nd is the number of dimensions, which can be 1, 2, 100, 4000, several thousands or even higher. The search principle is the same. In this demo, nd=15. So problems with two variables are usually considered "easy". Thanks.

Comment only
18 Jun 2012 Nur

Nur (view profile)

hi again.. i would like to know either this cuckoo search can solve the objective function with multiple variable such as this one

f(x,y) = y - x - 2x^2 - 2xy - y^2

Comment only
11 May 2012 Nur

Nur (view profile)

thank you for your response.

Does it mean I can't test the function?

I have tried change the function at the last line (line 175) with my function and also the dimension, but it gives me error at line 134.

it says that the number of element in j is not equal to fnew.

do I need to change anything?

Comment only
10 May 2012 Xin-She Yang

Xin-She Yang (view profile)

Hi, Thanks. The function you mentioned is too simple. Anyway,
if you want to test any function, just change the last line
(Line 175), also changed line 51 (the number of dimensions).

Comment only
10 May 2012 Nur

Nur (view profile)

hi..can someone help me..I want to use this cuckoo search algorithm to test a function. It state that we can change the function with our own function. But I don't know how and which part should I change. I want to test this function :

can someone help me to get the value of x and y at maximum point.. thank you..

Comment only
14 Mar 2012 mustafa arslan


09 Jan 2012 suman arora

Hi, Sir Can u tell me cuckoo search will apply on Eduction Data Mining ?

Comment only
26 Oct 2011 Seif Fateen

The empty_nests function in its current form can take the solution beyond bounds. Add these lines to the end of the function to correct this problem:

for i=1:n, new_nest(i,:)=simplebounds(new_nest(i,:),Lb,Ub);

Comment only
25 Aug 2011 priya

priya (view profile)

Hi,I have read the paper in which it is shown that cuckoo search is better than particle swarm optimization technique.How can we use CS algo for test effort estimation?

Comment only
10 Aug 2011 chongya

Hi, I've had the same situation with Ennio. Would you like to clarify them?

Comment only
10 Aug 2011 Xin-She Yang

Xin-She Yang (view profile)

Thanks. If you can define an appropriate objective function that links with
the parameters of SVM, it becomes an optimization problem, and thus should be
solved efficiently by CS in this case.

Comment only
09 Aug 2011 Wen

Wen (view profile)

Hi Yang, currently I am focusing on selecting optimal set of features and model parameters (e.g. SVM). I wondering that is it possible to use CS for my case? Would you please provide me some suggestions?

Thanks a lot!

Comment only
04 May 2011 Ennio Grasso

Hi again,
I finally received (and read) your book. I'm comparing the code in the book and the latest which is published here. I understand this one is supposed to be better and refined but I'd like to ask some clarification nonetheless since some things don't add up to me.
1) the 1st thing I noticed is that get_cuckoo in the book's algorithm (hence BA) cuckoos make random walks around the best so far, whereas in the latest algorithm (LA) they move from their own current position. chapter 12.2 of the book seems to explain these 2 strategies, but I wonder if indeed random walks from the current solution (not even around the better locally as in PSO) don't make intensification too sparse?
2) the 2nd issue has to do with the empty_nest. As I understand the objective here is apply "selection of the fittest". In BA indeed the worst nests are selected as candidates for replacement (again with random walk this time around the current position). In LA it seems the concept of "worst nests" is lost and a kind of Differential Evolution approach is taken, where a nest is moved (random uniform) toward one of the other nest.
It seems to me that both approach are reasonable but they are rather different conceptually. I mean, in the principle of "survival of the fittest" shouldn't we have a selection (as in BA) of the worst nest as candidate for this mutation rather than all of them (provided rand<pa obviously). In other words, shouldn't we always pick the worst nest rather than in parallel all nests together?
Thanks a lot for any help.

Comment only
29 Mar 2011 Ennio Grasso

Thanks a lot for your prompt reply. Indeed I ordered your book as google's version wont allow full access. In this paper

they compare 3 algs for levy distribution and they say McCulloch’s alg perform better than Mantegna's. Also, they provide a more complex Mantegna's implementation than yours (in matlab line 35-49)
35 invalpha = 1/alpha;
36 sigx = ((gamma(1+alpha)*sin(pi*alpha/2))/(gamma((1+alpha)/2)...
37 *alpha*2^((alpha-1)/2)))^invalpha;
38 v = sigx*randn(n,N)./abs(randn(n,N)).^invalpha;
39 kappa = (alpha*gamma((alpha+1)/(2*alpha)))/gamma(invalpha)...
40 *((alpha*gamma((alpha+1)/2))/(gamma(1+alpha)*sin(pi*alpha/2)))^invalpha;
41 p = [-17.7767 113.3855 -281.5879 337.5439 -193.5494 44.8754];
42 c = polyval(p, alpha);
43 w = ((kappa-1)*exp(-abs(v)/c)+1).*v;
44 if(n>1)
45 z = (1/n^invalpha)*sum(w);
46 else
47 z = w;
48 end
49 z = c^invalpha*z;

it seems your version is a simplified one that avoids step 39-49? BTW, all of my questioning is because I'm trying to port your alg in Java and I need to understand all the nuances of all tidbits. Thanks a lot for any help.

Comment only
29 Mar 2011 Xin-She Yang

Xin-She Yang (view profile)

Thanks. That's a good question.

a) For the formula: s=s+stepsize.*randn(size(s)),
the stepsize is a random number vector, but it is biased
because if s<best (in the sense of component-wise comparison),
then this stepsize is biased to one side, this leads to
a biased random-walk. In order to explore the search space
more efficiently, a symmetric random walk should be used.
Thus, another factor randn.

Here you might argue that the vector "stepsize" is already
symmetric, but this is only true for step sizes, but not for s.
Ideally, let's use 2D as an example, a random walk should
consists of a step size and angle (0 to 360) in a circle
on a 2D surface. The step size should be Gaussian (or Levy),
but the angle should be uniformly distributed, otherwise,
some regions cannot be reached.

b) The factor 0.01 or 1/100 is mainly to limit the step size.
Otherwise, Levy flights become too aggressive, and thus the
new solutions generated will be even outside of the domain.
For a more detail description of this factor, please see
the formulas (4.14 to 4.17) on page 33 of the book
"Nature-Inspired Metaheuristic Algoirthms", Second Edition,
(Yang 2010), Luniver Press.
Or at the link

Comment only
29 Mar 2011 Ennio Grasso

Hi there,
could you please clarify why you apply
(line 123), isn't stepsize already in levy distribution? Why the need to multiply for a gaussian?
Also, could you please explain what "the factor 0.01 comes from the fact that L/100 should the typical step size of walks/flights where L is the typical lenghtscale". Has it anything to do with the lower-upper bound limits of the problem? Thanks a lot.

Comment only
21 Mar 2011 Xin-She Yang

Xin-She Yang (view profile)

Thanks. I think you are right that
is consistent with the pseudocode.

This only changes the values of the pa. However, this does not affect the performance of the CS.

Again thanks :)

Comment only
20 Mar 2011 Marielena

shouldn't it be K=rand(size(nest))<pa
in line 147 of the code? otherwise a fraction of 75% would be replaced, wouldn't it?

Comment only
11 Feb 2013 1.2

There was a minor typo in the previous file, and a newer version is attached.

11 Feb 2013 1.1

Add a newer version.

14 Feb 2013 1.3

A version for constrained optimization with a spring design benchmark is now included. This version has three files.

Contact us