Skip to content

Fix #402: Add SubsetSum model#602

Merged
GiggleLiu merged 8 commits intomainfrom
issue-402-subset-sum
Mar 13, 2026
Merged

Fix #402: Add SubsetSum model#602
GiggleLiu merged 8 commits intomainfrom
issue-402-subset-sum

Conversation

@zazabap
Copy link
Collaborator

@zazabap zazabap commented Mar 12, 2026

Summary

  • Add SubsetSum satisfaction problem model to src/models/misc/
  • SubsetSum: given a set of positive integers and target B, decide if a subset sums to exactly B
  • Include CLI registration, unit tests, and serialization support

Fixes #402

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 97.67442% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.77%. Comparing base (6cc8cb6) to head (3379082).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/longestcommonsubsequence_ilp.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #602      +/-   ##
==========================================
+ Coverage   96.76%   96.77%   +0.01%     
==========================================
  Files         226      226              
  Lines       29949    29919      -30     
==========================================
- Hits        28981    28955      -26     
+ Misses        968      964       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

zazabap and others added 2 commits March 12, 2026 13:24
- Add SubsetSum satisfaction problem to src/models/misc/
- Binary variables: x_i = 1 if element i is in the subset
- Evaluates true iff selected subset sums to target B
- Complexity: 2^(n/2) via Horowitz-Sahni meet-in-the-middle
- CLI: pred create SubsetSum --sizes 3,7,1,8,2,4 --target 11
- 15 unit tests covering basic, edge cases, brute force, serialization
- Regenerated problem schemas JSON

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zazabap
Copy link
Collaborator Author

zazabap commented Mar 12, 2026

Implementation Summary

Changes

  • src/models/misc/subset_sum.rs — SubsetSum model (satisfaction problem): struct with sizes: Vec<u64> and target: u64, Problem/SatisfactionProblem impls, declare_variants with 2^(num_items / 2) complexity
  • src/unit_tests/models/misc/subset_sum.rs — 15 unit tests covering basic accessors, evaluate feasible/infeasible, empty set, brute force, serialization, edge cases
  • src/models/misc/mod.rs — register module and re-export
  • src/lib.rs — add SubsetSum to prelude
  • problemreductions-cli/src/problem_name.rs — add "subsetsum" alias
  • problemreductions-cli/src/dispatch.rs — add deser_sat/try_ser for SubsetSum
  • problemreductions-cli/src/cli.rs — add SubsetSum to help table
  • problemreductions-cli/src/commands/create.rs — add create handler (--sizes, --target)
  • docs/src/reductions/problem_schemas.json — regenerated (now 25 schemas)

Deviations from Plan

  • None

Open Questions

  • None

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SubsetSum satisfaction problem model to the library, along with CLI wiring and documentation schema updates so instances can be created/loaded/serialized consistently across the ecosystem.

Changes:

  • Introduces SubsetSum model (Problem<Metric=bool> + SatisfactionProblem) with schema registration and variants declaration.
  • Adds unit tests covering evaluation behavior, brute-force solving, and serde roundtrips.
  • Registers SubsetSum in the CLI (name resolution, create command, dispatch load/serialize) and updates docs problem schema JSON.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/models/misc/subset_sum.rs New SubsetSum problem model + registry schema + variants + tests module hook
src/unit_tests/models/misc/subset_sum.rs Unit tests for SubsetSum evaluation/solver/serialization
src/models/misc/mod.rs Exposes SubsetSum from models::misc
src/lib.rs Adds SubsetSum to the crate prelude
problemreductions-cli/src/problem_name.rs Adds subsetsum alias resolution
problemreductions-cli/src/dispatch.rs Adds load/serialize dispatch for SubsetSum
problemreductions-cli/src/commands/create.rs Adds pred create SubsetSum --sizes ... --target ... support
problemreductions-cli/src/cli.rs Documents SubsetSum flags in CLI help text
docs/src/reductions/problem_schemas.json Adds SubsetSum entry to exported problem schema list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +24 to +26
/// Given a finite set A with sizes `s(a) ∈ Z⁺` for each element and a
/// positive integer B, determine whether there exists a subset `A' ⊆ A`
/// such that `∑_{a ∈ A'} s(a) = B`.
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs/spec say the target B is a “positive integer”, but the implementation (u64) and unit tests explicitly allow target = 0 (e.g., empty set / target 0). Please either (a) update the documentation to describe B as nonnegative, or (b) enforce target > 0 in new() (and adjust/remove the target=0 tests accordingly) so the docs match behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +400 to +414
{
"name": "SubsetSum",
"description": "Decide if a subset of positive integers sums to a target value",
"fields": [
{
"name": "sizes",
"type_name": "Vec<u64>",
"description": "Positive integer size s(a) for each element a in A"
},
{
"name": "target",
"type_name": "u64",
"description": "Target sum B"
}
]
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

problem_schemas.json was updated for SubsetSum, but docs/src/reductions/reduction_graph.json is also generated from the registry and currently does not include any SubsetSum node/entry. Please regenerate and commit the updated reduction_graph.json (e.g., cargo run --example export_graph) so the docs’ JSON resources stay consistent.

Copilot uses AI. Check for mistakes.
GiggleLiu and others added 3 commits March 13, 2026 11:43
Resolve conflicts: prefer main's i64/num_elements convention for SubsetSum,
keep additional test coverage, combine CLI additions (GraphPartitioning,
MinimumFeedbackVertexSet, SubsetSum).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address Copilot review comment: ensure SubsetSum appears in both
generated JSON docs files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix type_format_hint() to handle Vec<i64> and i64 types, and add
SubsetSum entry to example_for() so `pred create SubsetSum` shows
a helpful usage example.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@GiggleLiu
Copy link
Contributor

Review Pipeline Report

Check Result
Merge conflicts Resolved (7 files, main merged)
Copilot comments 2 checked, 1 fixed (regenerated reduction_graph.json), 1 already addressed (doc wording)
Issue/human comments 1 checked (quality report — informational, no action needed)
CI green
Agentic test passed — fixed CLI format hints and added example for pred create SubsetSum
Board review-agentic → In Review

🤖 Generated by review-pipeline

GiggleLiu and others added 2 commits March 13, 2026 19:24
- Fix corrupted reduction_graph.json that had stdout text mixed into the file
- Apply rustfmt formatting to two example files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
# Conflicts:
#	problemreductions-cli/src/commands/create.rs
@GiggleLiu GiggleLiu merged commit f394f23 into main Mar 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Model] SubsetSum

3 participants