You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*Step 4 -- Verify a solution.* The optimal solution is $bold(x) = (#ks_qubo_sol.source_config.map(str).join(", "))$ (items 0 and 3), with slack $bold(s) = (0, 0, 0)$. Check constraint: $2 dot 1 + 5 dot 1 + 0 = 7 = C$#sym.checkmark. Penalty term: $(7 - 7)^2 = 0$ (feasible). Objective: $H = -(3 + 7) + 0 = -10$. The full QUBO configuration is $(#ks_qubo_sol.target_config.map(str).join(", "))$.
1206
+
1207
+
A suboptimal feasible solution $bold(x) = (0,1,1,0)$ gives weight $3 + 4 = 7$, value $9$, and $H = -9$. An infeasible selection $bold(x) = (1,1,0,1)$ has weight $10 > 7$; the penalty dominates: $H gt.eq -14 + 20 dot 9 = 166$.
1208
+
1209
+
*Count:*#ks_qubo_r.solutions.len() optimal solution (items $\{0, 3\}$ is the unique selection achieving value 10).
1210
+
],
1211
+
)[
1212
+
The 0-1 Knapsack capacity inequality $sum_i w_i x_i lt.eq C$ is converted to equality using $B = floor(log_2 C) + 1$ binary slack variables encoding the unused capacity. The penalty method (@sec:penalty-method) combines the negated value objective with a quadratic constraint penalty, producing a QUBO with $n + B$ binary variables.
1213
+
][
1214
+
_Construction._ Given $n$ items with weights $w_0, dots, w_(n-1)$, values $v_0, dots, v_(n-1)$, and capacity $C$, introduce $B = floor(log_2 C) + 1$ binary slack variables $s_0, dots, s_(B-1)$ to convert the capacity inequality to equality:
1215
+
$sum_(i=0)^(n-1) w_i x_i + sum_(j=0)^(B-1) 2^j s_j = C $
1216
+
Let $a_k$ denote the constraint coefficient of the $k$-th binary variable ($a_k = w_k$ for $k < n$, $a_(n+j) = 2^j$ for $j < B$). The QUBO objective is:
where $bold(z) = (x_0, dots, x_(n-1), s_0, dots, s_(B-1))$ and $P = 1 + sum_i v_i$. Expanding the quadratic penalty using $z_k^2 = z_k$ (binary):
1219
+
$ Q_(k k) = P a_k^2 - 2 P C a_k - [k < n] v_k, quad Q_(i j) = 2 P a_i a_j quad (i < j) $
1220
+
1221
+
_Correctness._ ($arrow.r.double$) If $bold(x)^*$ is a feasible knapsack solution with value $V^*$, then there exist slack values $bold(s)^*$ satisfying the equality constraint (encoding $C - sum w_i x_i^*$ in binary), so $f(bold(z)^*) = -V^*$. ($arrow.l.double$) If the equality constraint is violated, the penalty $(sum a_k z_k - C)^2 gt.eq 1$ contributes at least $P > sum_i v_i$ to the objective, exceeding the entire value range. Among feasible assignments (penalty zero), $f$ reduces to $-sum v_i x_i$, minimized at the knapsack optimum.
0 commit comments