Firefly Algorithms for Multimodal Optimization

Firefly Algorithms for Multimodal Optimization

Xin-She Yang
Department of Engineering, University of Cambridge,
Trumpington Street, Cambridge CB2 1PZ, UK

Nature-inspired algorithms are among the most powerful algorithms for optimization. This paper intends to provide a detailed description of a new Firefly Algorithm (FA) for multimodal optimization applications. We will compare the proposed firefly algorithm with other metaheuristic algorithms such as particle swarm optimization (PSO). Simulations and results indicate that the proposed firefly algorithm is superior to existing metaheuristic algorithms. Finally we will discuss its applications and implications for further research.

Citation detail: X.-S. Yang, “Firefly algorithms for multimodal optimization”, in: Stochastic Algorithms: Foundations and Applications, SAGA 2009, Lecture Notes in Computer Sciences, Vol. 5792, pp. 169-178 (2009).

1 Introduction

Biologically inspired algorithms are becoming powerful in modern numerical optimization [1, 2, 4, 6, 9, 10], especially for the NP-hard problems such as the travelling salesman problem. Among these biology-derived algorithms, the multi-agent metaheuristic algorithms such as particle swarm optimization form hot research topics in the start-of-the-art algorithm development in optimization and other applications [1, 2, 9].

Particle swarm optimization (PSO) was developed by Kennedy and Eberhart in 1995 [5], based on the swarm behaviour such as fish and bird schooling in nature, the so-called swarm intelligence. Though particle swarm optimization has many similarities with genetic algorithms, but it is much simpler because it does not use mutation/crossover operators. Instead, it uses the real-number randomness and the global communication among the swarming particles. In this sense, it is also easier to implement as it uses mainly real numbers.

This paper aims to introduce the new Firefly Algorithm and to provide the comparison study of the FA with PSO and other relevant algorithms. We will first outline the particle swarm optimization, then formulate the firefly algorithms and finally give the comparison about the performance of these algorithms. The FA optimization seems more promising than particle swarm optimization in the sense that FA can deal with multimodal functions more naturally and efficiently. In addition, particle swarm optimization is just a special class of the firefly algorithms as we will demonstrate this in this paper.

2 Particle Swarm Optimization

2.1 Standard PSO

The PSO algorithm searches the space of the objective functions by adjusting the trajectories of individual agents, called particles, as the piecewise paths formed by positional vectors in a quasi-stochastic manner [5, 6]. There are now as many as about 20 different variants of PSO. Here we only describe the simplest and yet popular standard PSO.

The particle movement has two major components: a stochastic component and a deterministic component. A particle is attracted toward the position of the current global best and its own best location in history, while at the same time it has a tendency to move randomly. When a particle finds a location that is better than any previously found locations, then it updates it as the new current best for particle . There is a current global best for all particles. The aim is to find the global best among all the current best solutions until the objective no longer improves or after a certain number of iterations.

For the particle movement, we use to denote the current best for particle , and or to denote the current global best. Let and be the position vector and velocity for particle , respectively. The new velocity vector is determined by the following formula


where and are two random vectors, and each entry taking the values between 0 and 1. The Hadamard product of two matrices is defined as the entrywise product, that is . The parameters and are the learning parameters or acceleration constants, which can typically be taken as, say, . The initial values of can be taken as the bounds or limits , and . The new position can then be updated by


Although can be any values, it is usually bounded in some range .

There are many variants which extend the standard PSO algorithm, and the most noticeable improvement is probably to use inertia function so that is replaced by where takes the values between 0 and 1. In the simplest case, the inertia function can be taken as a constant, typically . This is equivalent to introducing a virtual mass to stabilize the motion of the particles, and thus the algorithm is expected to converge more quickly.

3 Firefly Algorithm

3.1 Behaviour of Fireflies

The flashing light of fireflies is an amazing sight in the summer sky in the tropical and temperate regions. There are about two thousand firefly species, and most fireflies produce short and rhythmic flashes. The pattern of flashes is often unique for a particular species. The flashing light is produced by a process of bioluminescence, and the true functions of such signaling systems are still debating. However, two fundamental functions of such flashes are to attract mating partners (communication), and to attract potential prey. In addition, flashing may also serve as a protective warning mechanism. The rhythmic flash, the rate of flashing and the amount of time form part of the signal system that brings both sexes together. Females respond to a male’s unique pattern of flashing in the same species, while in some species such as photuris, female fireflies can mimic the mating flashing pattern of other species so as to lure and eat the male fireflies who may mistake the flashes as a potential suitable mate.

