# Moth flame optimization

Moth-Flame Optimization (MFO) algorithm was proposed in 2016  as one of the seminal attempt to simulate the navigation of moths in computer and propose an optimization algorithm. This algorithm has been widely used in science and industry.

## Inspiration

Moths are fancy insects, which are highly similar to the family of butterflies. Basically, there are over 160,000 various species of this insect in nature. They have two main milestones in their lifetime: larvae and adult. The larvae is converted to moth by cocoons. The most interesting fact about moths is their special navigation methods in night. They have been evolved to fly in night using the moon light. They utilized a mechanism called transverse orientation for navigation. In this method, a moth flies by maintaining a fixed angle with respect to the moon, a very effective mechanism for travelling long distances in a straight path . Since the moon is far away from the moth, this mechanism guarantees flying in straight line. The same navigation method can be done by humans. Suppose that the moon is in the south side of the sky and a human wants to go the east. If he keeps moon of his left side when walking, he would be able to move toward the east on a straight line.

Despite the effectiveness of transverse orientation, we usually observe that moths fly spirally around the lights. In fact, moths are tricked by artificial lights and show such behaviours. This is due to the inefficiency of the transverse orientation, in which it is only helpful for moving in straight line when the light source is very far. When moths see a human-made artificial light, they try to maintain a similar angle with the light to fly in straight line. Since such a light is extremely close compared to the moon, however, maintaining a similar angle to the light source causes a useless or deadly spiral fly path for moths .

## MFO algorithm

In the MFO algorithm, it is assumed that the candidate solutions are moths and the problem’s variables are the position of moths in the space. Therefore, the moths can fly in 1-D, 2-D, 3-D, or hyper dimensional space with changing their position vectors. Since the MFO algorithm is a population-based algorithm.

It should be noted here that moths and flames are both solutions. The difference between them is the way we treat and update them in each iteration. The moths are actual search agents that move around the search space, whereas flames are the best position of moths that obtains so far. In other words, flames can be considered as flags or pins that are dropped by moths when searching the search space. Therefore, each moth searches around a flag (flame) and updates it in case of finding a better solution. With this mechanism, a moth never lose its best solution.

A logarithmic spiral has been chosen as the main update mechanism of moths in this paper. However, any types of spiral can be utilized here subject to the following conditions: Spiral’s initial point should start from the moth Spiral’s final point should be the position of the flame Fluctuation of the range of spiral should not exceed from the search space Considering these points, we define a logarithmic spiral for the MFO algorithm as follows:

$S(M_{i},F_{i})=D_{i}e^{bt}cos(2\pi t)+F_{j}$ where $d_{i}$ indicates the distance of the $i-th$ moth for the $j-th$ flame, $b$ is a constant for defining the shape of the logarithmic spiral, and t is a random number in [-1,1].

D is calculated as follows:

$D_{i}=|F_{j}-M_{i}|$ where $M_{i}$ indicate the $i-th$ moth,$F_{j}$ indicates the $j-th$ flame, and $D_{i}$ indicates the distance of the $i-th$ moth for the $j-th$ flame.

$S(M_{i},F_{i})=D_{i}e^{bt}cos(2\pi t)+F_{j}$ is where the spiral flying path of moths is simulated. As may be seen in this equation, the next position of a moth is defined with respect to a flame. The t parameter in the spiral equation defines how much the next position of the moth should be close to the flame (t = -1 is the closest position to the flame, while t = 1 shows the farthest). Therefore, a hyper ellipse can be assumed around the flame in all directions and the next position of the moth would be within this space. Spiral movement is the main component of the proposed method because it dictates how the moths update their positions around flames. The spiral equation allows a moth to fly “around” a flame and not necessarily in the space between them. Therefore, the exploration and exploitation of the search space can be guaranteed.

