An Enhanced Energy-Efficient Web Service Composition Algorithm Based on the Firefly Algorithm

Numerous web services with the same function but different service qualities are constantly emerging on the network. Optimizing web service composition based on multiple candidate services sets an urgent problem in the service composition neighborhood. This paper modifies the traditional Firefly algorithm and adds exchange and mutation mechanisms to optimize the Web service composition efficiently in multiple candidate service sets. Meanwhile, it discretizes the continuous space of its solution set and better adapts to the service composition optimization problem. Experimental results show that compared with the GA, IA, SA, ACO, FACO, and EFACO algorithms, this algorithm has better optimization performance, faster speed, and higher energy efficiency for solving service composition optimization problems in the case of large-scale data. The higher the combined complexity of the solution, the stronger the performance compared to other algorithms. It can better deal with the increasingly complex situation of Web service composition problems.


BACKGRoUND
There are many ideas to solve the problem of Web service composition. Exhaustive algorithms can be used. However, exhaustive algorithms are computationally expensive and take a long time. Therefore, heuristic algorithms are widely used to solve such problems. Meyer proposes for the first time a Web service automatic composition algorithm based on heuristic search (Meyer & Weske, 2006). This algorithm supports the parallel creation of service composition and the creation of variables in the service composition process. However, the search space is too broad, and the running time is extended. Later, some scholars introduced swarm intelligence algorithms into this field. The swarm intelligence optimization algorithm is to find the optimal solution by imitating the habits of organisms and using the interaction between individuals (Zhang et al., 2010).
A genetic algorithm is an algorithm that simulates the process of biological genetics and evolution and has good global search capabilities. Literature (Amiri & Serajzadeh, 2010) modifies the function of generating chromosomes in the genetic algorithm to enhance the algorithm's speed, but this function is random, and the result of the algorithm is unstable. References (Seghir & Khababa, 2018;Yang et al., 2019;Zhang et al., 2012) apply a multi-objective genetic algorithm to analyze multiple objective functions to solve the Web service composition problem. However, the algorithm is challenging to operate, and it is easy to fall into the local optimum, and it is not easy to achieve the global optimum solution. Therefore, some scholars develop the genetic algorithm by integrating other methods. Literature (Yilmaz & Karagoz, 2014) updates the exchange strategy of a genetic algorithm by combining it with a simulated annealing algorithm and chorus search algorithm. To decrease the algorithm's search space and advance the performance of the genetic algorithm, literature (Sivaram et al., 2019;Ye & Guan, 2016) alters the local optimization method of the candidate service set.
Compared with the genetic algorithm, the particle swarm algorithm has fewer parameters and accelerated convergence speed. Literature (Pourpanah et al., 2022;Wen et al., 2013) proposes a particle swarm algorithm based on the circular orbit of sub-particles and zero inertia weight to optimize Web service composition. Literature (Liao et al., 2014;Pourpanah et al., 2022) introduces a particle swarm optimization algorithm, which searches for the optimal solution according to the density of feasible solutions of the subpopulation, and increases the search ability of the population. Nevertheless, particle swarm algorithm generally has premature convergence, and it is obvious to fall into the local optimum.
Ant colony algorithm is another population intelligent optimization algorithm. Its concept is simple, easy to understand, and has fewer parameters than the particle swarm algorithm. Literature (Yang et al., 2019) recommends a dynamic ant colony algorithm that transforms web service composition into a directed acyclic graph and finds the shortest path among them. Literature (Yang et al., 2019;Zhang et al., 2010) joins genetic algorithm and ant colony algorithm, obtains the local solution through the improved ant colony algorithm, utilizes the local solution to initialize the genetic algorithm population, and finally gains the optimal solution through the genetic algorithm. Literature (Dahan et al., 2017;Yang et al., 2019) offers a flying ant colony optimization algorithm. The optimal ant will share pheromone with the surrounding ants, promoting the quality of the optimal solution but extending the running time. Literature  states an improved flying ant colony algorithm, which adjusts the number of adjacent nodes receiving pheromone according to the quality of the solution, which better balances the exploration and development of the ant colony. Literature (Dahan et al., 2021) adds three different optimization methods based on FACO to improve the searchability of the algorithm. This method is the EFACO algorithm.
Since then, swarm intelligence optimization algorithms have developed swiftly, and various experts and scholars have recommended various swarm intelligence optimization algorithms to solve Web service composition optimization. Literature (Zhao et al., 2019) suggests an improved immune algorithm that applies heuristic algorithm ideas to reduce the search space and raise the algorithm's speed. References (F.-C. Qi et al., 2018) adjust the differential evolution algorithm, introduce structural knowledge, and submit new coding methods. Although the algorithm's optimization ability is improved, it is unsuitable for large-scale Web ser-vice composition scenarios. They aimed at the large-scale Web service portfolio, literature (Chandra & Niyogi, 2019;Huo et al., 2015) advanced artificial bee colony algorithms, and differential evolution algorithm to advance search efficiency. Literature (Attiya et al., 2020;Liu et al., 2008) combines the simulated annealing algorithm and the local greedy algorithm to comply the Web service composition. In 2008, Yang first introduced the firefly algorithm (Yang, 2009). Then Literature (Jiang et al., 2017;C. B. Pop et al., 2011;Rajeswari & Kanniappan, 2021) submitted a hybrid firefly algorithm, which consolidates the firefly algorithm with genetic operators and encodes all solutions through the planning graph structure to find the optimal solution.
Although the above algorithms have effectively solved Web service composition, they all have some problems, such as slow solution speed and effortless to fall into local optimum. For the optimization problem of Web service composition, this paper offers an enhanced firefly algorithm, which appends random disturbances when calculating the moving distance, which is better suited to explain the problem of discrete solution space. At the same time, the exchange and mutation mechanism in the genetic algorithm is added to make it converge faster and perform adequately.

