# Dynamic Cost Ant Colony Algorithm to Optimize Query for Distributed Database Based on Quantum-Inspired Approach

^{1}

^{2}

^{*}

## Abstract

**:**

## 1. Introduction

**Exhaustive Search**algorithms have exponential worst-case running time and exponential space complexity, which can lead to an algorithm requiring an infeasible amount of time to optimize large user queries [5]. Since exhaustive algorithms enumerate over the entire search space, the algorithm will always find the optimal plan based upon the given cost model. The traditional dynamic programming (DP) enumeration algorithm is a popular exhaustive search algorithm, which has been used in a number of commercial database management systems [8].

**Heuristic-based**algorithms were proposed with the intention of addressing the exponential running time problem of exhaustive enumeration algorithms. Heuristic-based algorithms follow a particular heuristic or rule in order to guide the search into a subset of the entire search space [4]. Typically, these algorithms have polynomial worst-case running time and space complexity but the quality of the plans obtained can be orders of magnitude worse than the best possible plan. Iterative dynamic programming (IDP) is an example for a heuristic-based algorithm [9].

**Randomized**algorithms consider the search space as a set of points each of which correspond to a unique QEP [2]. A set of moves M is defined as a means to transform one point in space into another i.e., a move allows the algorithm to jump from a point in space to another. If a point p can be reached from a point q using a move m $\in $ M, then we say that an edge exists between p and q. Randomized-based models and algorithms are applied with success to several optimization issues. Simulated annealing (SA), iterative improvement (II), and genetic algorithm (GA) have been suggested to optimize large scale recursive queries [10,11,12].

## 2. Preliminaries

#### 2.1. Ant Colony Optimization

_{k}is the length of the round created by ant k. When building the solution, the ants choose the next node that should be visited according to a randomized mechanism. When ant k is in node i and has so far constructed the partial solution s

^{p}, the probability of going to node j is given by:

^{p}) is the set of feasible nodes. The relative significance of the pheromone in contrast to the heuristic information η

_{ij}, controlled by the parameters α and β and obtained using distance d

_{ij}by:

_{ij}formulates a distance or cost from nodes i to the connected node j.

#### 2.2. Quantum-Inspired Evolutionary Algorithms

#### 2.3. Problem Definition

## 3. Related Work

## 4. The Proposed Technique

#### 4.1. Cost Model

_{join}+ COM

_{Ri},

_{join}is the cost of the join process and COM

_{Ri}represents the cost of transferring entity R

_{i}among the location of sites. The IO

_{join}cost is computed as:

_{join}= (P

_{join}+ P

_{write}) ∗ IO(S

_{k}),

_{k}) is the I/O time for the disk in location S

_{k}, P

_{write}is the page count that is required to save the join outcome, and P

_{join}is the page count accessed to perform the join process between R

_{i}and R

_{j}. P

_{join}is computed as:

_{join}= P

_{Ri}∗ P

_{Rj},

_{Ri}is the page count in entities R

_{i}and R

_{j}. P

_{write}is computed as:

_{i}) is the tuple count in R

_{i}, len(R

_{i}) is the average length for tuple in R

_{i}, and ps is the size of page. The cost of required to transfer relation R

_{i}from location S

_{k}to location S

_{p}is computed by:

_{Ri}= card(R

_{i}) ∗ len(R

_{i}) ∗ COM(S

_{k}, S

_{p}),

_{k}, S

_{p}) is the time needed to move one byte from location S

_{k}to location S

_{p}.

#### 4.2. Build Search Space

#### 4.3. Search Strategy

**Step 1. Initialization.**In this phase, all the parameters used in the model are initialized, depending on work in [31], experimentally. Minor changes were done to the constant values α, β, and ρ. The value of α used as 3 instead of 1, the value of β used as 2 instead of 5, and the value of ρ used as 0.02 instead of 0.1. These changes in the values increased the dependence of our work on the cost, instead of pheromone, and give a better result, while identifying the next entity in the join order. The number of ants will be determined, and pheromone trails will be initialized. All pheromone values will be initialized by an arbitrary small value equal to $\frac{1}{\sqrt{No.OfEntities}}$. The query graph that links the tables (entities) is generated such that every table is connected to all other tables. In this phase, each entity will be associated with a qubit and all entities’ qubit probability amplitudes will be initialed as ${a}_{i}={b}_{i}=\frac{1}{\sqrt{2}}$ which satisfy Equations (5) and (6):

