Graph coloring using the reduced quantum genetic algorithm
- Published
- Accepted
- Received
- Academic Editor
- Siddhartha Bhattacharyya
- Subject Areas
- Algorithms and Analysis of Algorithms, Quantum Computing
- Keywords
- Quantum computing, Quantum genetic algorithms, Graph coloring
- Copyright
- © 2022 Ardelean and Udrescu
- Licence
- This is an open access article distributed under the terms of the Creative Commons Attribution License, which permits unrestricted use, distribution, reproduction and adaptation in any medium and for any purpose provided that it is properly attributed. For attribution, the original author(s), title, publication source (PeerJ Computer Science) and either DOI or URL of the article must be cited.
- Cite this article
- 2022. Graph coloring using the reduced quantum genetic algorithm. PeerJ Computer Science 8:e836 https://doi.org/10.7717/peerj-cs.836
Abstract
Genetic algorithms (GA) are computational methods for solving optimization problems inspired by natural selection. Because we can simulate the quantum circuits that implement GA in different highly configurable noise models and even run GA on actual quantum computers, we can analyze this class of heuristic methods in the quantum context for NP-hard problems. This paper proposes an instantiation of the Reduced Quantum Genetic Algorithm (RQGA) that solves the NP-hard graph coloring problem in O(N^{1/2}). The proposed implementation solves both vertex and edge coloring and can also determine the chromatic number (i.e., the minimum number of colors required to color the graph). We examine the results, analyze the algorithm convergence, and measure the algorithm's performance using the Qiskit simulation environment. Our Reduced Quantum Genetic Algorithm (RQGA) circuit implementation and the graph coloring results show that quantum heuristics can tackle complex computational problems more efficiently than their conventional counterparts.
Introduction
In general, the heuristic methods—and genetic algorithms (GA) in particular—have received a great deal of research interest, being one of the most straightforward and widely applied forms of evolutionary computation Spector (2004). Indeed, GAs represent one of the most known methods for solving optimization problems. In the context of classical computation and conventional dedicated hardware, GAs achieve only marginal performance improvements over the deterministic perspectives. Therefore, quantum computing appears as one of the possible improvement solutions to approach NP-complete problems (Udrescu, Prodan & Vlăduţiu, 2006).
Simulated genetic operators (such as mutation and crossover) and population dynamical processes (such as reproduction and selection) underpin the GA. In the simplest form, the candidate solutions to search or optimization problems are encoded in arrays, referred to as chromosomes. The algorithm begins with a randomly generated initial population of chromosomes, and then it evolves the population over multiple generations in search of an optimal solution. A genetic algorithm has four phases: initialization, selection, reproduction, and termination. Concisely, a GA is a search for the optimal solution represented by the individual chromosome with the highest fitness value.
On the other hand, as stated in Nielsen & Chuang (2002) and in Spector (2004), quantum computation is very powerful for solving various problems due to its specific properties and phenomena such as entanglement, interference, and exponential parallelism. As such, the merge between genetic algorithms and quantum computing is natural and beneficial (Udrescu, Prodan & Vlăduţiu, 2006).
This paper aims to provide a method of instantiating the Reduced Quantum Genetic Algorithm (RQGA) to solve the graph coloring problem. Our implementation solves the most recognizable form of graph coloring, namely, vertex coloring (Kwok & Pudenz, 2020). The problem requires coloring each vertex of a graph such that no two adjacent vertices have the same color. Furthermore, our approach can also solve the edge coloring problem and find the chromatic number of a graph.
Accordingly, our main contributions to the state-of-the-art are defined by the following facts:
I. RQGA is merely a framework and not a specific algorithm. Thus, our first contribution is to instantiate the framework for the graph coloring problem and provide design solutions:
We provide an original design of the fitness function such that it accepts valid and invalid individuals as arguments. (An invalid individual has a chromosome configuration that does not satisfy given conditions).
We design the Oracle quantum circuit such that the search for the highest fitness will not take place in the invalid individuals area.
We provide a solution for individual and fitness representation, inspired by the one proposed by Fabrikant & Hogg (2002).
II. Our RQGA-based solution is a purely quantum method:
Our implementation solves the graph coloring problem in $\mathcal{O}\left(\sqrt{N}\right)$ oracle queries.
The same implementation solves both the node and edge coloring forms of the graph coloring problem.
Our implementation determines the chromatic number of a graph.
Background
Quantum computing
Classical computers are built according to the laws of classical physics. Therefore, a full specification of its state can be specified by a measurable set of numbers. According to Häner et al. (2016), sustaining the pace of Moore’s law has become increasingly difficult such that an alternative should be considered to meet the power and performance requirements; one of the most prominent such alternatives is quantum computing.
According to Spector (2004), quantum computing describes computational processes that rely for their efficacy on information processing hardware having quantum mechanical properties. Thus, as mentioned in Nielsen & Chuang (2002), quantum computers offer an essential speed advantage over their classical equivalents.
While in classical computers the bit is the basic information unit, the qubit is the analogous concept for quantum computers; as mentioned in Udrescu-Milosav (2009), qubits are the fundamental information storage unit. Like the classical bit that has a state (either 0 or 1), the qubit can be in either |0⟩ or |1⟩, which correspond to the classical ones, respectively. Additionally, the qubit can also be in a superposition state
(1) $$|\psi \u27e9=\alpha |0\u27e9+\beta |1\u27e9,$$where
(2) $$\alpha ,\beta \in \mathbb{C},|\alpha {|}^{2}+|\beta {|}^{2}=1,$$until it is observed/measured. As presented in Nielsen & Chuang (2002), the first postulate of quantum mechanics states that the state of a quantum system is described by a unit vector in a complex Hilbert space, $\mathscr{H}$. Thus, a system of n-qubits (referred as quantum register) has 2^{n} computational basis states of the form |x_{0}x_{1} … x_{n} _{−} _{1}⟩, and its quantum state is a normalized vector in ${\mathscr{H}}^{2n}$,
(3) $$|\psi \u27e9=\sum _{i=0}^{{2}^{n-1}}{\alpha}_{i}|i\u27e9,\sum _{i=0}^{{2}^{n-1}}|{\alpha}_{i}{|}^{2}=1.$$
According to the second postulate of quantum mechanics, the evolution of a closed quantum system is described by a unitary transformation. Considering that |ψ_{1}⟩ is the quantum state of the system at time t_{1}, |ψ_{1}⟩ is related to the quantum state |ψ_{2}⟩ at time t_{2}, t_{1} < t_{2}, by a unitary operator U. The unitary transformation U applied by a quantum computer with n-qubits, also called a gate, is represented by a unitary matrix in ${\mathbb{C}}^{{2}^{n}\times {2}^{n}}$.
As presented in Nannicini (2020), unitary matrices are norm-presenting; considering a unitary matrix U and a vector x, ‖Ux‖ = ‖x‖. Therefore, for a n-qubit system, the quantum state $|{\psi}_{1}\u27e9\in {\mathbb{C}}^{{2}^{n}}$ is an unitary vector and the result of applying U onto state |ψ_{1}⟩,
(4) $$|{\psi}_{2}\u27e9\to U|{\psi}_{1}\u27e9,U\in {\mathbb{C}}^{{2}^{n}\times {2}^{n}},$$is the unitary vector $|{\psi}_{2}\u27e9\in {\mathbb{C}}^{{2}^{n}}$, leading to the observation that quantum operations are linear and reversible.
According to Barenco et al. (1995), any unitary transformation can be expressed as a composition of gates. Thus, infinitely many quantum gates can be constructed. A finite set of quantum gates are universal for quantum computation since any unitary transformation may be approximated by a quantum circuit involving only those gates. In Table 1 we present some basic quantum unitary transformations we use in this paper, along with the unitary matrix and the graphical representation used in the implementation of the RQGA.
Gate | Graphical representation | Unitary matrix | Description |
---|---|---|---|
Hadamard | $H={\displaystyle \frac{1}{\sqrt{2}}\left[\begin{array}{cc}1& 1\\ 1& -1\end{array}\right]}$ | $|0\u27e9\to {\displaystyle \frac{1}{\sqrt{2}}\left(|0\u27e9+|1\u27e9\right)}$ and $|1\u27e9\to {\displaystyle \frac{1}{\sqrt{2}}\left(|0\u27e9-|1\u27e9\right)}$ | |
Pauli-X | $X=\left[\begin{array}{cc}0& 1\\ 1& 0\end{array}\right]$ | $|0\u27e9\to |1\u27e9$ and $|1\u27e9\to |0\u27e9$ | |
Pauli-Y | $Y=\left[\begin{array}{cc}0& -i\\ i& 0\end{array}\right]$ | $|0\u27e9\to i|1\u27e9$ and $|1\u27e9\to -i|0\u27e9$ | |
Pauli-Z | $Z=\left[\begin{array}{cc}1& 0\\ 0& -1\end{array}\right]$ | $|1\u27e9\to |-1\u27e9$ and |0⟩ is left unchanged | |
Controlled-Not | $CNOT=\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 0& 1\\ 0& 0& 1& 0\end{array}\right]$ | $|c\u27e9|t\u27e9\to |c\u27e9|t\otimes c\u27e9$, where |c⟩ is the control qubit and |t⟩ is the target Nielsen & Chuang (2002) |
The third postulate of quantum mechanics states that quantum measurement is described by a measuring transformation of the quantum state (i.e., the measurement operator M_{m}). For a quantum state |ψ⟩, the probability that the outcome of the measurement is m is $P\left(m\right)=\u27e8\psi {M}_{m}^{\text{\u2020}}{M}_{m}|\psi \u27e9$.
The single qubit |ψ⟩ = α|0⟩ + β|1⟩ where $\alpha ,\beta \in \mathbb{C}$ and |α|^{2} + |β|^{2} = 1 is projected by the measurement onto the basis {|0⟩,|1⟩}, thus yielding the outcome |0⟩ with probability α^{2} or |1⟩ with probability β^{2}. By measurement, the quantum state is irrevocably disturbed and collapsed to the specific Hilbert space basis state, consistent with the measurement result. Therefore, for any basis states |a⟩ and |b⟩ and the quantum state |ψ⟩ = α|a⟩ + β|b⟩ with |α|^{2} + |β|^{2} = 1 expressed in terms of the orthonormal base {|a⟩,|b⟩}, the measurement can be performed with respect to the |a⟩ and |b⟩ basis and the outcome will be |a⟩ with probability α^{2} or |b⟩ with probability β^{2}.
According to Nielsen & Chuang (2002), two principles are applied to measurement: the Principle of deferred measurement and the Principle of implicit measurement. The principle of deferred measurement states that the measurement can be moved from an intermediate stage of the circuit to its end. The principle of implicit measurement states that any unterminated quantum wires may be assumed as measured at the end of the circuit.
As presented in Nielsen & Chuang (2002), the fourth postulate describes the state space of a composite physical system as the tensor product of the state spaces of the component physical system.
Genetic algorithms and quantum computing
The literature proposes several quantum genetic algorithms, from algorithms that combine operations running on classic computers with quantum operators to genuine quantum evolutionary algorithms (Lahoz-Beltra, 2016). Using evolutionary algorithms for synthesizing quantum circuits has been thoroughly investigated and relevant progress has also been reported in the field of Quantum-Inspired Genetic Algorithm (QIGA) (Ruican et al., 2007).
In Ruican et al. (2007), the authors propose a method of synthesizing quantum circuits using genetic programming. The chosen approach is to split the potential circuits into vertical and horizontal levels used for chromosome definition. Furthermore, Ruican et al. (2008) propose an object-oriented framework for genetic algorithms in quantum circuit synthesis.
In Gepp & Stocks (2009), the authors analyze evolutionary algorithms for synthesizing quantum algorithms. They claim that genetic algorithms and genetic programming have been used with great success to analyse and optimize quantum algorithms. Moreover, by successfully evolving small new quantum algorithms, scalable quantum algorithms are proven.
In Malossini, Blanzieri & Calarco (2008), the authors propose a quantum genetic algorithm called Quantum Genetic Optimization Algorithm (QGOA). The algorithm starts with a qubit representation of the population and a quantum evaluation unit. Then, the selection step of the GA uses the quantum selection procedure, while the remaining steps (e.g., crossover, mutation, and substitution) are performed on a classical computer.
Nowotniak (2010) briefly presents Quantum-Inspired Evolutionary Algorithm (QIEA). Moreover, in Nowotniak & Kucharski (2010) the authors present the results after applying a meta-optimization algorithm for tuning the QIEA parameters for numerical optimizations problems coded in real numbers. The algorithm used for meta-optimization is based on local unimodal sampling and is applied to adjust the crossover rate and the contraction factor. According to Nowotniak & Kucharski (2010), the results show that the local unimodal sampling is an effective method for the meta-optimization of QIEAs.
Zhang (2011) presents a survey of the research in QIEAs; the author shows the differences between different solutions and compares the advantages and limitations of the various solutions. The author introduces the Binary Observation QIEA, shows that the use of Q-gates as a variation operator instead of crossover, recombination and mutation have a positive impact on the optimality of the solutions. Compared to Binary Observation QIEA, Binary Observation QIEA with crossover and mutation employs the mentioned operators to replace the migration operator with benefits in population diversity, especially in the later stages of evolution. Binary Observation QIEA with the novel update method for Q-gates, defines the Q-gate angle θ = kf(α,β), which directly influences the convergence speed. According to Zhang (2011), the algorithm also introduces the catastrophe operator; the scope of the new operator is to replace the best individual with the best individual of a new population if the best solution remains unchanged over some generations.
SaiToh, Rahimi & Nakahara (2014) introduces a novel quantum genetic algorithm with quantum crossover operation applied to all chromosomes in parallel. The proposed solution uses two identical copies of a superposition corresponding to a generation to relabel the qubits. They also show that the quantum genetic algorithm with quantum crossover operations achieves a quadratic speedup over its classical counterpart.
Kumar & Kumar (2018) propose a novel Quantum-Inspired Evolutionary View Selection Algorithm (QIEVSA). The authors also bring forward an experimental comparison with other evolutionary view selection algorithms. The method makes use of the Binary Observation QIEA algorithm to select the Top-K views from a multidimensional lattice. The authors experimentally show that QIEA is able to select good quality Top-K views for higher dimensional data sets (Kumar & Kumar, 2018).
In Moussa, Calandra & Humble (2019), the authors present an iterative quantum algorithm for finding the maximum value of a function along with the corresponding implementations. The approach utilizes quantum search and extends the RQGA with a dynamic oracle function.
Lahoz-Beltra (2016) presented a comparison between three algorithms: Quantum Genetic Algorithm (QGA), Hybrid Genetic Algorithms (HGA), and RQGA. QGA and HGA represent classical optimization methods, inspired by the principles of quantum computing. The first QGA step is the initialization of a quantum population of chromosomes; each chromosome is defined by a string of qubits. Hadamard gates and rotation around Y-axis with a random number process each qubit. Then, a classical computer performs the fitness evaluation, while a quantum computer (employing rotation gates) performs the selection. The quantum computer also performs mutation using inversion gates. Likewise, an HGA implements the above steps, the difference being that the crossover operator is also quantum.
Graph coloring applications
As mentioned in Mahmoudi & Lotfi (2015), the graph coloring problem is a well-studied NP-hard problem because of its multiple applications that include timetabling, scheduling, radio frequency assignment, computer register allocation, printed circuit board testing, and so forth.
The authors of Bincy & Presitha (2017) present the application of graph coloring in scheduling problems, such as timetable scheduling, aircraft scheduling, and seating plan design. In Dondi, Fertin & Vialette (2011), the authors present the use of graph coloring in pattern matching.
In Hennessy & Patterson (2018), the authors also present the application of graph coloring in register allocation algorithms; to this end, they build a graph representing all possible candidates for allocation to a register.
In Orden et al. (2018), the authors present the application of graph coloring to WI-FI channel assignment. Therefore, for a given spectrum of colors and a matrix of interferences between each pair of colors, the authors use the Threshold Spectrum coloring problem for fixing the number of colors available to minimize the interference threshold. Moreover, they use the Chromatic Spectrum Coloring and a given threshold to find the smallest number of colors that respect the constrain.
In Demange et al. (2015), the authors present the applications of graph coloring in routing and wavelength assignment, dichotomy-based constrained encoding, frequency assignment problems, and scheduling. As the authors mentioned, the routing and wavelength assignment problem involves generating a set of light paths for each request—routing—and selecting a light path per request, and assigning wavelengths to the selected path–wavelength assignment. To solve the problem, the optical network is transformed into a graph and the wavelengths are assigned using graph coloring. The dichotomy-based constrained encoding problem can be reduced to a graph coloring problem and, as mentioned by the authors, is used to generate asynchronous implementations of finite state machines.
Therefore, considering the large number of applications, solving graph coloring has received a great deal of research interest Dokeroglu & Sevinc (2021). For instance, in Aragón Artacho & Campoy (2018), the authors present a method for solving the graph coloring problem using the Douglas-Rachford Algorithm. Indeed, they prove that the algorithm is an effective heuristic for solving this NP-hard problem.
In Dokeroglu & Sevinc (2021), the authors propose a novel memetic Teaching-Learning-Based Optimization (TLBO) algorithm, combined with tabu search, for solving the graph coloring problem. Furthermore, they developed a version of TLBO that makes use of parallelism for solving large graphs. The authors claim that the results of the parallel version of the algorithm are better than those of its sequential counterpart, and the solution is competitive with state-of-the-art solutions presented in the literature.
Mahmoudi & Lotfi (2015) present a new approach for solving the graph coloring problem using a discrete Cuckoo Optimization Algorithm (COA). As stated by authors, the success rate of the proposed solution is above 60% for solving DIMACS (Center for Discrete Mathematics and Theoretical Computer Science) benchmark graphs, while in most cases is close to 100%.
In Tomar et al. (2013), the authors propose a novel artificial bee colony optimization algorithm for solving the graph coloring problem and compare the solutions with other algorithms such as first fit, largest degree based ordering, and saturation degree based ordering. They claim that the proposed solution can converge in a few iterations and optimally allocate colors to the vertices of a graph. As mentioned by the authors, compared to the other algorithms, their proposed solution can converge to the optimal solution in very few iterations. Moreover, they show that the performance of the artificial bee colony optimization algorithm improved with the increase of the graph size.
Graph coloring in quantum computing
Lately, quantum heuristic solutions for the graph coloring problem have received a great deal of interest. Most of the proposed solutions rely on quantum implementations of simulated annealing. In Kudo (2018), the authors use the Constrained Quantum Annealing (CQA) to solve the graph coloring problem with the advantage of reducing the Hilbert space dimension. Also, in Tabi et al. (2020) the authors introduce a space-efficient embedding for quantum circuits that solve the graph coloring problem and present the performance gain for this method. The authors indicate the limitation of the existing Quantum Annealing (QA) hardware solutions by running various numerical simulations and comparing results obtained with standard and enhanced Quantum Approximate Optimization Algorithm (QAOA) circuits.
Titiloye & Crispin (2011) propose comparing Classical Annealing and QA in solving graph coloring problems. The QA algorithm used in the comparison utilizes the Path-Integral Monte Carlo for Quantum Annealing—a population-based extension to simulated annealing inspired by quantum mechanics Titiloye & Crispin (2011). According to the authors, the QA algorithm outperforms its classical counterpart, and even finds the best algorithm solutions.
In Silva et al. (2020), the authors start by formulating the Quadratic Unconstrained Binary Optimization Problem (QUBO)—a powerful mathematical tool that can map any problem to a quantum annealing computer. Silva et al. (2020) solve the problem using different approaches: QUBO with classical simulated annealing in a simulated quantum environment, using a D-Wave quantum machine, and reducing polynomial degree using both the D-Wave library and their implementation. The results show that both Simulated Annealing and QA produce good heuristics for the graph coloring problem, although more solutions can be found using the quantum approach.
Kwok & Pudenz (2020) propose a comparison between a heuristic graph coloring approximation algorithm—based on QA—and a fully classical implementation. The metrics for calculating performance are success probability, wall clock time, and time-to-solution. For wall clock time and time-to-solution, the quantum solution performs better than its classical equivalents. As mentioned in Kwok & Pudenz (2020), the classical algorithm takes significantly longer to return a graph coloring for all graph sizes. The same is also true in the case of time-to-solution. The probability of success for the classical algorithm is lower than the quantum algorithm in the case of smaller size graphs. As the authors mention, the results of their experiments suggest a potential quantum advantage (Kwok & Pudenz, 2020).
Fabrikant & Hogg (2002) also present a quantum computer heuristic search algorithm for graph coloring. The authors consider the NP-complete case of 3 colors. For the problem representation, the authors introduce the idea of associating each node with a value from 0 to 3 (using two bits per node). As mentioned in Fabrikant & Hogg (2002), 0 represents an uncolored node, and any other value represents a specific color assigned to the node. Since the generalized Hamming distance underpins the quantum algorithm, using this representation has the benefit that the distance between the states is a simple function of their bit strings.
Shimizu & Mori (2021) present an exponential-space quantum algorithm computing the chromatic number using the Quantum Random Access Memory (QRAM); the authors also describe a polynomial-space quantum algorithm not using QRAM for the 20-coloring problem. Their main result is the theorem that states that, to solve the chromatic number problem, the running time for the exponential-space bounded error quantum algorithm using QRAM is $\mathcal{O}\left({1.9140}^{n}\right)$ (Shimizu & Mori, 2021).
Methodology
Quantum computing promises substantial speedups over conventional machines in many practical applications. To this end, the Qiskit toolchain fosters the development and simulation of quantum algorithms and applications that will run on real quantum machines Anis et al. (2021). As described in Wille, Van Meter & Naveh (2019), Qiskit is an end-to-end open-source software library for quantum computing, covering the full stack from the actual interaction with the IBM Q hardware up to the application-level algorithms. Compared to other quantum simulators, Qiskit Aer allows the execution of algorithms on noiseless or noisy simulators, so that we observe the expected results, or the effects of noise on the expected results.
Therefore, we decided to instantiate the RQGA for solving the node coloring version of the graph coloring problem. On randomly generated graphs, we employ RQGA to color the nodes such that no two adjacent nodes have the same color (see Fig. 1). Our goals are to observe the results, measure the performance of the algorithm in a simulated environment, and use the results for further algorithm development.
The Reduced Quantum Genetic Algorithm is an entirely quantum evolutionary algorithm proposed by Udrescu, Prodan & Vlăduţiu (2006), which puts forth a new methodology for running genetic algorithms on a quantum computer (Lahoz-Beltra, 2016). They also provide a design for the special-purpose oracle that works with a modified version of the maximum finding algorithm (Ahuja & Kapoor, 1999). Thus, the proposed method reduces the quantum genetic algorithm to a Grover search. The RQGA takes advantage of the fact that the best fitness value can be marked without destroying the superposition of the quantum register. In this context, Grover’s algorithm (Grover, 1996) can find the solution of the problem. The main steps of RQGA are:
Initialize a superposition of all possible chromosomes
Compute the unitary operation corresponding to fitness computation
Apply Grover’s algorithm:
– Ask the oracle O to mark the fitness value bigger than some value max
– Apply Grover’s diffusion operator G to augment the quantum amplitude of the marked fitness values
Perform the measurement to get one of the marked fitness values
Update max value with the measured fitness value
Repeat the steps above until the max value is not improved
Return the chromosome value corresponding to max as solution.
Problem statement
We consider an undirected graph G = (V,E) where V is the set of nodes and E is the set of edges. We define K as the set of colors. Our problem is to find the best way of assigning the colors in K to nodes from V, such that no two adjacent nodes have the same color (e_{ij} ∈ E with $k\left({v}_{i}\right)\ne k\left({v}_{j}\right)$ for distinct nodes v_{i} and v_{j}). Thus, coloring G is the mapping $k:V\to E$ such that $k\left({v}_{i}\right)\ne k\left({v}_{j}\right)$ if ∃e_{ij} ∈ E, as mentioned in Titiloye & Crispin (2011). The chromatic number of the graph, χ(G), can be found by first detecting the coloring for a high estimate of χ(G) and then successively narrowing the available colors.
Test graphs
Let the K be the set of colors and G = (V,E) a randomly generated Erdős-Rényi graph with a defined edge probability (Wang & Chen, 2003). In G, the number of edges in the graph is |E|, and |V| is the number of nodes.
Implementation
The first step initializes all individual–fitness register pairs |u⟩_{i} ⊗ |0⟩_{i} as
(5) $$|\psi {\u27e9}_{1}={\displaystyle \frac{1}{\sqrt{{2}^{N}}}\sum _{i=0}^{{2}^{N}-1}|u{\u27e9}_{i}\otimes |0{\u27e9}_{i}.}$$
The representation we use for graph coloring uses (Fabrikant & Hogg, 2002) work; the difference is that we consider each binary combination a color. If the number of colors used for coloring the graph is not a power of 2, then the unused combinations are considered invalid. The chromosome is a (n × |V|)-qubit quantum register, where each color is represented using n-qubits. Since there are 2^{n} − 1 possible colors, we define a subset $F\subset K$ of invalid color combinations. The quantum chromosome is a superposition of all (n × |V|)-bit classical chromosome values, representing valid and invalid individuals, see Udrescu, Prodan & Vlăduţiu (2006) (an invalid individual represents a combination that contains at least one of the invalid colors codes). The same approach can be used for edge coloring with the difference that the chromosome is a (n × |E|)-qubit quantum register. Algorithm 1 shows how to create the initial population.
1: Create the individual quantum register |u⟩ |
2: Create the fitness quantum register |fitness_{u}⟩ |
3: Create the carry quantum register |carry⟩ |
4: Create the oracle quantum register |oracle⟩ |
5: Create the positive number of edges quantum register |val⟩ |
6: Create the quantum circuit QC |
7: |u⟩ = H|u⟩ |
8: |oracle⟩ = H|oracle⟩ |
We represent the individual using a (n× |V|)-qubit individual quantum register and the fitness value using a M-qubit fitness register (see Fig. 2). As such, our algorithm uses 2^{n×} ^{|V|} − 1 quantum register pairs. In order to maintain correlation between each individual and its corresponding fitness value, the fitness function must be an unitary operator, U_{fit}, corresponding to the Boolean function $f:\{0,1{\}}^{n\times |V|}\to \{0,1{\}}^{M}$.
The next step is to calculate the fitness value for all individuals. The step is achieved by defining the function $f:\{G,K\}\to \mathbb{N}\cup \{-1\}$, $G=\left(V,E\right)$ as
(6) $$f((V,E),k)=\{\begin{array}{cc}-1& \phantom{\rule{1em}{0ex}}k\in F\\ 0& \phantom{\rule{1em}{0ex}}\nexists k\left({v}_{i}\right),k\left({v}_{j}\right)\in K,k\left({v}_{i}\right)\ne k\left({v}_{j}\right),{e}_{ij}\in E\\ x& \phantom{\rule{1em}{0ex}}\mathrm{\exists}k\left({v}_{i}\right),k\left({v}_{j}\right)\in K,k\left({v}_{i}\right)\ne k\left({v}_{j}\right),{e}_{ij}\in E,x\in \mathbb{N}.\end{array}$$
K is a set of colors
(7) $$K=\{{x}_{n-1}\dots {x}_{i}\dots {{x}_{0}}_{0},{x}_{n-1}\dots {x}_{i}\dots {{x}_{0}}_{1},\dots {x}_{n-1}\dots {x}_{i}\dots {{x}_{0}}_{j},\dots ,{x}_{n-1}\dots {x}_{i}\dots {{x}_{0}}_{|V|-1}\},$$where x_{i} ∈ {0,1} is a single bit and ${x}_{n-1}\dots {x}_{i}\dots {{x}_{0}}_{j}$ is the binary representation of a color from the set K. The fitness function returns ’−1’ if the individual is invalid and ‘0’ if there are no two adjacent nodes with different coloring. If there are adjacent nodes with different coloring, then the fitness function will return $x\in \mathbb{N}$, representing the number of edges between those nodes that met the criteria.
For solving the edge coloring problem, we can apply the same fitness function with minimal adjustments. Thus, the fitness function $f:\{G,K\}\to \mathbb{N}\cup \{-1\}$, $G=\left(V,E\right)$, returns ’−1’ if the individual is invalid (the chromosome contains at least one of the invalid colors), ’0’ if there are no two incident edges with different coloring and $x\in \mathbb{N}$, representing the number of nodes with incident edges of different coloring. Equation
(8) $$f((V,E),k)=\{\begin{array}{cc}-1& \phantom{\rule{1em}{0ex}}k\in F\\ 0& \phantom{\rule{1em}{0ex}}\nexists k\left({e}_{ij}\right),k\left({e}_{ik}\right)\in K,k\left({e}_{ij}\right)\ne k\left({e}_{ik}\right),{e}_{ij},{e}_{ik}\in E\\ x& \phantom{\rule{1em}{0ex}}\mathrm{\exists}k\left({e}_{ij}\right),k\left({e}_{ik}\right)\in K,k\left({e}_{ij}\right)\ne k\left({e}_{ik}\right),{e}_{ij},{e}_{ik}\in E\end{array}$$defines the fitness function for the edge coloring problem.
In both Eqs. (6) and (8), the fitness function accepts both valid and invalid individuals as arguments. As mentioned in Udrescu, Prodan & Vlăduţiu (2006), the values of the fitness function represented in the two’s complement belong to distinct areas in the quantum state vector representation, corresponding to valid and invalid individuals. Negative fitness values represent invalid individuals, with the most significant bit indicating the validity (‘0’ on the most significant bit position represents an invalid individual and ‘1’ represents a valid one). Thus, U_{fit} characterized by the fitness function f is an unitary operator
(9) $${U}_{fit}:|u\u27e9\otimes |0\u27e9\to |u\u27e9\otimes |{f}_{fit}(u)\u27e9,$$where |u⟩ ⊗ |0⟩ is the individual-fitness value quantum pair register. After applying
(10) $${U}_{fit}:{\displaystyle \frac{1}{\sqrt{{2}^{N}}}\sum _{i=0}^{{2}^{N}-1}|u{\u27e9}_{i}\otimes |0{\u27e9}_{i}\to {\displaystyle \frac{1}{\sqrt{{2}^{N}}}\sum _{i=0}^{{2}^{N}-1}|u{\u27e9}_{i}\otimes |{f}_{fit}(u){\u27e9}_{i}}}$$on the initial population, we obtain an assessed population
(11) $$|\psi {\u27e9}_{2}={U}_{fit}|\psi {\u27e9}_{1}={\displaystyle \frac{1}{\sqrt{{2}^{N}}}\sum _{i=0}^{{2}^{N}-1}|u{\u27e9}_{i}\otimes |{f}_{fit}(u){\u27e9}_{i}.}$$
We implement the fitness sub-circuit using n-qubit Controlled-Not gates. In Fig. 3, we present the U_{fit} sub-circuit with input and output qubits, and in Algorithm 2 we present the description of the subcircuit.
1: Create the individual quantum register |u⟩ |
2: Create the fitness quantum register | fitness_{u}⟩ |
3: Create the quantum sub-circuit U_{f it} |
4: for each individual in population do |
5: fitness_value = calculate_fitness(adjacency_matrix, individual) |
6: for i = 0 to M−1 do |
7: if fitness_value[i] = 1 then |
8: | fitnessu⟩_{i} = CNOT(|u⟩, | fitness_{u}⟩_{i}) |
9: end if |
10: end for |
11: if fitness value is valid then |
12: | fitness_{u}⟩ = CNOT(|u⟩, | fitnessu⟩valid) |
13: end if |
14: end for |
According to the algorithm presented in Udrescu, Prodan & Vlăduţiu (2006), the next step involves the random generation of value $max\in \mathbb{N},max>0$ from the interval [2^{M} ^{+ 1}, 2^{M} ^{+ 2} − 1), with M representing the size of the fitness quantum register, such that the search for the individual with the highest fitness will not occur in the invalid individuals area.
In the implementation of the graph coloring problem, an individual is invalid if it contains at least one of the invalid colors; the fitness value is −1 in that case. On the other hand, the fittest individual contains the configuration that colors the biggest number of nodes from G such that no two adjacent nodes v_{i},v_{j} have the same color. The fitness value of the fittest individual represents the number of edges between adjacent nodes with different coloring. Thus, instead of the randomly generated max value, we can use the number of edges in the graph, and so the search of the highest fitness will occur in the valid individuals area.
In the next step, we apply the Oracle and Grover diffuser m − 1 times, where m is the number of Grover Iterations.
The Oracle operates on the fitness register qubits except the validity qubit v and uses two’s complement number representation for marking the states. As such, by adding − (max + 1), (when $max\in \mathbb{N},max>0$) to the fitness value, the most significant qubit will always be 0. The corresponding basis states are marked by shifting their amplitudes and the fitness value is restored by adding max + 1. This way, the oracle ${\stackrel{~}{O}}_{max}({f}_{fit}(u))$ is applied
(12) $$|\psi {\u27e9}_{3}={\stackrel{~}{O}}_{max}|\psi {\u27e9}_{2}=(-1{)}^{g(u)}{\displaystyle \frac{1}{\sqrt{{2}^{N}}}\sum _{i=0}^{{2}^{N}-1}|u{\u27e9}_{i}\otimes |{f}_{fit}(u){\u27e9}_{i}}$$such that
(13) $$g(u)=\{\begin{array}{cc}1& \phantom{\rule{1em}{0ex}}if|{f}_{fit}(u){\u27e9}_{i}\text{}\ge \text{}max\\ 0& \phantom{\rule{1em}{0ex}}otherwise,\end{array}$$
then the corresponding |f_{fit}(u)⟩_{i} basis states are marked.
In our algorithm, the oracle is implemented as described in Udrescu, Prodan & Vlăduţiu (2006), using a quantum two’s complement subtractor and a quantum two’s complement adder, and it is then applied on the entire fitness register (except for the validity qubit). By using the two’s complement addition, the correlation between an individual and its corresponding fitness value is not affected because—as presented in Udrescu, Prodan & Vlăduţiu (2006)—the addition is a pseudo-classical permutation function. Figure 4 shows the Oracle circuit implementation, while Algorithm 3 provides the pseudocode for the Oracle description. All basis states for which the fitness value is greater than the number of edges are marked by multiplying their amplitudes with −1. For the subtractor and adder implementation, we use a Quantum Ripple Carry Adder circuit, as presented in Cuccaro et al. (2004). The gate-level implementation of the adder subcircuit is presented in Fig. 5. We analyzed the possibility of using a Quantum Carry Look-Ahead Adder (Cheng & Tseng, 2002), but it presented the disadvantage of a higher number of qubits. Considering M the size of the fitness register and $m=\mathcal{O}\left(\sqrt{{2}^{M}}\right)$ the number of Grover Iteration, by using the Ripple Carry Adder circuit we utilize one carry-in qubit and 2 qubits for carry-out in each iteration (1 carry-out qubit for each adder), thus a total of $2\sqrt{{2}^{M}}+1$ qubits. For the Quantum Carry Look-Ahead Adder, we need a total of 2(M + 1) carry qubits in each iteration (M + 1 carry qubits for each adder), hence not an acceptable solution to be used in our implementation.
1: Create |pqreg⟩, a quantum register that stores a positive value representing the maximum number of edges |
2: Create |fitness_{u}⟩–the fitness quantum register |
3: Create |ws⟩–the oracle workspace quantum register |
4: Create |cin⟩–the carry-in quantum register |
5: Create |cout⟩–the carry-out quantum register |
6: Create the Oracle quantum sub-circuit |
7: Append Adder(|pqreg⟩,|fitness_{u}⟩,|cin⟩,|cout⟩ sub-circuit ▹ Subtract the number of edges from the fitness value |
8: |ws⟩ = H|ws⟩ |
9: |ws⟩ = CNOT(|fitness_{u}⟩,|ws⟩) |
10: |ws⟩ = H|ws⟩ |
11: Append Adder(|pqreg⟩,|fitness_{u}⟩,|cin⟩,|cout⟩ sub-circuit ▹ Add the number of edges to the fitness value |
Next, we use the Grover diffuser, G, to augment the amplitude of the marked states, |ψ⟩_{i} = |f_{fit}(u)⟩_{i} with f_{fit}(u) ≥ 0, in the fitness register:
(14) $$|\psi {\u27e9}_{4}=G|\psi {\u27e9}_{3}.$$
We update the value of max with the state found. Figure 6 shows the Grover diffuser sub-circuit and its implementation; f is the fitness quantum register, v is the valid qubit and ws is the oracle workspace. In our implementation, we used the Hadamard Gate, the Pauli-X gates and the n-qubit Toffoli gate.
The last step in the algorithm is to measure |ψ⟩_{m} _{−} _{1} register to obtain the corresponding individual. The measured value represents the solution found to solve the problem.
Complexity analysis
RQGA, as presented in Udrescu, Prodan & Vlăduţiu (2006), is an adaptation of the quantum maximum finding algorithm introduced in Ahuja & Kapoor (1999). According to Ahuja & Kapoor (1999), the algorithm requires $\mathcal{O}\left(\sqrt{N}\right)$ queries made to the oracle. Since in RQGA the initial state processed using Grover’s Algorithm is an equally weighted superposition, it means that no extra Grover Iterations are required in order to augment the amplitudes (Udrescu, Prodan & Vlăduţiu, 2006)—the algorithm maintains the number of steps of the quantum maximum finding algorithm. Thus, RQGA’s complexity is $\mathcal{O}\left(\sqrt{N}\right)$, where N is the search space size.
For solving the graph coloring problem using RQGA, we define a M-qubit fitness quantum register. As shown, the size of the search space is 2^{M}. Therefore, according to Grover (1996) and Nielsen & Chuang (2002), the number of operations in which the oracle is consulted is $\mathcal{O}\left(\sqrt{{2}^{M}}\right)$. Considering that there are N possible solutions to the problem, according to Nielsen & Chuang (2002), the algorithm only needs to consult the oracle $\mathcal{O}\left(\sqrt{{\textstyle \frac{{2}^{M}}{N}}}\right)$; thus, the complexity of the algorithm in solving the graph coloring problem is $\mathcal{O}\left(\sqrt{{\textstyle \frac{{2}^{M}}{N}}}\right)$ if there are N possible solutions.
Measurements and Results
For performing the measurements, we implemented the algorithm as presented in Fig. 7, using Qiskit—for the simulation we use the IBMQ back end (Anis et al., 2021). We performed the simulations using the ibm-q provider with the ibmq_qasm_simulator back end (version 0.1.547 with a configuration of 16 shots). The simulator is general and context-aware—a general-purpose simulator for simulating quantum circuits, both ideally and subject to noise modeling—limited to 32-qubit circuits. The following basic gates are available on the mentioned simulator: U1, U2, U3, U, P, R, RX, RY, RZ, ID, X, Y, Z, H, S, SDG, SX, T, TDG, SWAP, CX, CY, CZ, CSX, CP, CU1, CU2, CU3, RXX, RYY, RZZ, RZX, CCX, CSWAP, MCX, MCY, MCZ, MCSX, MCP, MCU1, MCU2, MCU3, MCRX, MCRY, MCRZ, MCR, MCSWAP, UNITARY, DIAGONAL, MULTIPLEXER, INITIALIZE, KRAUS, ROERROR, DELAY. In the implementation of RQGA we used Hadarmard, Pauli-X, Toffoli, and n-qubits Toffoli gates which correspond to the H, X, CCX and MCX gates available in the simulator.
To study the complexity of the algorithm, we run it on 12 data sets. We utilize 10 data sets for testing the node coloring; half of them are represented by 4-node randomly generated graphs while the rest are 5-node randomly generated graphs. The remaining two data sets are used for testing the edge coloring capabilities of the algorithm. Each graph is colored using a maximum of 3 colors, K = 3. For the fitness representation, we use 4 qubits, thus, the number of Grover Iterations needed for finding the results is $\mathcal{O}\left(\sqrt{{2}^{4}}\right)\approx 4$. To analyze the complexity of the algorithm, we variate the number of Grover Iterations for each data set and perform each measurement 10 times. We are interested in observing the convergence of the algorithm, and for this purpose we analyze the solutions that represent the local optimum (i.e., valid solutions) and those that represent the global optimum (i.e., best solutions) for the coloring problem.
We start by presenting the results obtained after running the node coloring algorithm on 4-node graphs and continue with the results obtained after running our algorithm on 5-node graphs. The presented outcomes are ordered by the number of edges. Last, we show the results obtained after running the edge coloring algorithm.
Experimental results
In Supplemental Information, Figs. S1, S2, and S3 we notice that the algorithm finds only the best solutions, starting from the first Grover Iteration. As expected, we achieve the best outcome in terms of the number of best solutions after 4 Grover iterations. In these cases, our algorithm also found the chromatic number.
For the graphs in Fig. S4 from Supplemental Information, and Fig. 8—graphs with a higher number of edges–the algorithm found valid and best solutions, with the best outcome (in terms of number of solutions) obtained after 3 and 4 Grover iterations.
For the graphs presented in Supplemental Information, Figs. S5 and S6, the algorithm determines both the best coloring and chromatic number, with best outcome (in terms of number of solutions) obtained after 3 and 4 Grover iterations. In the case of graphs presented in Figs. S7 and S8 from Supplemental Information, and Fig. 9—graphs with a higher number of edges—the algorithm determined the best coloring after 2 Grover iterations.
In Figs. 10 and 11, we present the relationship between the number of Grover iterations and the minimum, maximum, and average number of valid and best solutions found after testing the node coloring algorithm on graphs with 4 and 5 nodes.
In Figs. 12 and 13, we present the results after using the algorithm to solve the edge coloring problem. For the graph presented in Fig. 12, the algorithm determined the best results after 1 Grover iteration. In Fig. 3, the algorithm finds the best solution after 2 Grover iterations. We obtain the best outcome from the point of view of valid and best solutions, after 3 oracle queries.
Discussions
We observed experimentally that, for the 4-node graphs, some of the best solutions found used only 2 colors instead of the configured 3 colors. Thus, without any modifications in the fitness function for simple graphs, the algorithm is capable of determining both the coloring and the chromatic number. For more complex graphs, the algorithm can determine the chromatic number by modifying the fitness function: for the valid individuals that color the graph using a number of colors smaller than the configured one, the fitness value will be amplified by a factor. Thus, solutions with a better (i.e., smaller) chromatic number will have a bigger fitness value, which generates a higher probability to be chosen as the best solutions.
In subsection Complexity analysis, we show that the expected complexity is $\mathcal{O}\left(\sqrt{{\textstyle \frac{{2}^{M}}{N}}}\right)$ oracle queries, where M is the fitness quantum register size and N is the number of possible solutions. Experimentally, the complexity assessment is confirmed; in most of the experiments, the algorithm found best solutions to the problem after the first queries, confirming that only $\mathcal{O}\left(\sqrt{{\textstyle \frac{{2}^{M}}{N}}}\right)$ iterations are required.
Compared to other solutions, our approach using RQGA can be used to solve both the node and edge coloring forms of the graph coloring problem. Moreover, with minimal adjustments to the fitness function, our solution can determine the chromatic number. In Table 2, we provide a comparison between our approach and other algorithms. Since the literature presents different types of heuristic algorithms, a comparison from the point of view of algorithm convergence is not relevant. Nevertheless, a possible comparison approach is to use the perspective of the number of solutions and optimality. Such comparisons with the heuristic algorithms presented would involve running RQGA on the same data sets. Unfortunately, since our algorithm is simulated on a classical computer, we have limitations on the number of qubits we can simulate, owing to the simulation time and circuit complexity (i.e., number of Controlled-Not gates). Since our approach is purely quantum, we need to compare it with purely quantum algorithms. Thus, we first consider a comparison that focuses on the forms of graph coloring problem that are solved, the ability to determine the chromatic number, and metrics used in order to determine the algorithm’s performance. Additionally, we provide a comparison that focuses on the solution count between RQGA and the algorithms presented in Silva et al. (2020); we also compare our approach with the algorithms presented in Silva et al. (2020), Tabi et al. (2020), and Aragón Artacho & Campoy (2018) from the perspective of the number of iterations required to find a solution that colors a 5-node graph.
Algorithm | Graph coloring form | Chromatic number | Observed metrics |
---|---|---|---|
RQGA | Node and edge coloring | Minimal adjustments | $\mathcal{O}\left(\sqrt{\frac{{2}^{M}}{N}}\right)$ complexity |
Quantum optimization for the graph coloring problem with space-efficient embedding Tabi et al. (2020) | Node coloring | Not mentioned | Convergence and CPU time |
Graph coloring with quantum annealing Kwok & Pudenz (2020) | Node coloring | Not mentioned | Success probability, time to solution,wallclock time |
Graph coloring with quantum heuristics Fabrikant & Hogg (2002) | Node coloring | Not mentioned | Asymptotic analysis |
Quantum annealing of the graph coloring problem Titiloye & Crispin (2011) | Node coloring | Not mentioned | Number of solutions found |
Constrained quantum annealing of graph coloring Kudo (2018) | Node coloring | Not mentioned | Residual energy and success probability |
Mapping graph coloring to quantum annealing Silva et al. (2020) | Node coloring | Not mentioned | Number of optimal solutions |
We performed 3 simulations with 8,192 repetitions to count the number of solutions found by our approach that color the graph from Fig. 9, as presented in Fig. 14. In Fig. 15 we present the comparison between our approach and the algorithms presented in Silva et al. (2020) that focus on the ratio between the number of solutions (optimal, possible, and none) and the number of repetitions. RQGA performed 4 iterations 8,192 times while the algorithms presented in Silva et al. (2020) performed 5,000 iterations 10,000 times. For all algorithms, we divided the number of solutions found by the number of iterations multiplied with the number of repetitions. Therefore, as presented in Fig. 15, RQGA performed better than the other algorithms because our approach has a success probability of 0.76% for finding the optimal solutions, compared to 0.0027% representing the best of the algorithm C_Q_sim.
In Fig. 16 we present a comparison between RQGA and the algorithms presented in Silva et al. (2020), Tabi et al. (2020), and Aragón Artacho & Campoy (2018), from the perspective of the number of iterations required to find the solutions that color a 5-node graph. As presented in subsection Complexity analysis and confirmed experimentally, RQGA requires 4 iterations for finding the solutions while the mentioned heuristic algorithms require 44, 5,000, and 100 iterations, respectively.
Limitations
Our study is limited by the fact that we propose a purely quantum method that needs to be simulated, given that we do not have access to a quantum computer. As mentioned in Udrescu, Prodan & Vlăduţiu (2012), the simulation of a quantum circuit on classical computers requires run-times exponential with the circuit size. Spector (2004), shows that the space and time requirements for simulation are of the order 2^{n} for a system with n-qubits. Moreover, Viamontes, Markov & Hayes (2009) argues that the linear algebraic simulation of quantum computers would have time and memory complexity $\mathcal{O}({2}^{2n})$ for an n-qubit system. Indeed, due to the fourth postulate of quantum mechanics, the simulation of quantum behavior on classical computers has exponential complexity.
Consequently, since we simulated the algorithm, we have limitations on the number of qubits, simulation time, and circuit complexity. Such limitations have an impact on the size of the datasets on which we apply the algorithm. Knowing the number of nodes in a graph, the number of colors available, and the number of Grover iterations, we calculate with function f the number of qubits required by the algorithm
(15) $$f(|V|,n,M,m)=|V|\times n+2\times (M+m)+3.$$
In Eq. (15), variable |V| represents the number of nodes in graph, n represents the number of qubits needed for color representation (as presented in subsection Implementation); M represents the number of qubits required by fitness representation in two’s complement; $m=\mathcal{O}\left(\sqrt{{2}^{M}}\right)$ represents the number of Grover Iterations; 3 qubits are needed for carry-in, oracle workspace, valid flag, while adders need 2 qubits for carry-out in each Grover iteration.
As such, for the graph presented in the Supplemental Information, Graph coloring example—with 4 nodes—2 qubits are used for color representation, and 4 qubits are used for fitness value representation. Considering that we need 4 Grover iterations, the circuit requires a total of f(4,2,4,4) = 4 × 2 + 2× 8 + 3 = 27 qubits. Therefore, according to Spector (2004), the space and time requirement for the simulation of the circuit is 2^{27}.
An increased number of qubits have an exponential impact on the circuit complexity and on the simulation time of the algorithm. Thus, considering the above-mentioned limitations, we could not simulate the algorithm on more complex graphs (i.e., with a high number of nodes and edges).
Conclusions
This paper describes the instantiation of the Reduced Quantum Genetic Algorithm for solving the graph coloring problem with the Qiskit toolchain. By this means, we introduce a pure quantum heuristic method that solves the problem in $\mathcal{O}\left(\sqrt{{\textstyle \frac{{2}^{M}}{N}}}\right)$ Grover oracle queries. We also provide solutions for the graph node coloring problem, the edge coloring problem, and finding the chromatic number of a graph with several fitness adjustments.
Because of the big number of qubits required by the algorithm implementation, our experiments based on computer simulations are limited. We observed the results to determine the convergence and complexity of the algorithm by analyzing the solutions for the problem. Experimentally, we prove the complexity assessment and we demonstrate that, at least for graphs with a small number of nodes, the algorithm not only finds the best solutions for the problem, but also the chromatic number.
Future research can analyze how the complexity of the algorithm can be reduced by employing meta-heuristics, as well as the impact of meta-heuristics on convergence. Indeed, our focus will be on finding a way to reduce the number of oracle queries, such that the complexity of the algorithm is reduced without affecting convergence.