A graph can represent conflicts between jobs, connections in a communications network, or relationships between candidate decisions. Changing the decision and its constraints gives rise to quite different optimization problems on the same graph. Binary quadratic models provide a common language for many of them.
A useful formulation should tell us three things: what a binary variable means, what is being optimized, and what makes an answer feasible. The feasibility check is especially important when comparing the output of heuristic methods.
Ten formulations
Let G = (V,E) be a simple undirected graph with n vertices. For node selection or partitioning, xv ∈ {0,1} indicates membership in a selected set. The cut objective is
C(x) = ∑{u,v}∈ Ewuv(xu + xv − 2xuxv).
Each term counts the edge weight exactly when its endpoints belong to different sides. Use unit weights unless the graph defines other weights.
| Problem | Objective and feasibility conditions |
|---|---|
| Max-Cut | Maximize C(x). There are no extra constraints. |
| Maximum independent set | Maximize ∑v xv, with xu + xv ≤ 1 on each edge. |
| Minimum vertex cover | Minimize ∑v xv, with xu + xv ≥ 1 on each edge. |
| Maximum clique | Maximize ∑v xv, with xu + xv ≤ 1 on each distinct nonedge. |
| Coloring with a fixed palette | Assign one color to every vertex. Minimize ∑{u,v}∈ E ∑c xu,cxv,c. A proper coloring has value zero. |
| Balanced bisection | Minimize C(x), with ∑v xv = n/2 for even order. |
| Minimum dominating set | Minimize ∑v xv, with xv + ∑u∈ N(v)xu ≥ 1 for every vertex. |
| Maximum-weight matching | Use one variable ye per edge. Maximize ∑e we ye, with ∑e∋ vye ≤ 1 for each vertex. |
| Minimum maximal matching | Minimize ∑e ye under the matching constraints, plus ∑f:f∩ e≠∅yf ≥ 1 for every edge e. |
| Traveling salesperson | On a complete distance graph use xv,t for vertex v at position t. Require one vertex per position and one position per vertex. Minimize ∑u,v,tduvxu,txv,(t+1) mod n. |
All the displayed hard conditions are linear in binary variables. The fixed-palette coloring formulation minimizes conflicts, rather than the number of colors. It counts conflicts among assignments that satisfy the one-color rule; a positive count means the assignment is not a proper coloring of the graph. For the traveling salesperson problem, a complete finite distance graph is assumed. For minimum maximal matching, a selected matching is maximal when no further edge can be added without breaking the matching condition. This is different from a maximum matching.
A reference calculation
The following illustration uses a six-vertex cycle with one chord, unit edge weights and a palette of two colors. For the tour it uses the metric closure, the complete graph of shortest-path distances. A tour in that closure need not be a Hamiltonian cycle using only original graph edges. Enumerating all relevant small candidates gives exact reference values. This is a standalone reference calculation, independent of a heuristic solver; the formulas above are the models to submit when investigating a larger instance.
Illustration: standalone Python calculation.
from itertools import combinations, product, permutations
V = set(range(6))
E = {(0,1),(1,2),(2,3),(3,4),(4,5),(0,5),(0,3)}
nonedges = set(combinations(sorted(V),2))-E
sets = [set(c) for k in range(len(V)+1) for c in combinations(sorted(V),k)]
cut = lambda s: sum((u in s) != (v in s) for u,v in E)
independent = lambda s: all(not {u,v} <= s for u,v in E)
cover = lambda s: all({u,v}&s for u,v in E)
clique = lambda s: all(not {u,v} <= s for u,v in nonedges)
dominates = lambda s: all(v in s or any(v in e and set(e)&s for e in E) for v in V)
alpha = max(map(len,filter(independent,sets)))
tau = min(map(len,filter(cover,sets)))
assert alpha+tau == len(V)
matchings = []
for k in range(len(E)+1):
for es in combinations(sorted(E),k):
ends = {v for e in es for v in e}
if len(ends)==2*k:
matchings.append((es,ends))
maximal = [es for es,ends in matchings if all(set(e)&ends for e in E)]
n = len(V)
d = [[0 if i==j else 1 if tuple(sorted((i,j))) in E else n+1
for j in range(n)] for i in range(n)]
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j], d[i][k]+d[k][j])
def tour_cost(p):
t = (0,)+p+(0,)
return sum(d[u][v] for u,v in zip(t,t[1:]))
results = dict(max_cut=max(map(cut,sets)), independent=alpha, cover=tau,
clique=max(map(len,filter(clique,sets))),
coloring_conflicts=min(sum(c[u]==c[v] for u,v in E)
for c in product(range(2),repeat=n)),
bisection=min(cut(s) for s in sets if len(s)==n//2),
dominating=min(map(len,filter(dominates,sets))),
matching=max(len(es) for es,_ in matchings),
minimal_maximal=min(map(len,maximal)),
tour=min(map(tour_cost,permutations(range(1,n)))))
assert results == dict(max_cut=7, independent=3, cover=3, clique=2,
coloring_conflicts=0, bisection=3, dominating=2,
matching=3, minimal_maximal=2, tour=6)
for problem,score in results.items():
print(problem,score) The exact reference values for this synthetic graph are:
| Model | Value | Independent check |
|---|---|---|
| Max-Cut | 7 | Count crossing edges |
| Independent set | 3 | No selected edge |
| Vertex cover | 3 | Every edge covered |
| Clique | 2 | Every selected pair adjacent |
| Two-color conflicts | 0 | Exactly one color per vertex; every edge joins different colors |
| Bisection | 3 | Equal side sizes; recount cut |
| Dominating set | 2 | Every vertex selected or adjacent to selection |
| Maximum matching | 3 | No shared endpoint |
| Minimum maximal matching | 2 | No additional edge can be added |
| Tour in the metric closure | 6 | Every vertex visited once and return to start |
For any returned assignment, apply the feasibility condition independently before comparing its score with the reference.
There is a useful independent relationship between two of the answers. The complement of any independent set is a vertex cover. At the optimum, the maximum independent-set size plus the minimum vertex-cover size equals the number of vertices. A pair of heuristic answers need not meet that equality. Either answer can also be used to construct a feasible solution of the other problem.
Choose the method for the structure
Some of these problems have effective specialized algorithms. Maximum-weight matching on a general graph has a polynomial-time algorithm, for example. The common binary formulation is useful when a model combines different decisions or requires additional conditions that change its structure. It also helps establish classical references for quantum optimization experiments.
A reader can extend the reference calculation by generating a small instance, independently evaluating the decoded solutions and then increasing the size. Record whether the answer satisfies all of the original problem's conditions as well as the mathematical model's rows. A feasible solution and a proven optimum are two different achievements.
The 4colors Optimizer for QUBO supports binary quadratic objectives with explicit linear constraints. These formulations provide a starting point for modeling your own graph optimization problems.
Further reading: Andrew Lucas, Ising formulations of many NP problems, Frontiers in Physics (2014), DOI: 10.3389/fphy.2014.00005.