1 Introduction

Vehicle Routing Problem (VRP) is an important combinatorial optimization problem in which the goal is to find the optimal setting of routes for a fleet of vehicles which should deliver some goods from a given origin (depot) to a given set of destinations (customers) [1]. It is a generalization of the Travelling Salesman Problem (TSP) (introduced first as the Truck Dispatching Problem [1]) in which one vehicle has to visit some number of destinations in the optimal way [2]. Both problems are proven to be NP-hard [3]. There exist the exact algorithms able to find optimal solutions in a reasonable time for relatively small instances, but generally, those problems are computationally difficult and the state-of-the-art approaches applied in practice are based on heuristics (constructive, improvement and composite) and metaheuristics [4, 5].

Recently, we can observe a noticeable progress in the development of quantum computing algorithms and it turned out that they may be particularly successful in solving combinatorial optimization problems, such as TSP and VRP [6]. The first quantum algorithms for TSP and VRP already exist and in the scientific literature we can find algorithms which can be run on gate-based quantum computers [7,8,9,10,11,12,13,14,15,16,17] as well as quantum annealing algorithms which can be run on adiabatic quantum computers [18,19,20,21,22,23,24].

In this paper, we present new methods for solving VRP and its more practical variant, CVRP (Capacitated Vehicle Routing Problem), in which all vehicles have a limited capacity. The algorithms introduced in this paper are based on quantum annealing, because due to the number of available qubits, those algorithms have currently a greater chance to give any practical improvement over classical algorithms.

We developed and present four algorithms: Full QUBO Solver (FQS), Average Partition Solver (AVS), DBSCAN Solver (DBSS) and Solution Partitioning Solver (SPS). The first and second one are designed only for solving VRP, DBSCAN solver can also solve CVRP if capacities of all vehicles are equal, SPS is able to solve CVRP with arbitrary capacities. It is also important to add that the last two methods are hybrid algorithms and they contain important components which should be run on classical processors.

In order to evaluate different algorithms for solving VRP using quantum annealing, we carried out series of experiments using D-Wave’s Leap framework [25] which contains implementations of built-in solvers and allows to implement new solvers. We used QBSolv [26] run on quantum processing unit (QPU) and simulating quantum annealing on classical processors (CPU), as well as hybrid solver [27] run on both, QPU and CPU.

Beside quantum algorithms, we also wanted to test and compare several well-known classical algorithms which gave good results in previous studies. Based on a comprehensive literature review [5] and further analysis, we selected 4 metaheuristics: based on simulated annealing [28], bee algorithm [29], evolutionary annealing [30] and recursive DBSCAN with simulated annealing [31], respectively.

In order to reliably compare different algorithms, we conducted experiments on well-established benchmark datasets [32, 33], as well as on datasets created by us, with realistic road networks (taken from the OpenStreetMap service) and artificially generated orders.

The rest of the paper is organized as follows: in Sect. 2, we describe in details all the quantum annealing solvers which we used in our experiments. Sections 3 and 4 present the design and results of our experiments, respectively. Section 5 outlines possible future research directions and concludes the paper.

2 CVRP Solvers Based on Quantum Annealing

In this section, we describe QUBO formulations and solvers which we developed for different variants of VRP: general VRP, CVRP with equal capacities and CVRP with arbitrary capacities. Before that, we introduce our notation and assumptions.

2.1 Notation and Assumptions

We assume that in each instance of VRP (or CVRP) we have a road network represented as a directed connected graph with vertices and edges. We also assume that the depots and destinations to which the orders of customers should be delivered are always located in vertices of the road network (in the case of benchmark instances and artificial networks, it may be even assumed that the road network is defined by locations of orders, while in the case of realistic road networks, real locations of orders are usually close enough to vertices determining the road network graph).

