Skip to content

Fix #210: [Model] Partition#664

Open
GiggleLiu wants to merge 4 commits intomainfrom
issue-210-partition-v2
Open

Fix #210: [Model] Partition#664
GiggleLiu wants to merge 4 commits intomainfrom
issue-210-partition-v2

Conversation

@GiggleLiu
Copy link
Contributor

Summary

Add the Partition problem model — a classical NP-complete satisfaction problem (Karp #20, Garey & Johnson SP12). Given a multiset of positive integers, decide whether it can be partitioned into two subsets of equal sum.

Implements the full model with brute-force solver support, canonical example, unit tests (>95% coverage), trait consistency, and paper entry.

Fixes #210

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.93%. Comparing base (9a2b2b7) to head (f3f9ed2).

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #664    +/-   ##
========================================
  Coverage   96.92%   96.93%            
========================================
  Files         271      273     +2     
  Lines       36298    36416   +118     
========================================
+ Hits        35182    35299   +117     
- Misses       1116     1117     +1     

☔ 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.

@GiggleLiu
Copy link
Contributor Author

Implementation Summary

Changes

  • src/models/misc/partition.rs — New Partition satisfaction problem model (Metric = bool, Vec<u64> sizes, evaluate checks selected_sum * 2 == total_sum)
  • src/unit_tests/models/misc/partition.rs — 14 unit tests covering basic accessors, satisfying/unsatisfying evaluation, edge cases (odd total, single element, two elements), solver integration, serialization, and panic paths
  • src/models/misc/mod.rs — Module registration + canonical example spec wiring
  • src/models/mod.rs — Re-export Partition
  • src/lib.rs — Added Partition to prelude
  • src/unit_tests/trait_consistency.rs — Added check_problem_trait entry
  • src/example_db/fixtures/examples.json — Regenerated (32 → 33 model examples)
  • docs/paper/reductions.typ — Added display-name entry + problem-def block after SubsetSum
  • docs/src/reductions/problem_schemas.json — Regenerated (41 → 42 schemas)
  • docs/src/reductions/reduction_graph.json — Regenerated

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 the Partition satisfaction problem model to the misc model catalog, integrating it into the registry/docs/example DB and ensuring it participates in the project’s shared solver + trait infrastructure.

Changes:

  • Introduces Partition model (Problem<Metric=bool>) with schema registration, variant declaration, and canonical example specs.
  • Adds a dedicated unit test suite for Partition and wires it into trait-consistency checks.
  • Updates generated documentation artifacts (problem schemas, reduction graph), paper catalog entry, and example DB fixtures.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/unit_tests/trait_consistency.rs Adds Partition to the cross-model trait sanity test.
src/unit_tests/models/misc/partition.rs New unit tests for Partition behavior, solver integration, and serialization.
src/models/mod.rs Re-exports Partition from models::misc.
src/models/misc/partition.rs New Partition model implementation, schema inventory entry, variants, and example spec hook.
src/models/misc/mod.rs Registers the new module and exposes Partition in misc.
src/lib.rs Adds Partition to the public prelude exports.
src/example_db/fixtures/examples.json Adds canonical Partition fixture (samples + satisfying set).
docs/src/reductions/reduction_graph.json Adds Partition node and shifts indices accordingly (generated artifact).
docs/src/reductions/problem_schemas.json Adds Partition schema entry (generated artifact).
docs/paper/reductions.typ Adds Partition to the paper’s problem catalog and definition section.

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

}

#[test]
#[should_panic(expected = "All sizes must be positive")]
Comment on lines +102 to +108
let selected_sum: u64 = config
.iter()
.enumerate()
.filter(|(_, &x)| x == 1)
.map(|(i, _)| self.sizes[i])
.sum();
selected_sum * 2 == self.total_sum()
Comment on lines +102 to +109
let selected_sum: u64 = config
.iter()
.enumerate()
.filter(|(_, &x)| x == 1)
.map(|(i, _)| self.sizes[i])
.sum();
selected_sum * 2 == self.total_sum()
}
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] Partition

2 participants