Pure

C omputers are often used when problems are big or hard to solve. However, traditional ways to find solutions are not enough when problems are very serious. Hence, turning to nature may be the answer to find solutions for these problems. Artificial intelligence tries to simulate creatures and activities in nature turning their techniques to find solutions for a given problem into an algorithm. Although there are many algorithms have been developed, whose works are inspired by nature, there has been continuous researches aimed at finding better and faster algorithms. Many mathematical optimization problems can be solved by Swarm intelligence algorithms. The aim of this algorithm is to get the optimum solution by repeated searches whose main concern is to discover the area related to solution. In this paper, Firefly Algorithm (FA) and Particle Swarm Optimization (PSO) algorithm are executed. The two algorithms are implemented to find the minimum and maximum values of the mathematical equations. Users of the proposed system are able to read the equation directly through the execution time, by displaying and


I. Introduction
Optimization is among the important way to solve many scientific and engineering problems.Through the continuous development in recent years, many optimization approaches to solve these problems have been developed; most of them inspire their work from nature [1].Algorithms that inspire their work from nature are among the strongest algorithms to solve the recent problems.Examples of this kind of algorithms are Particle Swarm Optimization (PSO), whose behaviors depend on the behaviors of swarms such as: shoal of fish and swarms of birds in nature.Recently, this algorithm has been applied to find many solutions of optimization applications [13].The behavior of natural species is the main inspiration to design and implement many new optimization techniques, such as ants systems which were developed using principle of observation ants in nature.The intelligence of swarm, which is the behavior applied in these algorithms, is a term used to describe the collective behaviors of decentralized and auto organization systems, whether it is natural or artificial.Therefore, it depends on the interaction among its components inspiring its behaviors from insects.The idea of this algorithm is distributing of a swarm in a limited research area moving randomly to find optimum solution in the area.Generally, when the number of swarms is increasing and the area of research is decreasing, it becomes easier and faster to find the optimum solution.When the number of components of swarm is decreasing and the area of research is increasing, it becomes hard to find the optimum solution [14].The work of firefly algorithm is inspired by the behaviors of fireflies in nature.Firefly produces short and rhythmical flashes.Flash comes out of bioluminescence represents an activity of each firefly or it may be used as warnings fireflies' works on groups attracting each other by this flash [5][3].This algorithm is widely used to solve the problems of reliability and repeating [4] [16].

II. Problem statement
In this paper, a program that deals with mathematical functions was designed, which cannot be accepted in advance, where these functions are multivariable.The proposed system calculates the maximum and minimum values of the function variables, as this function is defined and entered directly by the user during the system execution time.

III. Previous works
In 2011, Hanan A. R. Akkar and Firas R. Mahdi proposed adoption of the artificial neural networks using the PSO algorithms as mechanism to optimize the performance of artificial neural networks and to decrease the necessary circuits to build networks.The toolkit of the PSO algorithm was modified in this paper in the Matlab environment to be suitable for the desired application.In the proposed design, the training was carried out out-of-chip and then the design carried the entire training to the chip.In this way, the number of circuits is reduced as little as possible.This paper executes calculation and logic of ALU using the tools of diagramming as an example to apply the digital circuits using artificial neural networks by the PSO algorithm [11].In 2012, Saibal K. Pal and others applied the firefly algorithm and the PSO algorithm for solving nonlinear mathematical problems.A number of computational experiments were done by the researcher and his colleagues showing obtained results in the form of diagrams explaining the ways of finding the optimum solution.Then, the results of these experiments are analyzed and compared with the best solutions that are obtained so far depending on average of the execution time.The obtained results show that the performance of the firefly algorithm is better than that of the PSO algorithm [14].In 2014, Amarita Ritthipakdee and et al proposed an improvement of the original firefly algorithm.The proposed algorithm takes into consideration not only the firefly's reaction to light, but also the following factors: the exchange of genes in the firefly, its pheromone, and the wind effect on the dispersion of pheromone.The proposed algorithm has been tested and compared with the original firefly algorithm.It was found that the proposed algorithm was not only more effective but faster than other algorithms [16].In the year 2019, a common overview of the techniques for dealing with the determinants was presented by Umesh Balande and Deepti Shrimankar.They developed a hybrid algorithm called Stochastic Ranking with Import Firefly Algorithm (SRIFA), applied for solving geometric improvement problems in the real world.This algorithm is applied to enhance 24 functions of 200 CEC and five of common geometric design problem.Through the arithmetical results, it becomes obvious that results obtained from the test of the hybrid algorithms that are already mentioned that (SRIFA) algorithm has better results than that of the basic firefly algorithm [5].