Web Service Composition Description
Definite a Web service be expressed as WS= (S, F, QoS), where S is the service overview, F is the function implemented by the service, and QoS is the service quality. Each Web service often has multiple QoS attributes. Based on the different emphasis on the composite service, different QoS attributes can be selected. This paper mainly considers the five widely adopted QoS attributes: cost, response time, energy, availability, and reliability, and QoS=(C, RT, E, A, R). There into, C is the cost, which refers to the fee that needs to be paid to the service provider to use the Web service. RT is the response time, which is when it takes to initiate a request to the Web service until it returns the result. E is the energy, which is the energy consumed by performing web services. A is availability, which refers to the degree to which the Web service is ready for rapid use. And R is reliability, which represents the possibility of fault-free execution of the Web service.
Suppose a complex composition of Web services is composed of n tasks, and there are m candidate Web services in each type of task, then WSC = (G 1 , G 2 , ..., G n ) = (WS 11 ,WS 12 ,...,WS nm ) Figure 1. There are usually four structures for Web service composition: sequence, loop, parallelism, and selection, as shown in Figure 2 (Dahan et al., 2017).
In practical applications, Web service composition may also have a more complex structure to resolve elaborate assignments. However, complicated structures can be decomposed into sequential structures in the end, so this paper only considers the composition of Web services with sequential structures Figure 3, and the comprehensive QoS attribute calculation equation is shown in Table  1( Dahan et al., 2017;Ibrahim et al., 2020).
Different algorithms have different dimensions, so the following equation is used to standardize the fitness of each algorithm (Alayed et al., 2019): According to its QoS attribute, definite the objective function (Dahan et al., 2017;Ibrahim et al., 2020) of the web service composition be: Among them, Wa, Wr, Wc, Wrt, and We represent the weights of five QoS attributes of Web service availability, reliability, cost, response time, and energy, respectively.

Firefly Algorithm
Encode each firefly as a set of solutions as follows: x ws ws ws ws (3) The ws n is a Web service in task n.
In order to guarantee the orderliness of the candidate Web services in each task, the following equation is used to estimate and rank the comprehensive QoS attributes of each Web service (Dahan et al., 2017;Ibrahim et al., 2020) .
Then the candidate Web services in the k-th task are sorted as follows: Table 1.

