Combinatorial Optimization
Combinatorial optimization problems ask for the best solution from a finite set of candidates:
where is a discrete solution space. The counts grow fast enough that intuition fails early: a 10-city tour problem has distinct routes, 15 cities has about 43 billion, and 20 cities passes . Exhaustive search is therefore a luxury reserved for instances with fewer than about 25 binary variables.
Most of these problems are NP-hard, which means two things that get conflated. No known algorithm solves every instance to optimality in polynomial time, yet real instances are often easy â solvers close 10,000-vertex scheduling cases daily by combining linear relaxations, cutting planes and clever pruning. The interesting question is therefore never whether quantum can beat brute force, which it can, but whether it can beat a well-tuned commercial solver running on one core.
Quantum approaches target two distinct niches: providing a better approximation ratio than a classical heuristic within a fixed time budget, or offering a different scaling curve whose constant factors only pay off beyond some instance size that hardware has not reached yet.
MaxCut
MaxCut partitions the vertices of a graph to maximise the weight of edges crossing between the two sides:
where . For an unweighted graph with edges the optimum is at most , and the Goemans-Williamson randomised rounding of a semidefinite program guarantees of it in polynomial time â a bound that has stood since 1995.
Work a four-vertex cycle plus one chord: vertices â in a square with an extra edge â. The square alone can be cut 4 ways with 4 edges crossed; adding the chord forces a choice, and the optimum is a cut of size 3 crossing edges , and . Five edges, 16 possible assignments, optimum 3 â small enough to check by hand, which is exactly why MaxCut instances of this size are the standard smoke test for a QAOA implementation.
QAOA approaches the same objective from the other direction: the cost Hamiltonian encodes as a diagonal operator, the mixer spreads amplitude over feasible assignments, and the classical optimizer searches the angle pairs. Measured performance must be quoted against 0.878, not against the trivial 0.5 of a random partition.
Turning Constraints into Penalty Terms
Any problem with constraints needs a penalty term before a quantum annealer can see it. The recipe has three steps and one tuning parameter that decides whether the encoding works at all.
- Write each constraint as for binary .
- Square it and add to the objective.
- Choose larger than the largest possible objective improvement, so violating a constraint is never worth it.
For MaxCut the variables are unconstrained, so no penalty is needed. For TSP the constraint "every city is visited exactly once" becomes a row-sum penalty and a column-sum penalty; for portfolio selection the budget constraint becomes one quadratic term. If is too small the solver returns an infeasible solution that scores better than any legal one, and if it is far too large the matrix condition number degrades and the annealer's precision budget gets consumed by the penalty rather than the objective.
Traveling Salesman Problem (TSP)
TSP asks for the shortest tour visiting every city exactly once and returning to the start:
The standard binary encoding uses variables meaning city is visited at position . For 10 cities that is 100 qubits â a useful reminder that qubit count, not algorithmic cleverness, is usually the binding constraint. Two constraints dominate: each position holds exactly one city, and each city appears exactly once.
The result is a QUBO (Quadratic Unconstrained Binary Optimization) problem:
where combines the distance objective with the two penalty blocks. The encoding is quadratic because the distance term is a product of two binaries, and both constraints square into products as well.
Portfolio Optimization
Portfolio optimization maximises expected return for a given level of risk:
subject to and . Classically this is a convex quadratic program solved in time â 500 assets takes milliseconds, so quantum advantage here cannot come from solving the same convex problem faster.
The quantum angle discretises the weight vector. Round each weight to one of five levels in and 10 assets give million feasible portfolios; the encoding needs binary variables to express the level of each asset. The bet is that the discretised, non-convex landscape is where an annealer finds good solutions faster than a branch-and-bound solver proving optimality. Reported results on this formulation are mixed: small instances favour quantum annealing on time-to-solution, and most published speedups evaporate once the classical solver is allowed warm starts.
QUBO Formulation
Many combinatorial problems collapse into the single canonical form:
where and is upper triangular â the diagonal of is indistinguishable from for binary variables, so conventionally the linear terms are folded into the diagonal.
That single form is why QUBO matters: it is the input language of D-Wave's annealers, the target of QAOA's cost Hamiltonian, and the interface of hybrid solvers such as dimod and neal. Porting a problem between them becomes a matrix exercise rather than a reformulation.
| Problem | Objective terms | Constraint terms | Qubits for a typical instance |
|---|---|---|---|
| MaxCut | edge products | none | one per vertex |
| TSP | distance products | row and column sums | |
| Portfolio | return and covariance | budget, cardinality | assets times levels |
| Graph colouring | same-colour products | one colour per vertex | vertices times colours |
Quantum Speedups
The claimed advantages differ sharply by problem class, and the honest version of the table is more useful than the optimistic one:
| Problem | Classical baseline | Quantum candidate | Realistic status |
|---|---|---|---|
| MaxCut | 0.878 guarantee (GW) | QAOA about 0.69 on 3-regular | below classical guarantee at low depth |
| TSP | exact | QAOA or annealing heuristic | heuristic only, instance dependent |
| Portfolio | convex QP | discretised QAOA | non-convex variant, mixed results |
| SAT | exhaustive | Grover | quadratic, but gates cost too |
| Simulation of dynamics | exponential in | native quantum simulation | the one clean asymptotic win |
The pattern is worth internalising: quantum shows genuine asymptotic gains where the quantum device mirrors the structure of the problem â simulating Hamiltonians â and mostly heuristic, constant-factor gains where it is asked to solve a classical combinatorial problem.
Python: MaxCut QUBO
Building the QUBO matrix and checking it against brute force on a five-vertex instance:
import numpy as np
def maxcut_qubo(edges, n):
# MaxCut as a QUBO: minimising x^T Q x equals maximising the cut.
Q = np.zeros((n, n))
for i, j in edges:
Q[i, i] += 1
Q[j, j] += 1
Q[i, j] -= 2
Q[j, i] -= 2
return Q
def cut_value(edges, x):
# Objective evaluated directly on a bitstring.
return sum(x[i] ^ x[j] for i, j in edges)
edges = [(0, 1), (1, 2), (2, 3), (3, 0), (0, 2)]
n = 4
Q = maxcut_qubo(edges, n)
best_energy, best_x, visited = float('inf'), None, 0
for code in range(2 ** n):
x = np.array([(code >> i) & 1 for i in range(n)])
energy = x @ Q @ x
visited += 1
if energy < best_energy:
best_energy, best_x = energy, x
print(f"assignments searched: {visited}")
print(f"best bitstring: {best_x}")
print(f"QUBO energy: {best_energy:.1f}")
print(f"cut value: {cut_value(edges, best_x)}")
print(f"ratio vs optimum: {cut_value(edges, best_x) / 3:.3f}")
Brute force reports an energy of and a cut of 3 on this instance, matching the optimum found by hand earlier. Note that maxcut_qubo symmetrises and ; solvers that assume an upper-triangular matrix will happily read only one triangle and produce a matrix whose quadratic form differs by a factor of two.
Python: TSP QUBO with Penalties
The same pattern with constraints added, showing the tuning step in code rather than in prose:
import numpy as np
def tsp_qubo(dist, lam=10.0):
# Order-preserving TSP encoding: n cities, n positions, n^2 binaries.
n = len(dist)
N = n * n
Q = np.zeros((N, N))
idx = lambda city, pos: city * n + pos
# Objective: distance travelled between consecutive positions.
for pos in range(n):
nxt = (pos + 1) % n
for a in range(n):
for b in range(n):
Q[idx(a, pos), idx(b, nxt)] += dist[a][b]
# Penalty 1: exactly one city per position.
for pos in range(n):
for a in range(n):
Q[idx(a, pos), idx(a, pos)] += lam
for b in range(a + 1, n):
Q[idx(a, pos), idx(b, pos)] += 2 * lam
# Penalty 2: each city used exactly once.
for a in range(n):
for pos in range(n):
Q[idx(a, pos), idx(a, pos)] += lam
for t in range(pos + 1, n):
Q[idx(a, pos), idx(a, t)] += 2 * lam
return Q
dist = [[0, 2, 9, 10],
[1, 0, 6, 4],
[15, 7, 0, 8],
[6, 3, 12, 0]]
lam = 20.0
Q = tsp_qubo(dist, lam=lam)
print(f"encoding size: {Q.shape[0]} variables")
print(f"penalty scale lambda: {lam} (2*lambda = {2*lam} on penalty pairs)")
print(f"largest distance entry: {max(max(r) for r in dist)}")
print(f"largest |Q| entry: {np.abs(Q).max():.1f}")
With four cities the encoding needs 16 variables, and the penalty contributes per constraint-violating pair against a largest single-leg distance of 15, so no constraint violation can beat a legal tour. Raising further is not free: the penalty entries grow while the distances stay between 1 and 15, the dynamic range the annealer must resolve widens, and on real hardware that ratio is the difference between finding feasible tours and returning plausible-looking garbage.
Common Mistakes
Quoting a QAOA approximation ratio without the classical baseline beside it
Fix: Always report random assignment, the 0.878 Goemans-Williamson guarantee and the exact optimum together so a 0.69 result is read in its proper frame
Setting the penalty coefficient lambda by guesswork
Fix: Bound it above the largest possible objective swing, then check the returned solution satisfies every constraint before trusting its cost
Assuming discretised portfolio optimisation is the same convex problem a classical solver already closes instantly
Fix: State the discretisation explicitly â the QUBO is non-convex, and that non-convexity is the only part where quantum could plausibly compete
Feeding a non-symmetric QUBO matrix to a solver that reads only the upper triangle
Fix: Upper-triangularise on purpose and add each off-diagonal term once, since writing both Q[i,j] and Q[j,i] silently doubles the quadratic contribution
Key Takeaways
- Combinatorial problems become quantum-usable only after constraints are folded into penalty terms, and the penalty must exceed the largest objective swing without overwhelming the matrix
- MaxCut has a 0.878 classical guarantee that low-depth QAOA does not beat, so claimed quantum advantage has to be measured against that number rather than against random assignment
- TSP needs n squared binary variables for n cities â 10 cities is already 100 qubits â which makes qubit count the binding constraint long before algorithm quality does
- Every QUBO problem shares one canonical form, which is why D-Wave, QAOA and hybrid solvers all consume the same matrix with only formatting differences