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
* Add plan for #116: Knapsack to QUBO reduction
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add plan for #114: Knapsack
* feat: add Knapsack to QUBO reduction rule
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: add Knapsack to QUBO example program
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: regenerate reduction graph after Knapsack->QUBO rule
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: add Knapsack to QUBO reduction in paper
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* style: fix formatting (cargo fmt)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: address PR #172 review comments
- Delete plan files per user request
- Remove KS alias per user request (keep only lowercase "knapsack")
- Fix num_slack_bits() to use integer bit-length instead of float log2
(avoids precision loss for large i64 capacities above 2^53)
- Fix 1i64 << j to 1u64 << j in QUBO slack coefficients
(avoids negative coefficient from signed overflow)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix Knapsack to QUBO review findings
* Fix final review findings: remove README example, use nonempty check, fmt
- Remove specific Knapsack→QUBO example from README (keep README high-level)
- Replace hardcoded example count (43) with nonempty check in rule_builders test
- Fix rustfmt formatting in example and test files
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Remove legacy example binary and its integration test
The per-reduction example file examples/reduction_knapsack_to_qubo.rs
follows a deprecated pattern. Canonical examples belong in
src/example_db/rule_builders.rs (already registered there).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Derive paper example values from loaded data instead of hardcoding
Replace hardcoded formulas and item selections in the Knapsack→QUBO
paper extra section with data-driven computations from load-example.
Constraint equation, penalty P, objective H, selected items, and
weight/value sums are now all derived from the canonical example data.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: GiggleLiu <cacate0129@gmail.com>
so any violation of the equality is more expensive than the entire knapsack value range.
1650
+
1651
+
*Step 4 -- Verify a solution.* The QUBO ground state $bold(z) = (#ks_qubo_sol.target_config.map(str).join(", "))$ extracts to the knapsack choice $bold(x) = (#ks_qubo_sol.source_config.map(str).join(", "))$. This selects items $\{#ks_qubo_selected.map(str).join(", ")\}$ with total weight $#ks_qubo_selected.map(i=>str(ks_qubo.source.instance.weights.at(i))).join(" + ") = #ks_qubo_sel_weight$ and total value $#ks_qubo_selected.map(i=>str(ks_qubo.source.instance.values.at(i))).join(" + ") = #ks_qubo_sel_value$, so the slack bits are all zero and the penalty term vanishes #sym.checkmark.
1652
+
1653
+
*Count:*#ks_qubo.solutions.len() optimal QUBO solution. The source optimum is unique because items $\{#ks_qubo_selected.map(str).join(", ")\}$ are the only feasible selection achieving value #ks_qubo_sel_value.
1654
+
],
1655
+
)[
1656
+
For a standard 0-1 Knapsack instance with nonnegative weights, nonnegative values, and nonnegative capacity, the inequality $sum_i w_i x_i lt.eq C$ is converted to equality using binary slack variables that encode the unused capacity. When $C > 0$, one can take $B = floor(log_2 C) + 1$ slack bits; when $C = 0$, a single slack bit also suffices. The penalty method (@sec:penalty-method) combines the negated value objective with a quadratic constraint penalty, producing a QUBO with $n + B$ binary variables.
1657
+
][
1658
+
_Construction._ Given $n$ items with nonnegative weights $w_0, dots, w_(n-1)$, nonnegative values $v_0, dots, v_(n-1)$, and nonnegative capacity $C$, introduce $B = floor(log_2 C) + 1$ binary slack variables $s_0, dots, s_(B-1)$ when $C > 0$ (or one slack bit when $C = 0$) to convert the capacity inequality to equality:
1659
+
$sum_(i=0)^(n-1) w_i x_i + sum_(j=0)^(B-1) 2^j s_j = C $
1660
+
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):
1663
+
$ 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) $
1664
+
1665
+
_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. Since all values are nonnegative, every feasible assignment has objective in the range $[-sum_i v_i, 0]$, so that penalty exceeds the entire feasible value range. Among feasible assignments (penalty zero), $f$ reduces to $-sum v_i x_i$, minimized at the knapsack optimum.
0 commit comments