**Step 2.**For each ant, select random entity and uses it as the start-up point for the journey of the ant. This entity transfers to the virtual vertex and waits to choose the following entity to implement the join process.

**Step 3.**Use a partial negation quantum gate to choose the next entity in join sequence. The selection will be done by applying the negation gate, as operator, on all entities’ qubit that have a connection path with the current entity. This process will be applied many times according to the amount of pheromone that is raised on the path between the current entity and the connected entities. Then, the entity with best probability will be selected as the next entity. Let X be the Pauli-X gate, which is the quantum equivalent to the NOT gate and represented as:

^{th}partial negation for operator V is the c

^{th}root of the X gate and can be calculated using diagonalization as follows:

^{d}= X. When d = c = 2, this will give ${t}^{2}=-1$ and so:

**Step 4.**Instead of selecting the entity with better probability in the normalized vector as the next entity in the join order, the roulette wheel method is used to give the entities with small probability a chance to share in building the query join order.

**Step 5.**After choose the next entity, the join cost is determined and the outcome of the join process is transferred to the virtual vertex and afterward utilized as the beginning up entity for the following ant’s cycle. Equations (7)–(11) are used to determine the join cost.

**Step 6.**Repeat steps from 3 to 5 till all entities are handled and then the journey cost for the ant is calculated.

**Step 7.**Select the best journey cost from all the journeys for ants.

**Step 8. Pheromone update.**At the point when all the ants build their solutions and, in each cycle, the update of pheromone is performed. Every pheromone amount is reduced, to simulate the pheromone evaporation, and raised, to simulate the ant’s pheromones deposit on the trail. The modification of pheromone on all graphs’ arcs is done using Equation (1). The modifications of the pheromone are also dependent on ${L}_{k}$ in Equation (2) that symbolize the total cost of the better tour created by ant k.

**Step 9.**Repeat steps from 2 to 8 until maximum iterations and when the cycles complete, the best trail for all ants is chosen.

Algorithm 1. QIACO |

(1) $\mathrm{Initialize}\mathrm{values}\mathrm{for}\alpha ,\beta ,\rho ,Q,$Max-Iteration, Ant-Numbers // (step 1) |

(2) $\mathrm{Initialize}\mathrm{pheromone}\mathrm{by}{\tau}_{ij}=\frac{1}{\sqrt{No.OfEntities}}$. // (step1) |

(3) $\mathrm{Initialize}\mathrm{all}\mathrm{Qubit}\mathrm{by}|{\psi}_{i}\rangle $
= [1/sqrt(2); 1/sqrt(2)] // (step 1) |

(4) $t=0$ |

(5) Loop (cycle < Max-Iteration) |

(6) $t=t+1$ |

(7) StartEntity = random beginning entity // (step2) |

(8) Loop (ant < Ant-Numbers) |

partialStep = NegationGate(ant, StartEntity) // (step 3) |

NextEntity = ChooseNextEnity (partialStep) // (step 4) |

CalculateCost(StartEntity, NextEntity) // (step 5) |

StartEntity = NextEntity |

(9) EndLoop // (step 6) |

(10) Identify best trail for ants. // (step 7) |

(11) Modify the pheromones. // (step 8) |

(12) EndLoop // (step 9) |

(13) Identifybest trail for the solution |

**Convergence of the Model.**In [33], the author proves that the convergence of ACO depends on the pheromone value ${\tau}_{ij}$ from Equation (1) and heuristic information η

_{ij}, from Equation (4). The suggested model still depends on Equation (1) for updating the pheromone. Additionally, Equation (4) represents the inverse of cost which is used in the suggested model to find the best route obtained by ants. So, the convergence of the suggested model is guaranteed.

**Complexity analysis.**As in [34], the computational complexity of the most classical ant colony algorithms depends on the number of nodes n, the number of ants m, and the number of iterations T (the colony lifetime). Considering Equation (3) in more detail, we can notice that the computational complexity of the algorithm also depends on the parameters α and β. Here, the computational complexity was explained as:

^{2}). So, the overall computational time for the quantum part in our model is O(n) + O(n

^{2}) which can reduced to O(n

^{2}). Hence, the computational complexity for our QACO algorithm is:

Algorithm 2. Partial Negation Gate |

Function NegationGate(antX, currentEntity) |

(1) QGate = [0 1;1 0] |

(2) For (entity = 1 to Number-of-Entities) |

If entity is visited then |