Let M be the number of available vehicles and N the number of orders. Let’s denote the vehicles as \(V=\{v_1,v_2,\ldots ,v_M\}\) and the orders as \(O=\{o_1,o_2,\ldots ,o_N\}\). We assume that there is always a depot located in one of the vertices (we also assume that destinations of orders are not located in the depot - such orders can be just served immediately so are not interesting) and all vehicles are initially located in the depot and should finish all routes back in the depot. Therefore, we have in total \(N+1\) significant vertices and without any loss of generality, we can assume that our graph has exactly \(N+1\) vertices and \(N*(N+1)\) directed edges (we can just consider edges built based on the shortest paths between every pair of vertices in the original graph), destination of the order \(o_i\) is located in the vertex i and the depot is located in the vertex \(N+1\). We can also denote the cost of the direct travel from the vertex i (destination of the order \(o_i\)) to the vertex j (destination of the order \(o_j\)) as \(C_{i, j}\). We can also define \(C_{N+1,i}\) and \(C_{i,N+1}\) for \(i\in \{1,2,\ldots ,N\}\) as the costs of direct travels from the depot to the destinations of orders and from the destinations of orders to the depot, respectively.

Let’s assume that \(x_{i, j, k}=1\) if in a given setting the vehicle number i visits the vertex number j as k-th location on its route (for \(j\in \{1,2,\ldots ,N+1\}\) and \(k\in \{0,1,2,\ldots ,N+1\}\)), otherwise \(x_{i, j, k}=0\). We always have \(x_{i,N+1,0}=1\) and \(x_{i,j,0}=0\) for \(j<N+1\) (the depot is always the first location), and if \(x_{i,N+1,K}=1\) for some K then for \(k>K\) \(x_{i,j,k}=1\) (each vehicle stays in the depot after reaching it).

2.2 Full QUBO Solver

First, we defined a basic QUBO formulation used for solving VRP instances. The formulation is based on a similar formulation for TSP in [20].

Let’s define the binary function

$$A(y_1, y_2, ..., y_n) = \sum _{i=1}^{n} \sum _{j=i+1}^{n} 2 y_i y_j - \sum _{i=1}^{n} y_i,$$

where \(y_i\in \{0,1\}\) for \(i\in \{1,\ldots ,n\}\). It is easy to prove that the minimum value of \(A(y_1, y_2, ..., y_n)\) is equal to \(-1\) and this value can be achieved only if exactly one of \(y_1, y_2, ..., y_n\) is equal to 1.

By definition of VRP, the problem of minimizing the total cost can be defined as minimizing the function:

$$\begin{aligned} C = \sum _{m=1}^{M} \sum _{n=1}^{N} x_{m, n, 1}C_{N+1, n} + \sum _{m=1}^{M} \sum _{n=1}^{N} x_{m, n, N}C_{n, N+1} \end{aligned}$$
$$\begin{aligned} + \, \sum _{m=1}^{M} \sum _{n=1}^{N-1} \sum _{i=1}^{N+1} \sum _{j=1}^{N+1} x_{m, i, n} x_{m, j, n + 1} C_{i, j} \qquad \qquad \end{aligned}$$

The first component of the sum C is a sum of all costs of travels from the depot - the first section of each cars’ route. The second is a cost of the last section of a route (to depot) in a special case when a single car serves all N orders (only in such a case the component can be greater than 0). The last part is the cost of all other sections of routes.

To assure that each delivery is served by exactly one vehicle and exactly once, and that each vehicle is in exactly one place at a given time, the following term (in which all A components are equal to \(-1\) only for such desired cases) should be included in our QUBO formulation:

$$\begin{aligned} Q = \sum _{k = 1}^{N} A(x_{1, k, 1}, x_{2, k, 1}, \ldots , x_{1, k, 2}, \ldots , x_{M, k, N}) \end{aligned}$$
$$\begin{aligned} + \, \sum _{m=1}^{M} \sum _{n=1}^{N} A(x_{m, 1, n}, x_{m, 2, n}, \ldots , x_{m, N+1, n}) \end{aligned}$$

By definition of VRP, QUBO representation of this optimization problem is

$$\begin{aligned} QUBO_{VRP} = A_1\cdot C + A_2\cdot Q, \end{aligned}$$

for some constants \(A_1\) and \(A_2\), which should be set to ensure that the solution found by quantum annealer minimizes Q (which should be \(-N-NM\)) to ensure satisfiability of the aforementioned constraints (after running initial tests we set \(A_1=1\), \(A_2=10^7\)).

2.3 Average Partition Solver (APS)