We know that the light intensity at a particular distance from the light source obeys the inverse square law. That is to say, the light intensity decreases as the distance increases in terms of . Furthermore, the air absorbs light which becomes weaker and weaker as the distance increases. These two combined factors make most fireflies visible only to a limited distance, usually several hundred meters at night, which is usually good enough for fireflies to communicate.

The flashing light can be formulated in such a way that it is associated with the objective function to be optimized, which makes it possible to formulate new optimization algorithms. In the rest of this paper, we will first outline the basic formulation of the Firefly Algorithm (FA) and then discuss the implementation as well as its analysis in detail.

3.2 Firefly Algorithm

Now we can idealize some of the flashing characteristics of fireflies so as to develop firefly-inspired algorithms. For simplicity in describing our new Fireflire Algorithm (FA), we now use the following three idealized rules: 1) all fireflies are unisex so that one firefly will be attracted to other fireflies regardless of their sex; 2) Attractiveness is proportional to their brightness, thus for any two flashing fireflies, the less brighter one will move towards the brighter one. The attractiveness is proportional to the brightness and they both decrease as their distance increases. If there is no brighter one than a particular firefly, it will move randomly; 3) The brightness of a firefly is affected or determined by the landscape of the objective function. For a maximization problem, the brightness can simply be proportional to the value of the objective function. Other forms of brightness can be defined in a similar way to the fitness function in genetic algorithms.

Based on these three rules, the basic steps of the firefly algorithm (FA) can be summarized as the pseudo code shown in Fig. 1.

Firefly Algorithm    Objective function Generate initial population of fireflies Light intensity at is determined by Define light absorption coefficient while (MaxGeneration) for all fireflies for all fireflies if (), Move firefly towards in d-dimension; end if Attractiveness varies with distance via Evaluate new solutions and update light intensity end for end for Rank the fireflies and find the current best end while Postprocess results and visualization  
Figure 1: Pseudo code of the firefly algorithm (FA).

In certain sense, there is some conceptual similarity between the firefly algorithms and the bacterial foraging algorithm (BFA) [3, 7]. In BFA, the attraction among bacteria is based partly on their fitness and partly on their distance, while in FA, the attractiveness is linked to their objective function and monotonic decay of the attractiveness with distance. However, the agents in FA have adjustable visibility and more versatile in attractiveness variations, which usually leads to higher mobility and thus the search space is explored more efficiently.

3.3 Attractiveness

In the firefly algorithm, there are two important issues: the variation of light intensity and formulation of the attractiveness. For simplicity, we can always assume that the attractiveness of a firefly is determined by its brightness which in turn is associated with the encoded objective function.

In the simplest case for maximum optimization problems, the brightness of a firefly at a particular location can be chosen as . However, the attractiveness is relative, it should be seen in the eyes of the beholder or judged by the other fireflies. Thus, it will vary with the distance between firefly and firefly . In addition, light intensity decreases with the distance from its source, and light is also absorbed in the media, so we should allow the attractiveness to vary with the degree of absorption. In the simplest form, the light intensity varies according to the inverse square law where is the intensity at the source. For a given medium with a fixed light absorption coefficient , the light intensity varies with the distance . That is where is the original light intensity. In order to avoid the singularity at in the expression , the combined effect of both the inverse square law and absorption can be approximated using the following Gaussian form


Sometimes, we may need a function which decreases monotonically at a slower rate. In this case, we can use the following approximation


At a shorter distance, the above two forms are essentially the same. This is because the series expansions about


are equivalent to each other up to the order of .

As a firefly’s attractiveness is proportional to the light intensity seen by adjacent fireflies, we can now define the attractiveness of a firefly by


where is the attractiveness at . As it is often faster to calculate than an exponential function, the above function, if necessary, can conveniently be replaced by . Equation (6) defines a characteristic distance over which the attractiveness changes significantly from to .

In the implementation, the actual form of attractiveness function can be any monotonically decreasing functions such as the following generalized form


For a fixed , the characteristic length becomes as . Conversely, for a given length scale in an optimization problem, the parameter can be used as a typical initial value. That is .

3.4 Distance and Movement

The distance between any two fireflies and at and , respectively, is the Cartesian distance


where is the th component of the spatial coordinate of th firefly. In 2-D case, we have

The movement of a firefly is attracted to another more attractive (brighter) firefly is determined by


where the second term is due to the attraction while the third term is randomization with being the randomization parameter. is a random number generator uniformly distributed in . For most cases in our implementation, we can take and . Furthermore, the randomization term can easily be extended to a normal distribution or other distributions. In addition, if the scales vary significantly in different dimensions such as to in one dimension while, say, to along the other, it is a good idea to replace by where the scaling parameters in the dimensions should be determined by the actual scales of the problem of interest.

