Planning & Search in Rust
Esc

Loading…

↑↓ move ↵ open Esc close
Colour theme
All algorithms

QUBO penalty encoding

Also known as Penalty method for QUBO, Ising formulation

other planning-qubo

The penalty encoding turns a constrained problem over binary variables into a QUBO model, an energy offset + Σ aᵢ·xᵢ + Σ bᵢⱼ·xᵢ·xⱼ with no side conditions. Each constraint adds a quadratic penalty with a weight P that the caller picks: P·(1 − Σ xᵢ)² for exactly one, P·xᵢ·xⱼ per pair for at most one, and P·(Σ aᵢ·xᵢ + s − rhs)² for a linear constraint, whose slack s gets new bits weighted 1, 2, 4, … and a remainder, so it reaches exactly its maximum. With integer coefficients a penalty is 0 when its constraint holds and at least P otherwise; the builder does not tune P, and the decoder checks the constraints on the original variables. The model converts exactly to an Ising model over spins s = 2x − 1 and back: integer models scale every energy by 4 so the halves and quarters stay whole, and float models keep a scale of 1. Use it to hand a planning problem, such as assigning tasks to agents with capacities, to a QUBO sampler or an annealer.

Pseudocode

algorithm QUBO-Penalty-Encoding(objective, constraints)input: objective terms over named binary variables, constraints, each with a weight Poutput: QUBO model Q, and the constraints kept for the decoderQ ← the objective termsfor each constraint c with weight P doif c is exactly-one(x₁, …, x_k) thenadd-squared(Q, P, ⟨(x₁, 1), …, (x_k, 1)⟩, 1)      ▷ P · (1 − Σ xᵢ)²else if c is at-most-one(x₁, …, x_k) thenfor each pair i < j doQ ← Q + P · xᵢ · xⱼelseT ← the terms (xᵢ, aᵢ) of c                       ▷ rhs − slack-max ≤ Σ aᵢ · xᵢ ≤ rhsfor each w in slack-weights(slack-max) doappend(T, (new variable, w))                    ▷ named "c.slack0", "c.slack1", …add-squared(Q, P, T, rhs)                         ▷ P · (Σ aᵢ · xᵢ + s − rhs)²return Q, constraintsprocedure add-squared(Q, P, T, r)Q ← Q + P · r²for i in 1, …, |T| do(y, a) ← T[i]Q ← Q + P · (a − 2r) · a · y                        ▷ y · y = yfor j in i + 1, …, |T| do                           ▷ each pair once(z, b) ← T[j]Q ← Q + 2P · a · b · y · zfunction slack-weights(m)W ← ⟨⟩w ← 1while sum(W) < m doappend(W, min(w, m − sum(W)))                       ▷ 1, 2, 4, …, then the remainderw ← 2wreturn W                                              ▷ every value in 0, …, m is a subset sumfunction to-ising(Q)substitute xᵢ ← (1 + sᵢ) / 2 in 4 · E(x)divide every coefficient by 4 / scale                 ▷ scale 4 for integers keeps it exact; 1 for floatsreturn the Ising model and its scale                  ▷ to-qubo divides the scale out again

In the crates

  • planning-qubo

    Constraints become quadratic penalty terms on named binary variables (exactly-one, at-most-one, linear constraints with slack bits), added to the objective; QUBO and Ising models convert exactly.

    BuilderConstraintKind

Papers

  1. Ising formulations of many NP problems Andrew Lucas · 2014· Frontiers in Physics survey doi 10.3389/fphy.2014.00005 arXiv 1302.5843
  2. Quantum Bridge Analytics I: a tutorial on formulating and using QUBO models Fred Glover, Gary Kochenberger, Yu Du · 2019· 4OR survey doi 10.1007/s10288-019-00424-y