APS is a variation of Full QUBO Solver for which we decrease the number of variables for each vehicle by assuming that every vehicle serves approximately the same number of orders. This means, every vehicle can serve up to \(A + L\) deliveries, where A is the total number of orders divided by the number of vehicles and L is a parameter (called “limit radius”), which controls the number of orders. The QUBO formulation is the same as in case of Full QUBO Solver but the number of variables \(x_{i,j,k}\) is lower (\(M(A + L)N\)), which simplifies computations.

2.4 DBSCAN Solver (DBSS)

DBSS allows us to use quantum approach combined with a classical algorithm. This particular algorithm is inspired by recursive DBSCAN [31]. DBSS uses recursive DBSCAN as a clustering algorithm with limited size of clusters. Then, TSP is solved for each cluster separately by FQS (just by assuming in the QUBO formulation that the number of vehicles equals 1). If the number of clusters is equal to the number of vehicles, the answer is known immediately. Otherwise, the solver runs recursively considering clusters as deliveries, so that each cluster contains orders which in the final result are served one after another without leaving the cluster. What is more, we concluded that by limit the total sum of weights of deliveries in clusters, this algorithm can solve CVRP if all capacities of vehicles are equal.

2.5 Solution Partitioning Solver (SPS)

While adding capacity constraints is not simple, we were looking for the solution that can use results generated by DBSS. Therefore, we developed SPS. It is a simple algorithm which divides TSP solution found by another algorithm (e.g., DBSS) into consecutive intervals, which are the solution for CVRP. The idea is as follows:

Let \(d_1,d_2,...,d_N\) be the TSP solution for N orders, let \(P_v\) be a capacity of the vehicle v, let \(w_{i,j}\) be the sum of weights of orders \(d_i, d_{i+1}, d_{i+2}, \ldots , d_j\) (in the order corresponding to TSP solution) and let \(cost_{i,j}\) be the total cost of serving only orders \(d_i, d_{i+1}, \ldots , d_j\). Also, let \(dp_{i,S}\) be the cost of the best solution for orders \(d_1, d_2, d_3, ..., d_i\) and for the set of vehicles S. Now, the dynamic programming formula for solving CVRP is given by:

$$\begin{aligned} dp_{i,S} = \min _{v \in S, 0 \le j \le i, w_{j+1,i} \le P_v} \{ dp_{j,S \setminus \{ v \}} + cost_{j+1,i}\}, \end{aligned}$$

where \(cost_{i,j} = 0\) and \(w_{i,j}=0\) for \(i > j\). Formula (6) returns a plenty of possible routes, but it also finds the optimal solution. We can speed it up by noticing that if two vehicles have the same capacity, it doesn’t matter which one of them we choose, but pessimistically, capacities can be pairwise distinct. We propose the following heuristic to optimize this solution:

  1. 1.

    Instead of set S of vehicles, consider a sequence \(v_1, v_2,\ldots , v_M\) of vehicles and assume that we attach them to deliveries in such an order.

  2. 2.

    Now, our dynamic programming formula is given by:

    $$\begin{aligned} dp_{i, \{v_{1},v_{2}, \ldots ,v_{k}\}} = \min _{0 \le j \le i, w_{j+1,i} \le P_{v_k}} \{ dp_{j,\{v_1,\ldots ,v_{k-1}\}} + cost_{j+1,i} \} \end{aligned}$$
  3. 3.

    To count this dynamic effectively, we can observe that:

    $$\begin{aligned} \forall _{j < i} cost_{j, i} = C_{N+1, j} + C_{i, N+1} + \sum _{k=j}^{i-1}C_{k, k+1} \end{aligned}$$
    $$\begin{aligned} \forall _{j < i}cost_{j, i} = cost_{j, i - 1} + C_{i-1, i} + C_{i,N+1} - C_{i-1, N+1} \end{aligned}$$
    $$\begin{aligned} \forall _{j<i}cost_{j, i} - cost_{j, i - 1} = C_{i-1, i} + C_{i,N+1} - C_{i-1, N+1} \end{aligned}$$
    $$\begin{aligned} \forall _{j<i, 1\le k \le M}(dp_{j-1, \{v_1,v_2, \ldots ,v_k\}} + cost_{j, i}) - ( dp_{j-1, \{v_1,v_2, \ldots ,v_k\}} + cost_{j, i - 1}) = C_{i-1, i} + C_{i,N+1} - C_{i-1, N+1} \end{aligned}$$

    So if we have counted dp for fixed k, then for counting dp for \(k+1\) we can store all dp values for k and increase them, one by one (starting from \(i=j+1\)), by a right side of Eq. 10. Using monotonic queue, we can get minimum in O(1) time.