QoS attributes Calculation formula
The m is the number of candidate Web services in each task. Assuming that any two fireflies a and b in the solution space, their position variables x a = [x a1 ,x a2 ,x a3 ,...,x an ] and x b = [x b1 ,x b2 ,x b3 ,...,x bn ] are n-dimensional vectors. If the brightness Ia of the firefly a is greater than the brightness I b of the firefly b, then the firefly b is attracted by the firefly a and moves to a, and the attraction β ab can be expressed as: In the formula: β 0 is the attraction of the firefly at the light source (d = 0), generally taken as 1; γ is the light absorption coefficient, and the theoretical value range is [0, ¥); d ab is the distance between the firefly a and the firefly b; F is calculated according to equation (2).
In order to prevent the optimization from falling into the optimal local solution, random disturbance (Wang et al., 2017) is added to the attraction function: In equation (8), rand1 and rand2 represent two random numbers with a range of [0, 1]. The firefly b moves to the firefly a under the action of the attraction β ab , and its position update equation is as follows (Li et al., 2015;Wang et al., 2017;Yang, 2009): In the equation: t is the number of iterations of the algorithm, α is the step size factor, rand Î [−NWS/10, NWS/10] is a random number, and NWS is the number of candidates for Web services in each type of task. In order to better approximate the optimal solution, adaptively modify the step size according to the number of iterations (Wang et al., 2017), where G max represents the maximum number of iterations of the algorithm: Suppose that after the firefly population moves, the optimal solution in the population is not updated. In that case, this iteration is considered invalid, and some fireflies are selected for Exchange and Mutation. Exchange refers to selecting the fireflies with the top 1/4 of the objective function value, calculating the current Web service appearance probability of each firefly, and exchanging 1-3 Web services with low appearance probability to Web services with high appearance probability. The mutation is to select the fireflies whose objective function value is ranked as the last 1/2, calculate the probability of each web service task, and mutate 1-3 web services with a higher chance into any web service.

Algorithm Flowchart
This paper introduces an enhanced firefly algorithm for the Web service composition to better solve this problem. The specific algorithm implementation flow chart is shown in Figure 4. The specific steps of the firefly algorithm: Step 1: Input data, load the QoS attributes of all candidate Web services, store them according to their task categories, use equation (4) to calculate and sort the Q values of the Web services in each task.
Step 2: Initialize the firefly algorithm parameters: population size n, iteration size Maxiteration, light intensity absorption coefficient g, maximum attraction b0, and step factor a.
Step 3: Initialize the firefly population and assign a random solution vector to each firefly.
Step 4: Calculate the current optimal solution in the firefly population based on the existing population, use equations (2) to calculate the fitness value F of each solution, and record the maximum F value of the population and its corresponding solution.
Step 5: Individuals in the firefly population move to the corresponding firefly according to their respective brightness. Use equations (6)(7)(8) to calculate the attractiveness bab between firefly a and b, and then use equations (9)(10) Update the solution represented by the moving firefly and use equation (2) to update the fitness value F of the moving firefly.
Step 6: Calculate the optimal solution of the current population and determine whether the population's optimal solution has been improved after the firefly population has relocated and otherwise exchange the better 1/4 individuals in the population. Mutate the worst 1/2 individual in the firefly population. If yes, go to step 7.
Step 7: Determine whether the algorithm termination condition is met, output the optimal solution if it is satisfied, otherwise skip to step 4 to continue execution.