IV. Firefly algorith (FA)
Firefly algorithm is among the best ways for optimization inspired by nature, specifically by the behaviors of firefly in the nature.It has been developed by a scholar named Yang in Cambridge University.Each firefly produces a dim light that can be used by fireflies as warning signs.Since 2007, the year in which this algorithm is invented, firefly algorithm has attracted many researches around the world.Recent studies have shown that this algorithm is effective in numerical optimization and combinatorial optimization and it can be better than other algorithms designed in the same field [20].

A. Behavior of fireflies
The light of fireflies in nature is a beautiful scene in summer especially in Tropical and middle zones.There are around two thousands kinds of fireflies and most of them have a light to be short and rhythmical in order not to reach to far distances.Lighting often is unique for each firefly.Flash light is produced by a biological process and the way to produce these flashes is a matter of discussion.Nonetheless, there are two basic functions for these flashes: attraction for breeding and attraction for possible prays.In addition, this flash can be like a cautionary warning.The average of rhythmical light and the amount of lighting time represent a part of a signal system that gather two sexes together.Female responds to the mode produced by males of the same kind.In some kinds, females mimics the mode of flash that is special to attract males in the other kinds of fireflies making males prays for them [3].

B. Function of firefly algoritrhm 1. Attractiveness
The function of attractiveness for fireflies has its own way that is shown in the decreasing function described in equation (1).Where (r) denotes the distance between any fireflies and the primary value of (r) is zero and the value of attraction is zero too, and  is an absorption coefficient that controls the reduction of light intensity [15].() =  0 e − ℎ  ≥ 1 (1)

Distance
If there are two fireflies: firefly (i) and firefly (j), the distance between them will be calculated in the following equation: Where  represents the firefly in location (i) within the area of research, and (d) denotes the dimensions of the problem [6] [15].

Movement
Equation (3) shows the movement of fireflies which are attracted by other fireflies, eventually having more attraction.X i+1 = x i + β 0 e (- r)2 (x ix j ) 2 + α (rand -0.5) …. (3) The second term refers to the factor of attraction, where the third term refers to the random distribution, where the coefficient of the random distribution is denoted by (rand) and the value of which is distributed within the scope [0, 1] [9], figure 1 shows firefly algorithm.The following equation represents the primary generation of the fireflies: Where (LB) and (UB) denote the minimum and maximum limits for a firefly [7].V. Particale swarm optimization algorithm PSO algorithm is a combination of swarms or elements in which each element is called a particle that represents a solution.The behavior of the combination is inspired basically by the algorithms that inspire their work from living creature in nature.
In addition, this model is inspired from the social behavior of swarms of birds or group of fishes while moving from one place to another.This model was developed by Dr. Eberhartand Dr. Kennedy in 1995 [8].
The purpose of this algorithm is to get the optimum solution and results through simulating the behaviors of birds in their search of best food.Consequently, each system that depends on this algorithm will be represented at the beginning from a random combination of a random solution.Search within this combination includes the optimum solution through the update of generation.For example, one can imagine a bird looking for food through other birds that refers to a possible feed source, or when a bird remembers a place of food it saw and other near discovery area.It can also be seen as a simulation of a method through which problems can be solved by simulating people we know and we consider successful, and through learning selfdependence.Consequently, our problems will be solved through our experience and others that we know that solved similar problems in similar ways [12].
The PSO algorithm finds quick solutions for nonlinear, invariable and multimedia problems.To explain the work of the algorithm, it is assumed that each single solution is a bird within the distance of search is called particle.All particles have positions and velocities that leads these flying components that fly within the space of problem through following the best component so far [10].Swarm represents a possible solution for the problem that can be determined by fitness function.In each iteration, a new location for particle will be evaluated depending on its last position and velocity.Therefore, each particle has one chance to move for each iteration within limited velocity.Therefore, if velocity is too high, a particle will move faster and if the velocity is very slow, a particle will move slowly which makes approaching very slow.At the beginning, the PSO algorithm distributes the particles randomly in the search area, then it uses objective function simply to estimate the suitability of each particles.As a result, each particle has its own location, value of fitness function and velocity.In this case the best value of fitness existed in the swarm identified as the best particle or best individual solution [18] [19].From what are mentioned earlier it is clear that each particle in the swarm has two basic processes: 1. Velocity update.

Position update [2] [17]
. Finally, PSO algorithm estimates global best solution, which is the location of particle that gives the minimum and maximum limits from the value of fitness among the entire particle in the group.The following equations explains the concept of the standard PSO algorithm that uses both current global best   * and current individual best   * to get the desired value after many iterations.Figure (2) shows PSO algorithm.In the following section, the variables mentioned in the previous equations will be explained

