Fix #417: Add ConsecutiveOnesSubmatrix model#667
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #667 +/- ##
==========================================
+ Coverage 97.28% 97.31% +0.03%
==========================================
Files 322 324 +2
Lines 41598 41853 +255
==========================================
+ Hits 40470 40731 +261
+ Misses 1128 1122 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add satisfaction problem for the Consecutive Ones Submatrix problem (Garey & Johnson A4 SR14): given an m×n binary matrix and bound K, decide if K columns can be selected and permuted so each row's 1-entries are consecutive (C1P). - Model in src/models/algebraic/ with Heap's algorithm for permutations - 14 unit tests including Tucker matrix examples - CLI support (pred create ConsecutiveOnesSubmatrix --matrix --k) - Paper entry with CeTZ figure and bibliography - Trait consistency and example_db registration Co-Authored-By: Claude Opus 4.6 <[email protected]>
Implementation SummaryChanges
Deviations from Plan
Open Questions
|
There was a problem hiding this comment.
Pull request overview
Adds a new algebraic satisfaction model, ConsecutiveOnesSubmatrix, to the core library, along with CLI support, examples/fixtures, tests, and regenerated schema/reduction-graph documentation.
Changes:
- Implement
ConsecutiveOnesSubmatrixmodel (schema registration, evaluation, variants, example-db spec). - Add unit tests and wire the model into trait-consistency checks and module re-exports.
- Integrate with CLI
pred create, example fixtures, and regenerate docs JSON / paper references & section.
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/unit_tests/trait_consistency.rs | Adds trait/dims sanity check coverage for the new model. |
| src/unit_tests/models/algebraic/consecutive_ones_submatrix.rs | Introduces model-specific unit tests, brute-force solver checks, and serialization tests. |
| src/models/mod.rs | Re-exports ConsecutiveOnesSubmatrix from the models top-level module. |
| src/models/algebraic/mod.rs | Registers the new algebraic module and adds example-db spec wiring. |
| src/models/algebraic/consecutive_ones_submatrix.rs | Implements the model, registers schema metadata, declares variants, and adds example-db entry + tests module. |
| src/example_db/fixtures/examples.json | Adds a fixture instance + sample/optimal configs for the new model. |
| problemreductions-cli/src/commands/create.rs | Adds pred create ConsecutiveOnesSubmatrix instance construction via --matrix and --k. |
| problemreductions-cli/src/cli.rs | Documents the new problem’s CLI flags in the help text. |
| docs/src/reductions/reduction_graph.json | Adds the model node to the generated reduction graph docs (including shifted indices). |
| docs/src/reductions/problem_schemas.json | Adds the model schema to the generated schema docs. |
| docs/paper/references.bib | Adds Booth (1975) and Booth–Lueker (1976) references. |
| docs/paper/reductions.typ | Adds a paper definition + worked example/figure block for the model. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// Check if any permutation of the given columns has C1P. | ||
| fn any_permutation_has_c1p(&self, cols: &[usize]) -> bool { | ||
| let k = cols.len(); | ||
| if k == 0 { | ||
| return true; | ||
| } | ||
| let mut perm: Vec<usize> = cols.to_vec(); | ||
| // Generate all permutations using Heap's algorithm | ||
| let mut c = vec![0usize; k]; | ||
| if self.has_c1p(&perm) { | ||
| return true; | ||
| } | ||
| let mut i = 0; | ||
| while i < k { | ||
| if c[i] < i { | ||
| if i % 2 == 0 { | ||
| perm.swap(0, i); | ||
| } else { | ||
| perm.swap(c[i], i); | ||
| } | ||
| if self.has_c1p(&perm) { | ||
| return true; | ||
| } | ||
| c[i] += 1; | ||
| i = 0; | ||
| } else { | ||
| c[i] = 0; | ||
| i += 1; | ||
| } | ||
| } | ||
| false | ||
| } |
| impl SatisfactionProblem for ConsecutiveOnesSubmatrix {} | ||
|
|
||
| crate::declare_variants! { | ||
| default sat ConsecutiveOnesSubmatrix => "2^(num_cols) * num_rows", |
docs/paper/reductions.typ
Outdated
| let selected = cfg.enumerate().filter(((i, v)) => v == 1).map(((i, v)) => i) | ||
| [ | ||
| #problem-def("ConsecutiveOnesSubmatrix")[ | ||
| Given an $m times n$ binary matrix $A$ and a positive integer $K <= n$, determine whether there exists a subset of $K$ columns of $A$ whose columns can be permuted so that in each row all 1's occur consecutively (the _consecutive ones property_). |
| //! Given an m×n binary matrix A and a positive integer K ≤ n, determine whether | ||
| //! there exists a subset of K columns whose columns can be permuted so that in | ||
| //! each row all 1's occur consecutively. NP-complete (Booth, 1975) via | ||
| //! transformation from Hamiltonian Path. |
…17-consecutive-ones-submatrix # Conflicts: # docs/paper/reductions.typ # docs/src/reductions/problem_schemas.json # docs/src/reductions/reduction_graph.json # problemreductions-cli/src/commands/create.rs # src/example_db/fixtures/examples.json
Agentic Review ReportNote: This PR has merge conflicts with Structural Check
16/16 structural checks passed. Build: Whitelist violations: 6 files flagged — all justified and standard for a model PR ( Issue compliance (vs #417): 9/10 passed. One justified deviation: complexity string Semantic review highlights:
Suggestions (nice to have):
Quality CheckDesign principles: DRY OK, KISS OK, HC/LC OK HCI (CLI changed):
Test quality: OK — 19 tests with strong coverage:
Issues: None critical or important. Minor: Module doc in Agentic Feature Tests
16/16 feature tests passed. Full test suite: 2,223 tests pass, 0 failures, 0 clippy warnings. Observations (informational):
Generated by review-pipeline |
Agentic Review ReportStructural CheckStructural Completeness
16/16 structural checks passed. Build Status
Semantic Review
Issue Compliance (#417)
Issues Found
Quality CheckDesign Principles
HCI (CLI)
Test Quality
Issues Found
Agentic Feature Tests
All 7 tests PASS. No failures detected. The model is fully functional end-to-end: catalog registration, display, example creation, serialization, and brute-force solving all work correctly. Consolidated Findings
Generated by review-pipeline |
Resolve conflicts with QuadraticAssignment, PrimeAttributeName, PrecedenceConstrainedScheduling and other models added to main. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Change complexity from implementation cost (factorial permutation enumeration) to best-known algorithm bound (PQ-tree C1P testing) - Add ConsecutiveOnesSubmatrix to algebraic module docstring Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Summary
Add ConsecutiveOnesSubmatrix model — a satisfaction (decision) problem from Garey & Johnson A4 SR14. Given an m×n binary matrix and integer K, determines whether K columns can be selected and permuted so that each row's 1-entries are consecutive.
Fixes #417