Fix #443: Add RectilinearPictureCompression model#677
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #677 +/- ##
========================================
Coverage 97.31% 97.32%
========================================
Files 324 327 +3
Lines 41853 42170 +317
========================================
+ Hits 40731 41042 +311
- Misses 1122 1128 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Implement the Rectilinear Picture Compression problem: given an m x n binary matrix M and bound K, determine if at most K axis-aligned all-1 rectangles can cover precisely the 1-entries of M. Includes model file, unit tests, CLI create support, canonical example, trait consistency check, and regenerated fixtures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…(), add solution count assertion
Implementation SummaryChanges
Deviations from Plan
Open Questions
|
There was a problem hiding this comment.
Pull request overview
Adds a new satisfaction-problem model, RectilinearPictureCompression, to represent the NP-complete “cover 1-cells with ≤K all-1 rectangles” decision problem, along with CLI creation support and documentation/example catalog integration.
Changes:
- Introduces
RectilinearPictureCompressionmodel + schema registration + example-db spec. - Adds unit tests, CLI
pred createsupport, and fixture examples for the new model. - Regenerates/updates docs artifacts (schemas + reduction graph) and extends the paper with the new definition.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/models/misc/rectilinear_picture_compression.rs |
New model implementation, schema registration, variants, and example-db spec. |
src/models/misc/mod.rs |
Wires the new misc model module + re-export + example-db spec inclusion. |
src/models/mod.rs |
Re-exports the new model from the top-level models module. |
src/unit_tests/models/misc/rectilinear_picture_compression.rs |
Adds comprehensive unit tests for construction, maximal-rectangle enumeration, evaluation, brute-force behavior, and serialization. |
src/unit_tests/trait_consistency.rs |
Adds trait-consistency coverage for the new problem type. |
problemreductions-cli/src/commands/create.rs |
Adds pred create RectilinearPictureCompression instance construction + example flag string. |
problemreductions-cli/src/cli.rs |
Updates help text to document flags for the new problem. |
src/example_db/fixtures/examples.json |
Adds a fixture example instance + sample configs for the example database. |
docs/src/reductions/problem_schemas.json |
Adds generated schema entry for the new problem. |
docs/src/reductions/reduction_graph.json |
Adds generated variant node for the new problem (and reindexes edges accordingly). |
docs/paper/reductions.typ |
Adds paper definition/section + figure for Rectilinear Picture Compression. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Step 3: Filter to keep only maximal rectangles. | ||
| // A rectangle A is dominated by rectangle B if B contains A as a proper subset. | ||
| let mut maximal = Vec::new(); | ||
| for &(r1, c1, r2, c2) in &candidates { | ||
| let is_dominated = candidates.iter().any(|&(sr1, sc1, sr2, sc2)| { | ||
| sr1 <= r1 | ||
| && sc1 <= c1 | ||
| && sr2 >= r2 | ||
| && sc2 >= c2 | ||
| && (sr1, sc1, sr2, sc2) != (r1, c1, r2, c2) | ||
| }); | ||
| if !is_dominated { | ||
| maximal.push((r1, c1, r2, c2)); | ||
| } |
| /// Given an m x n binary matrix M and a positive integer K, determine whether | ||
| /// there exists a collection of at most K axis-aligned all-1 rectangles that | ||
| /// covers precisely the 1-entries of M. |
| covering entries $M_(i j)$ for $a lt.eq i lt.eq b$ and $c lt.eq j lt.eq d$, | ||
| where every covered entry must satisfy $M_(i j) = 1$. | ||
| ][ | ||
| Rectilinear Picture Compression is a classical NP-complete problem from Garey & Johnson (A4 SR25, p.~232) @garey1979. It arises naturally in image compression, DNA microarray design, integrated circuit manufacturing, and access control list minimization. NP-completeness was established by Masek (1978) via transformation from 3SAT. The best known exact algorithm runs in $O^*(2^(m n))$ by brute-force enumeration over all possible rectangle selections#footnote[No algorithm improving on brute-force is known for the general case of Rectilinear Picture Compression.]. |
| let m = self.num_rows(); | ||
| let n = self.num_cols(); | ||
|
|
||
| // Step 1: Enumerate all all-1 rectangles by extending from each (r1, c1). |
…43-rectilinear-picture-compression # Conflicts: # docs/src/reductions/problem_schemas.json # docs/src/reductions/reduction_graph.json # problemreductions-cli/src/commands/create.rs # src/models/misc/mod.rs # src/models/mod.rs # src/unit_tests/trait_consistency.rs
- allow RectilinearPictureCompression through the crate prelude and add a regression test - replace quadratic maximal-rectangle filtering with prefix-sum extension checks - align Rectilinear documentation with bound_k = 0 support and rephrase the paper complexity note
Review Pipeline Report
Follow-up fixes
Remaining issues for final review
🤖 Generated by review-pipeline |
Resolve conflicts: keep RectilinearPictureCompression alongside newly added models (ConsecutiveOnesSubmatrix, PrimeAttributeName, StaffScheduling, etc.). Adapt ModelExampleSpec to the new API (instance/optimal_config/optimal_value fields instead of build closure). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The parse_bool_rows refactor catches ragged rows before validate_staff_scheduling_args, producing a different error message. Update the assertion to accept either message. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zazabap
left a comment
There was a problem hiding this comment.
Final review passed. All CI green, implementation complete, 21 tests, paper section with figure. LGTM.
Summary
Add the RectilinearPictureCompression satisfaction problem model — a classical NP-complete problem (Garey & Johnson A4 SR25) asking whether a binary matrix can be exactly covered by K or fewer axis-aligned all-1 rectangles.
Fixes #443