File Exchange

image thumbnail

Firefly Algorithm

version (8.26 KB) by Xin-She Yang
Firefly Algorithm for Constrained Optimization


Updated 16 Aug 2011

View Version History

View License

Firefly algorithm for nonlinear constrained optimization.

For simple demo in 2D, please use firefly_simple.m

For unconstrained functions in higher dimenisions, please use fa_ndim.m

For nonlinear constrained optimization,
please use fa_mincon.m

Cite As

Xin-She Yang (2021). Firefly Algorithm (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (44)

Stephen Kwarteng

I'm using firefly algorithm to optimize Artificial Neural Network for fault detection and classification of permanent magnet synchronous motor.
Could anyone help me with this since I'm a beginner in MATLAB.
Thank you.

Nguyen Thieu

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

Pham Minh Cong


I am using this firefly algorithm for tuning PID controller as a part of speed control of BLDC motor. I need to know how I can write the matlab code for tuning the PID controller using firefly algorithm please help me


thank you so much !


I am using this firefly algorithm for the optimization of process parameters of drilling by minimising the response using fa_mincon.m file.

i need to know how to plot the graph between the iteration and the best solution.
please guide

Jiaxun Li

Thank you so much, they are very useful!

Khampaserth xaphakdy

Thank you very much, Sir

sagar mali

Ali sameer

Thanks for shearing this important code
Can you please help me how can I train Artificial Neural network and ANFIS by using firefly algorithim

Saliha C A

how relay coordination is related to firefly algorithm in coding

Tricker Maelstrom

what different between " beta=(beta0-betamin)*exp(-gamma*r.^2)+betamin " and
" beta=beta0*exp(-gamma*r.^2) " and why you include betamin in to the equation?

Jinhua Zhou

Hamadi ikram

Hello , how can use firefly algorithm for tuning parameters of PSS and POD

mohanad AL-musaylh

Dear Sir

Could you please tell me how can I use Firefly algorithm to select the parameters of the SVR model?.


Marcelo Fernandes

padma reddy

Can any body tell me how fire fly can use for Classification to an Image.Please help me in code.


omar serrano

porque en fa_mincon.m nunca evalúa la función dentro del doble for como lo marca en el articulo del 2010?

C zin ping

Dear sir
I have second order mathematical equation for surface roughness as output responses and cutting speed, feed, depth of cut as input parameters.I want to get optimal cutting conditions using firefly algorithm .
Can u show me demo how to write matlab coding using firefly algorithm??


Sangeetha Natarajan.. please help me


Sir, i am trying to implement algorithm in c.. please give me the steps to implement this for correlating with what I have done..

bajuri satu

can i ask how to use this algorithm for optimizing svr parameter?

jasmin mary

sir can i use FA for optimization of TMD parameters

sangeetha natarajan

Sir, i have used your algorithm in matlab and could get nice results. But if i try to implement the same logic in c for embedded applications, it is not working if i increase the firefly population beyond 25. What would be the problem in it ??? i couldnt guess it.

Sun Zhen



I need the firefly algorithm demo in order to use at the fusion level. I already tested with cuckoo search algorithm.

Josephine Amala


Chinchu Thomas

toan le


We require this to understand the concept

yaser moniri


Jagatheesan Kaliannan

realy good

Jagatheesan Kaliannan


Ashraf K.


hamed abdulaziz

Please I wonder if it is possible to use Firefly Algorithm for features selection,where I have one dimensional array of features like Contrast,Correlation,Homogeneity,Cluster prominence,Energy,and...etc,and I want to use Firefly Algorithm to choose the best features of them,please could you guide me to do this job?thanks in advance.




Thank you so much, Dr. Yang

d g

very good..



I used firefly algorithm to solve a multimodal design problem
with 149 design variables, it works very efficiently.

escato carreira

Does this algorithm solve multi-objective problems with non-linear constrains?

Jackson Shen

Haven't look in detail. The first impression is great.

It is nice that the algorithm is implemented by the author.

Great Job!

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!