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>
There was a problem hiding this comment.
Pull request overview
This PR adds the 0-1 Knapsack problem as a new model in the misc/ category, implementing it as described in Issue #114. The Knapsack problem is a foundational NP-complete problem from Karp's 21 problems, where the goal is to select items maximizing total value subject to a weight capacity constraint.
Changes:
- New
Knapsackmodel struct withProblemandOptimizationProblemtrait implementations, binary configuration space, inventory schema registration, and 15 comprehensive unit tests - CLI integration: dispatch for loading/serializing Knapsack instances and alias
KSfor the CLI - Documentation: paper problem definition with formal mathematical formulation, two new bibliography entries (Horowitz-Sahni 1974, Ibarra-Kim 1975), and updated schema JSON
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/models/misc/knapsack.rs |
Core Knapsack model implementation with Problem and OptimizationProblem traits |
src/models/misc/mod.rs |
Register and re-export Knapsack module |
src/models/mod.rs |
Add Knapsack to top-level misc re-exports |
src/unit_tests/models/misc/knapsack.rs |
15 unit tests covering evaluation, edge cases, brute force, serialization |
problemreductions-cli/src/dispatch.rs |
CLI dispatch for loading/serializing Knapsack |
problemreductions-cli/src/problem_name.rs |
Add KS alias and case-insensitive resolution |
docs/src/reductions/problem_schemas.json |
Add Knapsack schema entry |
docs/paper/reductions.typ |
Add display name and formal problem definition |
docs/paper/references.bib |
Add Horowitz-Sahni 1974 and Ibarra-Kim 1975 references |
docs/plans/2026-03-04-knapsack-model.md |
Implementation plan document |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #171 +/- ##
==========================================
+ Coverage 96.88% 96.90% +0.01%
==========================================
Files 200 202 +2
Lines 27537 27679 +142
==========================================
+ Hits 26680 26823 +143
+ Misses 857 856 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Paper definition: use w_0,...,w_(n-1) to match 0-based subset S ⊆ {0,...,n-1}
- Add Knapsack to prelude re-export for consistency with other misc models
Resolves Copilot review comments on PR CodingThrust#171.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ing aliases) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
GiggleLiu
left a comment
There was a problem hiding this comment.
Should mention if the set index is 0-based or 1-based.
| ("TSP", "TravelingSalesman"), | ||
| ("BP", "BinPacking"), | ||
| ("CVP", "ClosestVectorProblem"), | ||
| ("KS", "Knapsack"), |
There was a problem hiding this comment.
Is KS a good shorthand? I doubt it. Also, BP is also bad. Consider removing these two.
There was a problem hiding this comment.
Removed both KS and BP aliases (from ALIASES constant and resolve_alias match arms). Case-insensitive full names (knapsack, binpacking) still work.
- Delete docs/plans/2026-03-04-knapsack-model.md - Remove KS and BP short aliases; case-insensitive full names still work Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "bmf" => "BMF".to_string(), | ||
| "bicliquecover" => "BicliqueCover".to_string(), | ||
| "bp" | "binpacking" => "BinPacking".to_string(), | ||
| "binpacking" => "BinPacking".to_string(), |
There was a problem hiding this comment.
The BP alias for BinPacking is removed from both the ALIASES const and the resolve_alias() function. This is an unrelated breaking change: any existing CLI user who used pred create BP ... or pred evaluate BP ... will now get an "Unknown problem" error. If this removal was intentional, it should be mentioned in the PR description; otherwise, it should be reverted.
| "bp" | "binpacking" => "BinPacking".to_string(), | ||
| "binpacking" => "BinPacking".to_string(), | ||
| "cvp" | "closestvectorproblem" => "ClosestVectorProblem".to_string(), | ||
| "knapsack" => "Knapsack".to_string(), |
There was a problem hiding this comment.
The PR description mentions "CLI dispatch + alias (KS)" but no KS alias was actually added. The ALIASES const does not include ("KS", "Knapsack") and resolve_alias() does not handle "ks". If you intended to add this alias (matching the pattern of TSP, MIS, CVP, etc.), it should be added to both ALIASES and resolve_alias().
| crate::declare_variants! { | ||
| Knapsack => "2^(num_items / 2)", | ||
| } |
There was a problem hiding this comment.
The reduction_graph.json is auto-generated (via cargo run --example export_graph or pred export-graph) but has not been regenerated to include the new Knapsack node. Other misc models like Factoring and PaintShop appear as nodes in this file even without reduction edges. Since the declare_variants! macro registers Knapsack in the variant registry, re-running the export should add it. Without this update, the paper's completeness check (which compares display-name keys against reduction_graph.json nodes) may produce a warning for the missing Knapsack entry.
…ude Knapsack The Knapsack node was missing from the exported graph and schemas, which would cause the paper's completeness check to fail. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Addressing Copilot review comments1. Indexing inconsistency in paper definition ( 2. Knapsack missing from prelude ( 3. BP alias removal is breaking change ( 4. KS alias not added ( 5. reduction_graph.json not regenerated ( |
|
Reduction rule is here #116 and implemented #172 @GiggleLiu |
Summary
src/models/misc/knapsack.rs)KS)Test plan
cargo test -- knapsack)Closes #114
🤖 Generated with Claude Code