The parameter now characterizes the variation of the attractiveness, and its value is crucially important in determining the speed of the convergence and how the FA algorithm behaves. In theory, , but in practice, is determined by the characteristic length of the system to be optimized. Thus, in most applications, it typically varies from to .

3.5 Scaling and Asymptotic Cases

It is worth pointing out that the distance defined above is not limited to the Euclidean distance. We can define many other forms of distance in the -dimensional hyperspace, depending on the type of problem of our interest. For example, for job scheduling problems, can be defined as the time lag or time interval. For complicated networks such as the Internet and social networks, the distance can be defined as the combination of the degree of local clustering and the average proximity of vertices. In fact, any measure that can effectively characterize the quantities of interest in the optimization problem can be used as the ‘distance’ . The typical scale should be associated with the scale in the optimization problem of interest. If is the typical scale for a given optimization problem, for a very large number of fireflies where is the number of local optima, then the initial locations of these fireflies should distribute relatively uniformly over the entire search space in a similar manner as the initialization of quasi-Monte Carlo simulations. As the iterations proceed, the fireflies would converge into all the local optima (including the global ones) in a stochastic manner. By comparing the best solutions among all these optima, the global optima can easily be achieved. At the moment, we are trying to formally prove that the firefly algorithm will approach global optima when and . In reality, it converges very quickly, typically with less than 50 to 100 generations, and this will be demonstrated using various standard test functions later in this paper.

There are two important limiting cases when and . For , the attractiveness is constant and , this is equivalent to say that the light intensity does not decrease in an idealized sky. Thus, a flashing firefly can be seen anywhere in the domain. Thus, a single (usually global) optimum can easily be reached. This corresponds to a special case of particle swarm optimization (PSO) discussed earlier. Subsequently, the efficiency of this special case is the same as that of PSO.

On the other hand, the limiting case leads to and (the Dirac delta function), which means that the attractiveness is almost zero in the sight of other fireflies or the fireflies are short-sighted. This is equivalent to the case where the fireflies fly in a very foggy region randomly. No other fireflies can be seen, and each firefly roams in a completely random way. Therefore, this corresponds to the completely random search method. As the firefly algorithm is usually in somewhere between these two extremes, it is possible to adjust the parameter and so that it can outperform both the random search and PSO. In fact, FA can find the global optima as well as all the local optima simultaneously in a very effective manner. This advantage will be demonstrated in detail later in the implementation. A further advantage of FA is that different fireflies will work almost independently, it is thus particularly suitable for parallel implementation. It is even better than genetic algorithms and PSO because fireflies aggregate more closely around each optimum (without jumping around as in the case of genetic algorithms). The interactions between different subregions are minimal in parallel implementation.

Figure 2: Michalewicz’s function for two independent variables with a global minimum at .

4 Multimodal Optimization with Multiple Optima

4.1 Validation

In order to demonstrate how the firefly algorithm works, we have implemented it in Matlab. We will use various test functions to validate the new algorithm. As an example, we now use the FA to find the global optimum of the Michalewicz function


where and . The global minimum in 2-D occurs at , which can be found after about 400 evaluations for 40 fireflies after 10 iterations (see Fig. 2 and Fig. 3). Now let us use the FA to find the optima of some tougher test functions. This is much more efficient than most of existing metaheuristic algorithms. In the above simulations, the values of the parameters are , and .

Figure 3: The initial 40 fireflies (left) and their locations after iterations (right).

We have also used much tougher test functions. For example, Yang described a multimodal function which looks like a standing-wave pattern [11]


is multimodal with many local peaks and valleys, and it has a unique global minimum at in the region where and . The 2D landscape of Yang’s function is shown in Fig. 4.

4.2 Comparison of FA with PSO and GA

Various studies show that PSO algorithms can outperform genetic algorithms (GA) [4] and other conventional algorithms for solving many optimization problems. This is partially due to that fact that the broadcasting ability of the current best estimates gives better and quicker convergence towards the optimality. A general framework for evaluating statistical performance of evolutionary algorithms has been discussed in detail by Shilane et al. [8]. Now we will compare the Firefly Algorithms with PSO, and genetic algorithms for various standard test functions. For genetic algorithms, we have used the standard version with no elitism with a mutation probability of and a crossover probability of . For the particle swarm optimization, we have also used the standard version with the learning parameters without the inertia correction [4, 5, 6]. We have used various population sizes from to , and found that for most problems, it is sufficient to use to . Therefore, we have used a fixed population size of in all our simulations for comparison.