A. Description
The firefly algorithm and the PSO algorithm are used to solve many optimization problems.To do so, it is needed to identify the objective function, naming it the firefly algorithm.On the other hand, PSO algorithm is named in fitness.In addition, many needed variables are identified called variables of control.The objective function will be identified by a user from the interactive interface and the following format includes some variables that can be existed in the objective function:  → (, ) =  +  2 −  , (, ) ∈ (−, ) (7) w: is the maximum and minimum limits for the firefly (i) x,y: the value of which is random, while C: refers to a constant number.In this paper, the firefly algorithm and the PSO algorithm are executed on MATLAB in windows 8 or windows 10, the result will be displayed on the interactive interface.When any technique of metaheuristic is executed, variables of control should be prepared.This is the same for firefly algorithm where it is very important to select the variables of control to find the optimum solution.Our choices for these variables depend on the experimental results.

Choosing control variables for firefly algorithm
The variables of control for firefly algorithm are explained in the following way: 1. nf: is the number of fireflies in all examples since its value = 45 which is tested because the increasing of which to more than 100 will not change the result notably and the execution time will increase with no improvement in results.2. n iter: is the number of iteration, which is another variable of control for firefly algorithm that should be identified the algorithm to be implemented until the solution that is near to the optimum one will be found in low mistakes.In all examples 50=(n iter), is identified and it is found that the result is suitable.When the value of n iter is increased to more than 50, this will not change the result.3. β0: is the primary value for (attractiveness).In many proposed optimization problems (0.1= β0).In this paper, bigger value is used, which yields better result.4. : is absorption coefficient whose value in this research is =1, this value increases the velocity of algorithm the solution to find the optimum solution.5. μ: is the value of possible coefficient, which can be an positive number.Its value in the search is μ = 0.1 6. α: is the value of random variable in which the variable control has a value of any number between (w,w-).The rate of randomness is specified with a value of α and the variable, which is very important since it allows to have a new solution in order not to add a low local limit for it.In this research, the value of α = 0.1, this value is selected to avoid the disturbance of fireflies.At the beginning, values for the variables of control will be selected.Then, the algorithm is executed until it reaches iter=50, to remove the random effects and avoids the early approaching.20 independent operations are executed.After that, the firefly with a best value of fitness is selected as an optimum solution for the given problem.

Choosing control variables for pso algorithm
The variables of control for the PSO algorithm are explained as follows: The PSO algorithm is prepared with a group of random components (solutions), and then the best solution through the update of generation is looked for.1-N: is the number of particles in all examples whose values = 45.2-IterMax: is the number of iteration, which is another variable of control for the PSO algorithm.In all examples, the number of iteration is identified iter =50 (in this algorithm, when the number of iterations is increasing, the result will be best and more accurate).Within each iteration, each component is being updated ith the group through following values: "pbest": represents the best suitable value that (i) reaches so far, "gbest": represents the best suitable value within the whole swarm, the best component within the whole swarm.The values of variables will be identified, then, the algorithm is executed until it reaches iter =50.After that, a particle with the best fitness value will be selected as an optimum solution for the problem.

B. System interfsces
The following figures explain the whole cases existed in the system: 1.First case: shows the main interface containing the whole parts existed in the system.

VII. Conclusion
By comparing the two algorithms, it has become clear that the firefly algorithm is better to find the optimum solution.When equations are executed, the results of the firefly algorithm are better than that of the PSO algorithm.The experiments done on the two algorithms have shown that when the number of iteration is increasing, the firefly algorithm helps to find the optimum solution faster, and then it is stopped at certain iteration.For the PSO algorithm, increasing the number of iteration leads to improve the result, this means that the firefly algorithm is faster to find the optimum solution than that of the PSO algorithm.It is possible to propose many future works in this paper such as adding other algorithms, like bee swarm, increasing functions related to comparison, making computations to compare between the algorithms and improving the interfaces.In addition, the FA algorithm can be executed using hardware devices that will increase time and decrease energy used to run the algorithm.

"
lbest": when a component in the swarm is taking position within a group, as for other components, the best value within this partial groups represents the best local value called 1best.After finding the best values, components are modified in terms of their velocity, position according to equations a and b. v[]=c3*v[]+c1*rand()*(pbest[]present[])+c2*rand()*(gbest[]-present[]).....(a) present[] = persent[] + v[]….....(b)Where v[]: represents the velocity of a particle.persent[]: represents the position of (i) in k moment.Pbest[]: represents the best position for the current component of the swarm.Gbest[]: represents the best position within the whole swarm.Tand: represents a random number within the scope [0, 1] c1, c2, c3: acceleration coefficients, they often have the values of c1+c2+c3=1.

Fig. 3 -
Fig. 3-a: The main interface for the system without entering scope value

Fig. 7 :Fig. 8 :
Fig. 7: The case of entering a wrong equation 6. Sixth case: execution of the first equation

8 .
Eighth case: Execution of the third equation.

Fig. 10 :
Fig.10: Execution of the third equation 9. Ninth case: execution of a equation without entering the scope value by a user and the system wil

Fig. 11 :
Fig. 11: the case of the scope is not entered by the user.