SIMULATIoN EXPERIMENT Experimental Environment and Data
All the calculation examples in this article are completed under the Ubuntu operating system. The computer CPU model is Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz, the quantity is 2, and the memory is 32GB. The algorithm's code implementation is based on Python 3.8.0, and the Numpy library version 1.20.3 is adopted in the calculation. Database1, Database2, Database3, and Database4 employed in the experiment are real data sets constructed based on the real QWS data sets (Al-Masri & Mahmoud, 2007a, 2007b) QWS1 and QWS2. Among them, QWS1 and QWS2 contain 365 and 2507 essential web services, respectively, each in the data set Web services to include nine QoS attributes. This experiment selects three types of QoS attributes: response time, availability, and reliability. Due to its lack of cost and energy attributes, they are randomly generated. The cost is in the range of 45-50. And the energy is in a normal distribution with a mean of 25 and a variance of 5. Refer to Table 2 for the number of tasks in the dataset and Web services in the tasks.
In order to compare the pros and cons of the algorithms, the experiments selected genetic algorithm(GA) (Amiri & Serajzadeh, 2010) (Dahan et al., 2021) were tested in the same data set, and each group of experiments was repeated 50 times. To explain how the enhanced firefly algorithm (EFA) performs in different task quantities and under different Web services, expand the number of Web services or tasks based on a fixed number of tasks of 30 and a Web service of 30, respectively. Each combination is repeated 20 times based on the same data set experiment.   Table 3.

Figure 5
results from seven algorithms running 50 times on the simulation data set Database1 with 10 tasks and 30 candidate Web services. There are nine segments: the average running time of the algorithm(mean-T), the average fitness(mean-V), the maximum running time of the algorithm(max-T), the maximum fitness of the algorithm(max-V), the coefficient of variation of the algorithm running time(cv-T), the coefficient of variation of the fitness(cv-V), the energy of the web service composition (E), the energy efficiency of the fitness(mean-V/E), the energy efficiency of the running time(mean-T/E). Figure 6, Figure 7, Figure 8 are the comparison results of the EFA and the other six algorithms under the data sets with different task numbers and different candidate Web service numbers.
In summary, as shown in the above four figures, the EFA has no apparent advantage in running time, and adaptability is preferable when the data set is small. And, it has lower energy consumption and higher energy efficiency in time and fitness. Meantime, it has lower energy consumption and higher energy efficiency in time and fitness. When the data set is considerable, the EFA runs less time to optimize web service combinations. The result is more stable; the fitness value is significantly better than other algorithms; the maximum value is considerably higher than other algorithms; the coefficient of variation is the smallest; the energy efficiency of the fitness is exceptionally superior to other algorithms. Comparing Figure 5 and Figure 8, when the number of tasks in the Web service composition is more numerous than the number of Web services, the EFA runs faster than the ACO, the FACO, and the EFACO. It is better than the SA in the coefficient of variation of the running time. It is significantly better than the other six algorithms in the solution of the best web service combination. At the same time, the coefficient of variation of the result is the smallest, and the energy efficiency is the highest. Figures 9 and 10 show the energy consumption of the seven algorithms when the number of fixed web services or tasks is 30. As shown in the figure, as the number of tasks or web services rises, the energy consumption of EFA is at a comparatively high level. Figures 11 and 12 show the comparison of runtime energy efficiency (T/E) among the seven algorithms when the number of fixed candidate Web services for web service combination is 30 or when the number of set tasks is 30. As the number of tasks or candidate Web services improvements, compared with ACO, FACO, and EFACO, the time required for the EFA algorithm to consume unit energy, the energy consumption rate gradually decreases as the number of tasks or the number of candidate Web services increase. The reduction is much smaller than the ACO, the FACO, and the EFACO. The overall trend is similar to the GA and the IA. Figure 13 and Figure 14 display the comparison of the energy efficiency of the service quality(V/E) among the seven algorithms when the number of fixed candidate Web services for web service combination is 30 or when the fixed task is 30. With the increase of the number of tasks or Web services, the energy efficiency of the EFA algorithm is more reliable than that of the other six algorithms.
In summary, in optimizing web service composition, the EFA has achieved more dependable calculation results with less energy investment. The EFA has a more excellent appearance in solving this problem.