We can now select some random permutations of vehicles and perform dynamic programming for each of them. The number of permutations can be regulated by additional parameter. With optimization of dynamic programming, the complexity of this algorithm is O(NMR), where R is the number of permutations.

The greatest limitation of SPS is that it considers only one TSP solution. Nonetheless, we observed that DBSS for more than one vehicle works in a similar way.

3 Design of Experiments

The goal of our experiments was to test and compare different formulations of QUBO (solving different variants of VRP) on different datasets and with different solvers and settings (number of qubits and quota of time on quantum processor). We ran them using D-Wave’s Leap platform [25] and its 2 solvers: qbsolv [26] and hybrid solver [27]. To run comprehensive and comparable experiments, we prepared several datasets:

  • Christofides1979 - a standard benchmark dataset for CVRP, well-known and frequently investigated by the scientific community [32, 33],

  • A dataset built by us based on a realistic road network of Belgium, acquired from the OpenStreetMap service.

Christofides1979 consists of 14 tests, where each test instance is described by three files. The first one provides the number of vehicles and their capacity (the same for all vehicles). The second file describes the orders, i.e. their coordinates in \(2-\)dimensional plane and the demand. The last file reports the time matrix (times of travel between various vertices in a graph). For a purpose of running our experiments and compare the results, we selected only 9 out of 14 tests because in case of other tests some hybrid or classical algorithms were not able to find any good solutions. All the important parameters describing Christofides1979 instances are given in Table 1.

Table 1. Parameters of instances of Christofides1979 used in our experiments.
Table 2. Parameters and descriptions of tests

In the case of the second dataset, we generated in total 51 tests. Each test was characterized by the number of orders. Table 2 presents a description of this dataset. Basically, it consists of 4 groups of test cases: small test (small number of orders), medium tests (medium number of orders), big tests (large number of order), mixed tests (various number of orders with some additional conditions).

In every experiment, our programs computed the minimal cost of serving all orders. D-Wave’s quantum annealing machine is naturally nondeterministic, so are the returned results, so for every algorithm and on every test case we ran 5 experiments. The code of programs used in our experiments is publicly available at [34].

4 Results of Experiments

In this section, we present results of experiments conducted using QBSolv and hybrid solver built-in D-Wave’s Leap framework and using algorithms described in Sect. 3.

4.1 Full QUBO Solver (FQS)

First, we investigated Full QUBO Solver (FQS) on test cases small-0 - small-9. On every test except small-0, we ran experiments for 3 different numbers of vehicles (1, 2, 3) on quantum processor (FQS QPU [26]), its classical simulator (FQS CPU) and using a hybrid solver (FQS Hybrid [27]). On small-0 there were only 2 orders so we tested only 1, 2 vehicles.

As we can see in Table 3, QBSolv (FQS CPU and FQS QPU) exacerbates final results in test cases with more vehicles. For more vehicles, it can potentially generate the same solution as for less vehicles, because some vehicles can be just ignored. Solutions generated with hybrid solver (FQS Hybrid) confirm that. However, the size of QUBO makes the solutions with more vehicles unavailable for QBSolv. In hybrid solver, we have such a problem in only one case (small-9). However, in only 1 test case (small-3) QBSolv was able to improve the solution returned for smaller number of vehicles. In addition, in most cases QBSolv was not able to find a solution on QPU, the size of the instance and the number of the required variables and qubits was just too large. Also the required time of computations on QPU was worse than in case of CPU or hybrid approach. Therefore, we concluded that it doesn’t make sense to run more experiments on QPU for larger test cases (with more cars and more orders) and we conducted next tests only using QBSolv on CPU and using a hybrid solver.

