File Exchange

image thumbnail

Cuckoo Search (CS) Algorithm

version 1.3 (8.84 KB) by

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

26 Ratings



View License

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.

Comments and Ratings (94)

can u please help me in importing an image into the code you have given. my email id is i will be highly thankful.

can you please tell me the code how to input the data with cuckoo algorithm or with practical example like small data set with minimal parameters optimization. (theory & practical ), if it's possible give an example which apply this algorithm on it. my email ID:

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 ;



pankaj (view profile)

I want to know how to implement Hybrid PSO and Cuckoo search algorithm


Megha (view profile)

how can i use this cuckoo search algorithm for a two dimensional objective function

hello sir i want to know how to implement Cuckoo search for iris classification using nntool... can you please send me cs algo function so that i will call it for iris dataset. thank you


Megha (view profile)

i have an objective function which is the sum of two equations in x and y.for eg; fnctn=fnctn1+fnct2;
if z=(x1-x)+(y1-y); where x and y are to optimized with x1 and y1 which i will input.This(x1,y1)keeps on varying with each iteration,there are 25 iterations.for each iteration i will get an optimized (x,y) which i have to store.
So my doubts are...
1)I read in one of the comments that,line 51 needs to be changed to get the required dimension so here its 2 right? x and y.
2) line 175 is to be changed to give the objective functionbut for me its fnctn=fnctn1+fnct2;how to give this? this is another code as i am giving x1 and y1 values in it?
how should i do this?please help me
and in this case how should the tolerance value be like?

I’m a seiner year student in renewable energy engineering school at the International university of Rabat and now I’m working on an end of semester project about smart grids.
Therefore, we want to use the cuckoo search algorithm to assure a perfect distribution of different sources of energy (wind, solar, biomass, Fuel cell, and grids)on a number of consumers and that with taking into account the cost and availability of the source.
So I have noticed that the levy flight only operate with continuous variable which is not the case with our problematic since we are working with discrete variable. we were wondering if you have an alternative for this matter.

After searching in a lot of documents, we have conclude that the following equations might be suitable for our problematic:


Found in this link in Equation 24 on page 3 :

and in this link in Equation (1) on page 3 :

However, we have some difficulties in implementing it on matlab.
Thank you a lot for your consideration and i look forward to hear from you.


vaidehi p

hello sir, i am a student and i'm doing project on integration of process planning and scheduling and i want to use cuckoo search for this. can you please tell me how to generate a new solution by levy flights?

kamel krim

hi Xin-she yang, i am a student and in am working on extraction satellit image and segmentation and i want to use Cuckoo search Algorithm for this purpose, i have read all the algorithms but i think this is the best algorithm will you please help me for this purpose, please give me some hints to use CSA to solve my problem."

Hello Sir,
I'm an M.Tech Scholar and I"m doing my project in Vedic multiplier and the multiplier selection is based on the applied number. I need an intelligent network for the selection of the multiplier unit based on the types of the number(for example the multiplicand contains only nine then we can switch to one of the sutra's in five like that).Is the switching process or the selection unit can be implemented with CS?? Please help me by providing sufficient information My mail

suresh kumar

can you please tell me the code how to input the data with cuckoo algorithm or with practical example like small data set with minimal parameters optimization

suresh kumar

i have large data set near about 1500 records and i would like to optimize using cuckoo search algorithm but i am not able to find how to insert the data through this algorithm pls help me on my email :

Wang gang


Algorithm is too simple and elitist, not gives acceptable results for CEC2015 and CEC2005-Dim30. Suit for students.

sadiq sary

Hi dear
i would like to ask you about how can I use cuckoo search algorithm in sentiment analysis ?
please help me coz I have been started to implement master thesis in this field
Thank you in advance

Sir I am doing project in "logistics optimization in cuckoo algorithm".I don't know how to incorporate my data set in cuckoo algorithm and how to write coding in MAT LAB.Help me sir.My email ID:

nabisha a

Hai Sir I need code for tunning PID controller using cuckoo algorithm

Haroon Javaid

hi Xin-she yang, i am a student and in am working on HEPWM problems in MVSI and i want to use Cuckoo search Algorithm for this purpose, i have read all the algorithms but i think this is the best algorithm will you please help me for this purpose, please give me some hints to use CSA to solve HEPWM Problems.


pankaj (view profile)

in equation of step size for cuckoo search algorithm uj and vj are noted as randn[D] Which generates a uniform integer between [1,D] but what is D please specify

sudha s

Hai sir,could please tell me how to solve a equation of x+y=1 using cuckoo algorithm.pls ans me through the mail.mail

sudha s

Hai sir,could please tell me how to solve a equation of x+y=1 using cuckoo algorithm.pls ans me through the mail.mail

Xuhong Yang

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
Many thanks,
Best ragards.

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 ""

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

subject to x1+2x2<=2

Many thanks for you

Sri Akshaya

Respected Sir we saw ur cuckoo search algorithm for optimization...we r planning to use it in medical field...for feature 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 :)

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

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

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;

Chen U-an


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:

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


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

Dear sir
I am trying to get a code of CS_New to solve a problem of optimizationin power 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

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

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.


badr (view profile)


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


Sijie (view profile)

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.

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

dear sir can u please provide me code cuckoo search optimization algorithm for job shop scheduling,if possible send me to my emailid


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 :


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:


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


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


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.


Harinee T

hi sir
i need modified cuckoo search algorithm code.

Harinee T

i need cuckoo search algorithm code. can i have?

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

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,


Hello,Xin-She Yang
I am Gurpreet Singh, student of 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


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.

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.


Zeltni (view profile)


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.


Saeid (view profile)

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


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.


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

can you put these codes in internet?


hello sir

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


hema (view profile)

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


hema (view profile)

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

Ken Kueh

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


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.

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.


Nur (view profile)


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


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!


Q Q (view profile)

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

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

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.


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.

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.


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


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?

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


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


suman arora

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

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);


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?


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

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.


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!

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.

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.

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

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.

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 :)


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?



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


Add a newer version.


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

MATLAB Release
MATLAB 7 (R14)

Inspired: ACS_CS(L,F,MET)

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

» Watch video