After implementing these algorithms using Matlab, we have carried out extensive simulations and each algorithm has been run at least 100 times so as to carry out meaningful statistical analysis. The algorithms stop when the variations of function values are less than a given tolerance . The results are summarized in the following table (see Table 1) where the global optima are reached. The numbers are in the format: average number of evaluations (success rate), so means that the average number (mean) of function evaluations is 3752 with a standard deviation of 725. The success rate of finding the global optima for this algorithm is .

Figure 4: Yang’s function in 2D with a global minimum at where .
Functions/Algorithms GA PSO FA
Michalewicz’s ()
Rosenbrock’s ()
De Jong’s ()
Schwefel’s ()
Ackley’s ()
Shubert’s (18 minima)
Yang’s ()
Table 1: Comparison of algorithm performance

We can see that the FA is much more efficient in finding the global optima with higher success rates. Each function evaluation is virtually instantaneous on modern personal computer. For example, the computing time for 10,000 evaluations on a 3GHz desktop is about 5 seconds. Even with graphics for displaying the locations of the particles and fireflies, it usually takes less than a few minutes. It is worth pointing out that more formal statistical hypothesis testing can be used to verify such significance.

5 Conclusions

In this paper, we have formulated a new firefly algorithm and analyzed its similarities and differences with particle swarm optimization. We then implemented and compared these algorithms. Our simulation results for finding the global optima of various test functions suggest that particle swarm often outperforms traditional algorithms such as genetic algorithms, while the new firefly algorithm is superior to both PSO and GA in terms of both efficiency and success rate. This implies that FA is potentially more powerful in solving NP-hard problems which will be investigated further in future studies.

The basic firefly algorithm is very efficient, but we can see that the solutions are still changing as the optima are approaching. It is possible to improve the solution quality by reducing the randomness gradually. A further improvement on the convergence of the algorithm is to vary the randomization parameter so that it decreases gradually as the optima are approaching. These could form important topics for further research. Furthermore, as a relatively straightforward extension, the Firefly Algorithm can be modified to solve multiobjective optimization problems. In addition, the application of firefly algorithms in combination with other algorithms may form an exciting area for further research.


  • [1] Bonabeau E., Dorigo M., Theraulaz G., Swarm Intelligence: From Natural to Artificial Systems. Oxford University Press, (1999)
  • [2] Deb. K., Optimisation for Engineering Design, Prentice-Hall, New Delhi, (1995).
  • [3] Gazi K., and Passino K. M., Stability analysis of social foraging swarms, IEEE Trans. Sys. Man. Cyber. Part B - Cybernetics, 34, 539-557 (2004).
  • [4] Goldberg D. E., Genetic Algorithms in Search, Optimisation and Machine Learning, Reading, Mass.: Addison Wesley (1989).
  • [5] Kennedy J. and Eberhart R. C.: Particle swarm optimization. Proc. of IEEE International Conference on Neural Networks, Piscataway, NJ. pp. 1942-1948 (1995).
  • [6] Kennedy J., Eberhart R., Shi Y.: Swarm intelligence, Academic Press, (2001).
  • [7] Passino K. M., Biomimicrt of Bacterial Foraging for Distributed Optimization, University Press, Princeton, New Jersey (2001).
  • [8] Shilane D., Martikainen J., Dudoit S., Ovaska S. J., A general framework for statistical performance comparison of evolutionary computation algorithms, Information Sciences: an Int. Journal, 178, 2870-2879 (2008).
  • [9] Yang X. S., Nature-Inspired Metaheuristic Algorithms, Luniver Press, (2008).
  • [10] Yang X. S., Biology-derived algorithms in engineering optimizaton (Chapter 32), in Handbook of Bioinspired Algorithms and Applications (eds Olarius & Zomaya), Chapman & Hall / CRC (2005).
  • [11] Yang X. S., Engineering Optimization: An Introduction with Metaheuristic Applications, Wiley (2010).
Comments 0
Request Comment
You are adding the first comment!
How to quickly get a good reply:
  • Give credit where it’s due by listing out the positive aspects of a paper before getting into which changes should be made.
  • Be specific in your critique, and provide supporting evidence with appropriate references to substantiate general statements.
  • Your comment should inspire ideas to flow and help the author improves the paper.

The better we are at sharing our knowledge with each other, the faster we move forward.
The feedback must be of minimum 40 characters and the title a minimum of 5 characters
Add comment
Loading ...
This is a comment super asjknd jkasnjk adsnkj
The feedback must be of minumum 40 characters
The feedback must be of minumum 40 characters

You are asking your first question!
How to quickly get a good answer:
  • Keep your question short and to the point
  • Check for grammar or spelling errors.
  • Phrase it like a question
Test description