# Query Optimization in Distributed Database Based on Improved Artificial Bee Colony Algorithm
## 2 Proposed Method
### Improved Artificial Bee Colony Algorithm
Then, retain the three most used sites (S\({}_{1}\), S\({}_{5}\), S\({}_{3}\)), perturb the remaining three sites (S4, S2, S6), and re-select the used sites in the corresponding search domains for the data shardings using the perturbed nodes according to Equation (1). In this way, the lesser-used sites are perturbed in each iteration in order to increase the site concentration of the query plan. Meanwhile, a dynamic perturbation factor \(\eta\) is proposed so that the perturbation coefficient changes dynamically with the change in the whole population state during the iteration of the algorithm. Since the fitness values of food sources in the population are converging as the population iteration progressing, i.e., the concentration of sites in each query plan is increasing, a food source with a better fitness value for the population should be updated using a lower perturbation coefficient. If the perturbation coefficient is too large, the sites that are originally used more may be re-randomized as well, which is detrimental to the optimization of the food source. The specific dynamic perturbation factor \(\eta\) is shown in Equation (4):  
\[\eta=1+(Fit_{i}-Fit_{best})\cdot\frac{L-t}{L} \tag{4}\]  
where \(L\) is the parameter for the maximum number of iterations of the algorithm, \(t\) is the current number of iterations, \(Fit_{i}\) is the fitness value of honey source \(X_{i}\) in the population under the current number of iterations, and \(Fit_{best}\) is the fitness value of the best honey source in the population under the current number of iterations. The perturbation coefficient \(\delta\) for each specific food source is obtained as in Equation (5):  
\[\delta=\delta^{\prime}\cdot\eta \tag{5}\]  
where \(\delta^{\prime}\) is the perturbation coefficient set during the initialization of the algorithm, and \(\eta\) is the perturbation factor of the current food source calculated according to the Equation (4). The third step is the follower bee search phase. Based on the food source information shared by the leader bees, the probability that the leader bees are followed by the follower bees is calculated by Equation (6):  
\[P_{i}=\frac{Fit_{i}}{\sum\limits_{i}^{N}Fit_{i}} \tag{6}\]  
where \(Fit_{i}\) is the fitness value of the i-th food source. Then, the follower bees adopt the roulette method to follow a leader bee. Equivalently, a uniformly distributed random number \(r\) is generated in [0, 1] and, if \(P_{i}\) is greater than \(r\), this follower bee generates a new food source based on the food source \(i\) according to Algorithm 1. Then, the retained food source is determined by the greedy selection method used in the leader bee phase. The fourth step is the scout bee search phase. When a leader bee searches for a food source \(X_{i}\), if the food source is not updated, the number of searches for this food source trail is recorded, plus 1. If the food source \(X_{i}\) reaches the threshold limit after trial iterations of search and no better food source is found, then this food source \(X_{i}\) will be abandoned, and the corresponding leader bee will be changed to a scout bee. The scout bee will generate a new food source \(Z_{i}\) based on this food source \(X_{i}\), according to Algorithm 1, but with a larger perturbation coefficient. The same greedy selection method will be used to determine the retained food source, while the number of searches of this food source is reset to 0, as shown in the equation below:  
\[X_{i}^{t+1}= \begin{cases}Algorithm1(X_{i},\delta\cdot 1.5),trial_{i}>limit\\ X_{i}^{t},trial_{i}<limit\end{cases}  \tag{7}\]  
where \(t\) is the current number of iterations and trial\({}_{i}\) is the number of times the food source \(X_{i}\) has been searched for.