partialStep[entity] = $0.1*{10}^{-10}$; very small value |

continue |

End IF |

cost = CalcCost(currentEntity, entity) |

ph = GetPheromone(currentEntity, entity) |

$tau=p{h}^{\propto}*cos{t}^{\beta}$ |

$|{\psi}_{i}^{t+1}\rangle =QGat{e}^{tau}*|{\psi}_{i}^{t}\rangle $ |

partialStep[entity] = $|{\psi}_{i}^{t+1}\rangle $ |

(3) End For |

(4) Return partialStep[entity] |

#### 4.4. Limitation

- This algorithm uses the total query time calculated for distributed query optimization as the model’s cost.
- The algorithm applies for non-replicated entities.

Algorithm 3. Choose Next Enity |

Function ChooseNextEnity(partialStep) |

NRV= NormalizeVictore(partialStep) |

SelectedEntity = RouletteWheel(NRV)Return SelectedEntity |

## 5. Experimental Results

^{−3}, and 0.98 × 10

^{−4}, respectively.

## 6. Conclusions

## Author Contributions

## Funding

## Institutional Review Board Statement

## Informed Consent Statement

## Data Availability Statement

## Conflicts of Interest

## References

- Ramakrishnan, R. Databases Management Systems, 3rd ed.; McGraw-Hill Inc.: New York, NY, USA, 2003. [Google Scholar]
- Tiwari, M.P.; Chande, S.V. Query Optimization Strategies in Distributed Databases. Int. J. Adv. Eng. Sci.
**2013**, 3, 23–29. [Google Scholar] - Dokeroglu, T.; Cosar, A. Dynamic Programming with Ant Colony Optimization Metaheuristic for Optimization of Distributed Database Queries. In Proceedings of the 26th International Symposium on Computer and Information, London, UK, 26–28 September 2011; pp. 107–113. [Google Scholar]
- Sharma, M.; Gurvinder, S.; Rajinder, S. A Review of Different Cost-based Distributed Query Optimizers. Prog. Artif. Intell.
**2019**, 8, 45–62. [Google Scholar] [CrossRef] - Hameurlain, A.; Morvan, F. Evolution of Query Optimization Methods. Lect. Note Comput. Vis.
**2009**, 5740, 211–242. [Google Scholar] - Chen, M.; Yu, P. Using Join Operations as Reducers in Distributed Query Processing. Proceedings of 2nd International Symposium on Databases in Parallel and Distributed System, Dublin, Ireland, 2–4 July 1990. [Google Scholar]
- Pramanik, S.; Vineyard, D. Optimizing join queries in distributed databases. IEEE Trans. Softw. Eng.
**1988**, 14, 1319–1326. [Google Scholar] [CrossRef] - Raipurkar, A.; Bamnote, G.R. Query Processing in Distributed Database through Data Distribution. Int. J. Adv. Res. Comput. Commun. Eng.
**2013**, 2, 1134–1139. [Google Scholar] - Kossmann, D.; Konrad, S. Iterative dynamic programming: A new class of query optimization algorithms. ACM Trans. Database Syst.
**2000**, 25, 43–82. [Google Scholar] [CrossRef] - Ioannidis, Y.E.; Younkyung, K. Randomized Algorithms for Optimizing Large Join Queries. ACM Sigmod Rec.
**1990**, 19, 312–321. [Google Scholar] [CrossRef] - Horng, J.T.; Cheng-Yan, K.; Baw-Jhiune, L. A Genetic Algorithm for Database Query Optimization. In Proceedings of the First IEEE Conference on Evolutionary Computation, Orlando, FL, USA, 27–29 June 1994; pp. 432–444. [Google Scholar]
- Sevinc, E.; Cosar, A. An Evolutionary Genetic Algorithm for Optimization of Distributed Database Queries. Comput. J.
**2010**, 54, 717–725. [Google Scholar] [CrossRef] - Ristè, D.; Da Silva, M.P.; Ryan, C.A.; Cross, A.W.; Córcoles, A.D.; Smolin, J.A.; Gambetta, J.M.; Chow, J.M.; Johnson, B.R. Demonstration of quantum advantage in machine learning. NPJ Quantum Inf.
**2017**, 3, 16. [Google Scholar] [CrossRef] - Kuo, S.; Yao-Hsin, C.; Chi-Yuan, C. Quantum-inspired algorithm for cyber-physical visual sur-veillance deployment systems. Comput. Netw.
**2017**, 117, 5–18. [Google Scholar] [CrossRef] - Mohsin, S.A.; Darwish, S.M.; Younes, A. Dynamic Cost Ant Colony Algorithm for Optimize Distributed Database Query. In Proceedings of the Artificial Intelligence and Computer Vision (AICV2020), Cairo, Egypt, 8–10 April 2020. [Google Scholar]
- Dorigo, M.; Birattari, M.; Stützle, T. Ant Colony Optimization. IEEE Comput. Intell. Mag.
**2006**, 1, 28–39. [Google Scholar] [CrossRef] [Green Version] - Dorigo, M.; Stuzle, T. Ant Colony Optimization; MIT Press: Cambridge, MA, USA, 2004. [Google Scholar]
- Han, K.H.; Kim, J.H. Quantum-inspired evolutionary algorithm for a class of combinatorial optimization. IEEE Trans. Evol. Comput.
**2002**, 6, 580–593. [Google Scholar] [CrossRef] [Green Version] - Narayan, A.; Chellapilla, P. A novel quantum evolutionary algorithm for quadratic knap-sack problem. In Proceedings of the 2009 IEEE International Conference on Systems, Man and Cybernetics, San Antonio, TX, USA, 11–14 October 2009; pp. 1388–1392. [Google Scholar]
- Kaye, P.; Laflamme, R.; Mosca, M. An Introduction to Quantum Computing; Oxford University Press: New York, NY, USA, 2007. [Google Scholar]
- Rana, M.S.; Mohammad, K.S.; Shohel, A. Distributed Database Problems, Ap-proaches and Solutions—A Study. Int. J. Mach. Learn. Comput.
**2018**, 8, 472–476. [Google Scholar] - Steinbrunn, M.; Moerkotte, G.; Kemper, A. Heuristic and Randomized Optimization for the Join-Ordering Problem. Int. J. Very Large Data Bases
**1997**, 6, 191–208. [Google Scholar] [CrossRef] - Zhou, Z. Using Heuristics and Genetic Algorithms for Largescale Database Query Optimization. J. Inf. Comput. Sci.
**2007**, 2, 261–280. [Google Scholar] - Ban, W.; Jiming, L.; Jichao, T.; Shiwen, L. Query optimization of distributed database based on par-allel genetic algorithm and max-min ant system. In Proceedings of the 8th International Symposium on Computational Intelligence and Design (ISCID), Hangzhou, China, 12–13 December 2015; Volume 2, pp. 581–585. [Google Scholar]
- Li, N.; Liu, Y.; Dong, Y.; Gu, J. Application of Ant Colony Optimization Algorithm to Multi-Join Query Optimization. In Proceedings of the 3rd International Symposium on Intelligence Computation and Applications, Berlin/Heidelberg, Germany, 19–21 December 2008. [Google Scholar]
- Golshanara, L.; Rankoohi, S.M.T.R.; Shah-Hosseini, H. A multi-colony ant algorithm for optimizing join queries in distributed database systems. Knowl. Inf. Syst.
**2014**, 39, 175–206. [Google Scholar] [CrossRef] - Zhang, G. Quantum-inspired evolutionary algorithms: A survey and empirical study. J. Heuristics
**2011**, 17, 303–351. [Google Scholar] [CrossRef] - Chmiel, W.; Kwiecień, J. Quantum-Inspired Evolutionary Approach for the Quadratic Assignment Problem. Entropy
**2018**, 20, 781. [Google Scholar] [CrossRef] [Green Version] - Darwish, S.M.; Shendi, T.A.; Younes, A. Quantum-inspired genetic programming model with application to predict toxicity degree for chemical compounds. Expert Syst.
**2019**, 36, e12415. [Google Scholar] [CrossRef] - Dey, S.; Bhattacharyya, S.; Maulik, U. New quantum inspired meta-heuristic techniques for multi-level colour image thresholding. Appl. Soft Comput.
**2016**, 46, 677–702. [Google Scholar] [CrossRef] - Tiwari, P.; Chande, S.V. Optimal Ant and Join Cardinality for Distributed Query Optimization Using Ant Colony Optimization Algorithm. In Proceedings of the 2nd International Symposium on Emerging Trends in Expert Applications and Security, Singapore, 17–18 February 2018. [Google Scholar]
- Younes, A. Reading a single qubit system using weak measurement with variable strength. Ann. Phys.
**2017**, 380, 93–105. [Google Scholar] [CrossRef] [Green Version] - Duan, H. Ant colony optimization: Principle, convergence and application. In Handbook of Swarm Intelligence; Springer: Berlin/Heidelberg, Germany, 2011; pp. 373–388. [Google Scholar]
- Kazharov, A.A.; Kureichik, V.M. Ant colony optimization algorithms for solving transportation problems. J. Comput. Syst. Sci. Int.
**2010**, 49, 30–43. [Google Scholar] [CrossRef] - James, M. Test Run—Ant Colony Optimization. Msdn Mag.
**2012**, 27, 2. Available online: https://docs.microsoft.com/en-us/archive/msdn-magazine/2012/february/test-run-ant-colony-optimization (accessed on 30 December 2020). - Deshpande, A.; Hellerstein, J.M. Decoupled query optimization for federated database systems. In Proceedings of the 18th International Conference on Data Engineering, San Jose, CA, USA, 26 February–1 March 2002; pp. 716–727. [Google Scholar]

