Fix #116: Add Knapsack to QUBO reduction#172
Fix #116: Add Knapsack to QUBO reduction#172zazabap wants to merge 14 commits intoCodingThrust:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Re-export Knapsack from models/mod.rs (structural review finding) - Add tests: zero capacity, single item, greedy-not-optimal adversarial case Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #172 +/- ##
==========================================
+ Coverage 96.88% 96.91% +0.02%
==========================================
Files 200 204 +4
Lines 27537 27768 +231
==========================================
+ Hits 26680 26911 +231
Misses 857 857 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a new Knapsack problem model and wires in a Knapsack → QUBO reduction (via binary slack variables + quadratic penalty), including tests, CLI support, examples, and documentation/exports.
Changes:
- Introduces
Knapsackas a first-class problem model (schema-registered, exported in prelude, unit-tested). - Implements and registers the
Knapsack → QUBOreduction rule with closed-loop brute-force tests and an example exporter. - Updates CLI alias/dispatch plus regenerates reduction graph + schemas and adds paper documentation for Knapsack and the new rule.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/suites/examples.rs | Registers the new reduction_knapsack_to_qubo example in the examples test suite. |
| src/unit_tests/rules/knapsack_qubo.rs | Adds closed-loop tests validating the reduction against brute-force optimal solutions. |
| src/unit_tests/models/misc/knapsack.rs | Adds unit tests for Knapsack model behavior and serialization. |
| src/rules/mod.rs | Registers the new knapsack_qubo rule module. |
| src/rules/knapsack_qubo.rs | Implements Knapsack → QUBO reduction and solution extraction. |
| src/models/mod.rs | Re-exports Knapsack from models. |
| src/models/misc/mod.rs | Adds knapsack module and re-export in misc category. |
| src/models/misc/knapsack.rs | Implements the Knapsack model, schema registration, evaluation logic, and variant declaration. |
| src/lib.rs | Exposes Knapsack via the crate prelude. |
| problemreductions-cli/src/problem_name.rs | Adds KS / knapsack alias resolution. |
| problemreductions-cli/src/dispatch.rs | Adds load/serialize dispatch for Knapsack. |
| problemreductions-cli/src/commands/graph.rs | Removes stray whitespace (no functional change). |
| examples/reduction_knapsack_to_qubo.rs | Adds an example program exporting the reduction instance + result JSON. |
| docs/src/reductions/reduction_graph.json | Regenerates reduction graph to include Knapsack and Knapsack → QUBO. |
| docs/src/reductions/problem_schemas.json | Regenerates problem schemas to include Knapsack. |
| docs/plans/2026-03-04-knapsack-to-qubo.md | Adds implementation plan document for the reduction. |
| docs/plans/2026-03-04-knapsack-model.md | Adds implementation plan document for the model. |
| docs/paper/references.bib | Adds Knapsack-related bibliography entries. |
| docs/paper/reductions.typ | Adds Knapsack problem definition and the Knapsack → QUBO reduction write-up + example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- 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>
|
I have merged #171 , please rebased on the main branch. We'd better not simultaneouly work on models and rules to avoid diverged history. |
Summary
Closes #116