The proposed position updating procedure can guarantee the exploitation around the flames. In order to improve the probability of finding better solutions, we consider the best solutions obtained so far as the flames. So, the matrix F in the above equation always includes n recent best solutions obtained so far. The moths are required to update their positions with respect to this matrix during optimization. In order to further emphasize exploitation, we assume that t is a random number in [r,1] where r is linearly decreased from -1 to -2 over the course of iteration. Note that we name r as the convergence constant. With this method, moths tend to exploit their corresponding flames more accurately proportional to the number of iterations.

A question that may rise here is that the position updating only requires the moths to move towards a flame, yet it causes the MFO algorithm to be trapped in local optima quickly. In order to prevent this, each moth is obliged to update its position using only one of the flames. It each iteration and after updating the list of flames, the flames are sorted based on their fitness values. The moths then update their positions with respect to their corresponding flames. The first moth always updates its position with respect to the best flame, whereas the last moth updates its position with respect to the worst flame in the list.

It should be noted that this assumption is done for designing the MFO algorithm, while possibly it is not the actual behaviour of moths in nature. However, the transverse orientation is still done by the artificial moths. The reason that why a specific flame is assigned to each moth is to prevent local optimum stagnation. If all of the moths get attracted to a single flame, all of them converge to a point in the search spaces because they can only fly towards a flame and not outwards. Requiring them to move around different flames, however, causes higher exploration of the search space and lower probability of local optima stagnation.

Therefore, the exploration of the search space around the best locations obtained so far is guaranteed with this method due to the following reasons:

• Moths update their positions in hyper spheres around the best solutions obtained so far.
• The sequence of flames is changed based on the best solutions in each iteration, and the moths are required to update their positions with respect to the updated flames. Therefore, the position updating of moths may occur around different flames, a mechanism that causes sudden movement of moths in search space and promotes exploration.

Another concern here is that the position updating of moths with respect to n different locations in the search space may degrade the exploitation of the best promising solutions. To resolve this concern, an adaptive mechanism is proposed for the number of flames.

$FlameNumber=round(N-l\times {\frac {N-1}{T}})$ where $l$ is the current number of iteration, $N$ is the maximum number of flames, and $T$ indicates the maximum number of iterations.

There is N number of flames in the initial steps of iterations. However, the moths update their positions only with respect to the best flame in the final steps of iterations. The gradual decrement in number of flames balances exploration and exploitation of the search space. After all, the general steps of the P function are as follows.

The pseudo code of the WOA algorithm is presented below:

Update the number of flames (FlameNumber)
Initialise the population of moths
Calculate the objective values

for all moths
for all paramters
update r and t
Calculate D with respect to the corresponding moth
Update the matrix M with respect to the corresponding moth
end
calculate the objective values
Update flames
end


## Applications

Forecast the electricity consumption of Inner Mongolia 

Multi-item EOQ model with nonlinear unit holding cost and partial backordering

Training multi-layer perceptrons

Optimal Power Flow 

Parameters extraction of the three diode model for the multi-crystalline solar cell/module

Optimal Multi-Criteria Design of Hybrid Power Generation Systems

Automatic mitosis detection in breast cancer histology images

Tomato diseases detection

Optimal power flow with voltage stability improvement and loss reduction in power system

Optimal setting of STATCOM based on voltage stability improvement and power loss

Terrorism detection

Optimal Active and Reactive Power Dispatch Problem

Price Penalty factors Based Approach for Combined Economic Emission Dispatch Problem

Single level production planning in petrochemical industries

Profit maximization with integration of wind farm in contingency constraint deregulated power market 

Thermogram Breast Cancer Detection

optimal bidding strategy under transmission congestion in deregulated power market

Optimal power flow with non-parametric statistical evaluation validation

Alzheimer's Disease Diagnosis

Sharp MDFT Filter Banks 

Feature selection

Controller Performance in Microgrid Frequency Deviation Enhancement

Unit Commitment in Power System Operation Planning

Multilevel Thresholding Image Segmentation

Economic Load Dispatch problem with ramp rate limits and prohibited operating zones

Harmonic elimination of multilevel inverters

Multi area power system

Facial emotion recognition