**Figure 1.**Overall Structure of Quantum-inspired evolutionary algorithms [18].

**Figure 9.**Comparison between classical ACO and QIACO (Fixed number of sites =1 and different entities from 3 to 15).

**Figure 10.**Comparison between minimum cost for classical ACO and QIACO (fixed number of entities = 10 and sites from 1 to 5).

**Figure 11.**Comparison between average cost for classical ACO and QIACO (fixed number of entities = 10 and sites from 1 to 5).

**Figure 12.**TPC-H benchmark queries [36].

**Table 1.**Parameters for the Ant Colony Optimization algorithm [31].

Parameter | Description | Value |
---|---|---|

$\alpha $ | Pheromone influence factor | 3 |

$\beta $ | The influence of heuristic | 2 |

$\rho $ | Pheromone evaporation rate | 0.02 |

Q | Constant used while pheromone update | 2 |

Max-Iteration | Varies with the number of entities | - |

Ant-Numbers | Varies with the number of entities | - |

**Table 2.**TPC-H tables [36].

Table Name | Number of Tuples | Tuple Size | Table Name | Number of Tuples | Tuple Size |
---|---|---|---|---|---|

Lineitem | 6,000,000 | 120 | orders | 1,500,000 | 100 |

Partsupp | 800,000 | 140 | Part | 200,000 | 160 |