DISCUSSIoN
Web service portfolios introduce a new paradigm for distributed applications. However, the rapid growth of web service provisioning leads to the availability of many web services (WSs) that can perform the same task. It is challenging to construct a good web service portfolio workflow from many optional web services in a limited time. Here, we propose an enhanced firefly algorithm based on the QoS property of web services. We are demonstrating the implementation of the firefly algorithm through a custom transformation to adapt it to the web service combination (WSC) problem to achieve faster convergence and better merit search results. Xin She Yang initially developed the Firefly algorithm as a nature-inspired metaheuristic algorithm for solving continuous optimization problems. However, FA can also solve discrete permutation problems such as the TSP problem and the flow shop scheduling problem. However, few studies have been conducted on applying the FA algorithm to the web service composition problem, which proved to be an NP-hard problem. We improve and optimize FA for solving the web service combination problem. At the same time, our method takes a similar index encoding approach in the EDFA and DFA algorithms. Also, it computes Q k (Equation 4) based on the QoS property of individual web services for ranking, which enhances the ability of the algorithm to avoid local minimal traps to some extent. On the other hand, we improved the diversity of results to search for high-quality solutions by adopting a randomization mechanism in processing the attractiveness β ab of fireflies (Equation 8). In addition, the randomization parameter α of the algorithm decreases gradually with the number of EFA iterations. This allows the algorithm to maintain high flexibility in the early iterations to obtain more excellent solutions. Still, as the number of iterations increases and the current optimal solution is already at a high level, the decrease of α helps to reduce the exploration of other sub-optimal results by EFA. This allows EFA to obtain better solutions within a more limited number of iterations and reduce the solution search time. Experimentation of these methods in EFA shows that the EFA algorithm has superior solving power and less solution time than other metaheuristics (Figure 6-8).
In addition, from a higher level, deep learning has its advantages over EFA-like heuristics in solving web service combination problems. Firstly, it has excellent learning ability and excellent solving ability. Secondly, it is highly adaptable and can be applied more easily and quickly in the face of web service combination problems. In addition, because of the data-driven nature of deep learning, the deep learning algorithm's performance will be further improved through the continuous increase of data sets and training iterations, which can better solve the web service combination problem. The research on deep learning in service combinations is also increasing gradually (Moustafa & Zhang, 2013). For example, Huagang Liang used PD-DQN to solve the service combination problem in cloud manufacturing (Liang et al., 2021). Hongbing Wang proposed a new service combination scheme based on the deep reinforcement learning (DRL) POMDP-WSC model . However, there are some disadvantages of deep-learning methods. High computational effort and high model complexity this back makes the solution time of the algorithm prolonged, which is difficult to meet when facing the needs of time-sensitive tasks (Liu & Lang, 2019). High data dependency, poor interpretability and possible bias, etc., make it easier for previously trained models to cope with new situations when the environmental data changes (Johnson & Khoshgoftaar, 2019;Shinde & Shah, 2018). Considering their respective advantages and disadvantages, we believe that metaheuristics and deep learning algorithms complement each other. Integrating these two algorithms for application in solving web service problems may be helpful, where better solutions are obtained faster and more efficiently.

CoNCLUSIoN
This paper analyzes the optimization of QoS-based Web service composition. It implements a new firefly algorithm with superior performance, EFA, which brings the population solution approaching the optimal solution in the traditional firefly algorithm to the principle of selection, exchange, and mutation in the genetic algorithm. The combination of mechanisms makes the enhanced firefly algorithm more fitting for optimizing Web service composition, diminishing the running time, and promoting the value of the objective function. The algorithm has two main innovations: adding random disturbances when calculating the moving distance to adapt to the Web service composition problem; after the iteration is completed, the firefly population is exchanged and mutated. This mutation and exchanged increase the diversity, allow firefly to explore, and obtain a more dependable solution. Experiments have demonstrated that the EFA algorithm is superior to the EFACO, FACO, ACO, SA, IA, and GA algorithms in operating speed, robustness, and energy efficiency. In addition, in the application of large-scale data, compared to other algorithms, the EFA algorithm has more robust superiority.