Skip to content

Fix #443: Add RectilinearPictureCompression model#677

Open
GiggleLiu wants to merge 8 commits intomainfrom
issue-443-rectilinear-picture-compression
Open

Fix #443: Add RectilinearPictureCompression model#677
GiggleLiu wants to merge 8 commits intomainfrom
issue-443-rectilinear-picture-compression

Conversation

@GiggleLiu
Copy link
Contributor

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

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.06%. Comparing base (dfcc313) to head (645e7a1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #677      +/-   ##
==========================================
+ Coverage   97.04%   97.06%   +0.02%     
==========================================
  Files         284      287       +3     
  Lines       38037    38347     +310     
==========================================
+ Hits        36914    37223     +309     
- Misses       1123     1124       +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 and others added 4 commits March 17, 2026 00:13
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>
@GiggleLiu
Copy link
Contributor Author

Implementation Summary

Changes

  • src/models/misc/rectilinear_picture_compression.rs — New satisfaction problem model (binary matrix + bound K, maximal all-1 rectangle enumeration, precomputed candidate cache)
  • src/unit_tests/models/misc/rectilinear_picture_compression.rs — 21 unit tests (construction, evaluation, solver, serialization, edge cases, panic tests)
  • src/models/misc/mod.rs, src/models/mod.rs — Module registration and re-export
  • problemreductions-cli/src/commands/create.rs, problemreductions-cli/src/cli.rs — CLI pred create RectilinearPictureCompression --matrix --k support
  • src/unit_tests/trait_consistency.rs — Trait consistency check
  • src/example_db/ — Canonical model example (4×4 two-block matrix)
  • docs/paper/reductions.typ — Problem definition, background, CeTZ example diagram

Deviations from Plan

  • Maximal rectangles are precomputed in the constructor and cached (review fix: avoids redundant recomputation in dims() and evaluate())
  • Custom Deserialize implementation to recompute cache on deserialization
  • matrix() returns &[Vec<bool>] instead of &Vec<Vec<bool>> (idiomatic Rust)

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 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 RectilinearPictureCompression model + schema registration + example-db spec.
  • Adds unit tests, CLI pred create support, 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.

Comment on lines +181 to +194
// 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));
}
Comment on lines +31 to +33
/// 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
@GiggleLiu
Copy link
Contributor Author

Review Pipeline Report

Check Result
Copilot comments 4 fixed
Issue/human comments checked, no open items
Structural review passed after follow-up fixes
CI green
Agentic test passed
Needs human decision none
Board Review pool → Under review → Final review

Follow-up fixes

  • Corrected schema-driven pred create help for RectilinearPictureCompression and LengthBoundedDisjointPaths.
  • Made shared pred create --help descriptions for --matrix and --k generic instead of problem-specific.
  • Made pred inspect report only actually usable solvers for the loaded problem.
  • Validated ragged boolean matrices in pred create so malformed input now returns a user-facing error instead of panicking.
  • Added/updated CLI docs for the RectilinearPictureCompression workflow and aligned the paper example wording.
  • Added CLI regressions covering the new help, inspect, and validation behavior.

Remaining issues for final review

  • None.

🤖 Generated by review-pipeline

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] RectilinearPictureCompression

2 participants