Customer | 150,000 | 180 | supplier | 10,000 | 160 |

Nation | 25 | 120 | region | 5 | 120 |

Site | Tables |
---|---|

1 | supplier, partsupp |

2 | orders, lineitem |

3 | nation, region, customer |

4 | Part |

No. of Entity | ACO | QIACO | Perform-ance % | ||||||
---|---|---|---|---|---|---|---|---|---|

No. of Iterations | Worst Cost | Average Cost | Best Cost | No. of Iterations | Worst Cost | Average Cost | Best Cost | ||

5 | 100 | 0.01341 | 0.01304 | 0.01239 | 100 | 0.01138 | 0.01138 | 0.01138 | 12.73 |

10 | 100 | 0.88999 | 0.352626 | 0.10301 | 100 | 0.23963 | 0.11929 | 0.06968 | 66.17 |

15 | 300 | 6538.64340 | 2367.65590 | 158.82610 | 100 | 58.25450 | 18.66170 | 2.34710 | 99.21 |

20 | 300 | 51,574.72700 | 20,818.50940 | 1506.29500 | 100 | 9689.55970 | 4627.87840 | 890.40500 | 77.77 |

Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |

© 2021 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Mohsin, S.A.; Younes, A.; Darwish, S.M.
Dynamic Cost Ant Colony Algorithm to Optimize Query for Distributed Database Based on Quantum-Inspired Approach. *Symmetry* **2021**, *13*, 70.
https://doi.org/10.3390/sym13010070

**AMA Style**

Mohsin SA, Younes A, Darwish SM.
Dynamic Cost Ant Colony Algorithm to Optimize Query for Distributed Database Based on Quantum-Inspired Approach. *Symmetry*. 2021; 13(1):70.
https://doi.org/10.3390/sym13010070

**Chicago/Turabian Style**

Mohsin, Sayed A., Ahmed Younes, and Saad M. Darwish.
2021. "Dynamic Cost Ant Colony Algorithm to Optimize Query for Distributed Database Based on Quantum-Inspired Approach" *Symmetry* 13, no. 1: 70.
https://doi.org/10.3390/sym13010070