For larger VRP instances (medium-0 - medium-9), we observed that the transition from one vehicle to two vehicles is difficult. QBSolv usually returns much worse results (there is only 1 exception, test case medium-8). For the hybrid solver, in only one case the result for two vehicles is better (medium-6) but the results are usually still better than in case of QBSolv. We also noticed that the order of deliveries in tests with one vehicle was not optimal for majority of test cases. Only the least instances - with up to 15 orders - seem to be solved optimally. An interesting thing is that differences between results for two vehicles and one vehicle are very discrepant and it is not caused by the number of orders. By analyzing full results, we concluded that for 2 vehicles the solvers divided deliveries evenhandedly and for some tests it is a good way to build the optimal solution. We came up with an idea that since solvers found only these solutions, we can ask them to optimize only that kind of solutions, so we implemented Average Partition Solver, which demands less qubits.

Table 3. Results on small and medium datasets

4.2 Average Partition Solver (APS)

We extended Full QUBO Solver with an option of changing the maximum difference between the number of deliveries attached to the vehicles, i.e., a deflection from the average number of deliveries per one vehicle. We found out experimentally that it should be \(\frac{1}{10}\) of the number of deliveries, which gives maximum difference in our test cases equal to 5. Having 1 vehicle, APS works exactly the same as Full QUBO Solver, so we ran experiments only for more vehicles (but we also included the results for 1 vehicle in Table 3, just for comparison).

In most test cases, the results found using APS were better than results found by FQS. We can also notice that differences between results for 3 vehicles and results for 2 vehicles generated by APS are lower than the differences between results for 2 vehicles and 1 vehicle generated by FQS. However, in case of 3 vehicles, QBSolv on CPU still can’t find better solutions with only 2 vehicles. The hybrid solver can find better solutions in cases with 3 vehicles than in cases with only 2 vehicles in 4 (out of 10) test cases.

4.3 DBSCAN Solver (DBSS)

We can see in Table 3 that DBSS usually gives worse results than the APS, but we expected that it may change in case of tests with more orders thanks to utilizing the power of recursive DBSCAN.

Indeed, on big test cases with a larger number of orders, DBSS gives much better results than APS (Table 4). Additionally, DBSS can be run on larger instances and don’t need assumption that every vehicle serves approximately the same number of deliveries (as it is in case of APS).

Table 4. Comparison of results for Average Partition Solver and DBSCAN Solver on big test cases.
Table 5. Comparison of DBSCAN Solver and Solution Partitioning Solver (SPS) run on CPU on big test cases with various capacities.
Table 6. Comparison of results achieved by Solution Partitioning Solver (SPS) and classical algorithms (SA - simulated annealing, BEE - Bee algorithm, EA - evolutionary annealing, DBSA - DBSCAN with simulated annealing) on a benchmark dataset Christofides79.

4.4 Solution Partitioning Solver (SPS)

At the beginning, we tested SPS on test cases where all capacities are equal, in order to compare results with DBSS which can solve this problem. The results are presented in Table 5. In some cases, our solvers were not able to find the proper solutions (we mark such cases as “Not valid”) but in general, SPS outperformed DBSS.

Based on those experiments, we decided to test further only SPS and compare it with 4 classical algorithms - simulated annealing (SA), bee algorithm (BEE), evolutionary annealing (EA) and recursive DBSCAN with simulated annealing (DBSA). We ran next experiments with even more orders on mixed test cases generated by us (Table 2) and on benchmark datasets Christofides1979 (Table 1). The results are presented in Table 6 and Table 7.

Table 7. Results of Solution Partitioning Solver compared with results for classical algorithms run on artificially generated test cases.

5 Conclusion and Future Research Directions

We introduced new hybrid algorithms for solving VRP and CVRP and ran tests using D-Wave’s Leap framework on well-established benchmark test cases and on our own test scenarios built based on realistic road networks. We also compared our new quantum and hybrid methods with classical algorithms - well-known metaheuristics for solving VRP and CVRP. The results indicate that our hybrid methods give promising results and are able to find solutions of a similar quality to the tested classical algorithms.

Our primary future research direction is extending QUBO formulations to solve even more realistic variant of VRP - the Vehicle Routing Problem with Time Windows (VRPTW). Also, we are planning to compare our hybrid algorithms with even more classical algorithms for solving VRP and its variants.