Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #663 +/- ##
==========================================
+ Coverage 96.94% 96.95% +0.01%
==========================================
Files 273 275 +2
Lines 36505 36735 +230
==========================================
+ Hits 35388 35618 +230
Misses 1117 1117 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add the Sum of Squares Partition satisfaction problem (Garey & Johnson SP19). Given positive integers, K groups, and bound J, determine whether the set can be partitioned into K groups with sum of squared group sums <= J. - Model: src/models/misc/sum_of_squares_partition.rs - Tests: 16 unit tests including paper example, edge cases, serialization - CLI: pred create SumOfSquaresPartition --sizes --num-groups --bound - Paper: problem-def entry in reductions.typ - Registry: declare_variants!, ProblemSchemaEntry, trait_consistency - Example DB: canonical model example with fixture regeneration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
Implementation SummaryChanges
Deviations from Plan
Open Questions
|
There was a problem hiding this comment.
Pull request overview
Adds a new satisfaction problem model, SumOfSquaresPartition, to the misc models set, and wires it into the library’s exports, CLI instance creation, example database, and generated docs so it can be created/solved like existing problems.
Changes:
- Introduces
SumOfSquaresPartitionmodel with schema registration, variants declaration, and example-db spec. - Adds unit tests and trait-consistency coverage for the new model.
- Integrates the model into CLI
pred create, example fixtures, and generated documentation artifacts.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/models/misc/sum_of_squares_partition.rs | New model implementation, schema registration, variant declaration, and example-db spec. |
| src/models/misc/mod.rs | Registers and re-exports the new misc model; adds example-db spec hook. |
| src/models/mod.rs | Re-exports SumOfSquaresPartition from the models root. |
| src/lib.rs | Adds SumOfSquaresPartition to the crate prelude exports. |
| src/unit_tests/models/misc/sum_of_squares_partition.rs | New unit test suite covering construction, evaluation, brute-force solving, and serialization. |
| src/unit_tests/trait_consistency.rs | Adds trait-consistency check for the new model’s dims(). |
| problemreductions-cli/src/cli.rs | Adds --num-groups flag to pred create arguments and help text. |
| problemreductions-cli/src/commands/create.rs | Adds pred create SumOfSquaresPartition ... wiring and example command string. |
| src/example_db/fixtures/examples.json | Adds a canonical example instance and satisfying configurations for the example DB. |
| docs/src/reductions/problem_schemas.json | Regenerates schemas JSON to include the new model. |
| docs/src/reductions/reduction_graph.json | Regenerates reduction graph JSON to include the new variant node. |
| docs/paper/reductions.typ | Adds the paper definition block for SumOfSquaresPartition. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+55
to
+63
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct SumOfSquaresPartition { | ||
| /// Positive integer sizes for each element. | ||
| sizes: Vec<i64>, | ||
| /// Number of groups K. | ||
| num_groups: usize, | ||
| /// Upper bound J on the sum of squared group sums. | ||
| bound: i64, | ||
| } |
Comment on lines
+113
to
+125
| pub fn sum_of_squares(&self, config: &[usize]) -> Option<i64> { | ||
| if config.len() != self.sizes.len() { | ||
| return None; | ||
| } | ||
| let mut group_sums = vec![0i64; self.num_groups]; | ||
| for (i, &g) in config.iter().enumerate() { | ||
| if g >= self.num_groups { | ||
| return None; | ||
| } | ||
| group_sums[g] += self.sizes[i]; | ||
| } | ||
| Some(group_sums.iter().map(|&s| s * s).sum()) | ||
| } |
Comment on lines
+70
to
+87
| /// Panics if any size is not positive (must be > 0), if `num_groups` is 0, | ||
| /// or if `num_groups` exceeds the number of elements. | ||
| pub fn new(sizes: Vec<i64>, num_groups: usize, bound: i64) -> Self { | ||
| assert!( | ||
| sizes.iter().all(|&s| s > 0), | ||
| "All sizes must be positive (> 0)" | ||
| ); | ||
| assert!(num_groups > 0, "Number of groups must be positive"); | ||
| assert!( | ||
| num_groups <= sizes.len(), | ||
| "Number of groups must not exceed number of elements" | ||
| ); | ||
| Self { | ||
| sizes, | ||
| num_groups, | ||
| bound, | ||
| } | ||
| } |
docs/paper/reductions.typ
Outdated
| #problem-def("SumOfSquaresPartition")[ | ||
| Given a finite set $A = {a_0, dots, a_(n-1)}$ with sizes $s(a_i) in ZZ^+$, a positive integer $K lt.eq |A|$ (number of groups), and a positive integer $J$ (bound), determine whether $A$ can be partitioned into $K$ disjoint sets $A_1, dots, A_K$ such that $sum_(i=1)^K (sum_(a in A_i) s(a))^2 lt.eq J$. | ||
| ][ | ||
| Problem SP19 in Garey and Johnson @garey1979. NP-complete in the strong sense, so no pseudo-polynomial time algorithm exists unless $P = "NP"$. For fixed $K$, a dynamic-programming algorithm runs in $O(n S^(K-1))$ pseudo-polynomial time, where $S = sum s(a)$. The problem remains NP-complete when the exponent 2 is replaced by any fixed rational $alpha > 1$. #footnote[No algorithm improving on brute-force $O(K^n)$ enumeration is known for the general case.] The squared objective penalizes imbalanced partitions, connecting it to variance minimization, load balancing, and $k$-means clustering. Sum of Squares Partition generalizes Partition ($K = 2$, $J = S^2 slash 2$). |
Contributor
Author
Review Pipeline Report
Remaining issues for final review
🤖 Generated by review-pipeline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add the SumOfSquaresPartition satisfaction problem (Garey & Johnson SP19, A3). Given a finite set of positive integers, K groups, and bound J, determine whether the set can be partitioned into K groups such that the sum of squared group sums is at most J.
Fixes #403