You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix#420: Add ConsecutiveBlockMinimization model (#668)
* Add plan for #420: ConsecutiveBlockMinimization model
* Implement #420: Add ConsecutiveBlockMinimization model
Add the Consecutive Block Minimization satisfaction problem (Garey &
Johnson SR17) to the algebraic/ category. Given an m×n binary matrix
and bound K, decide whether a column permutation exists yielding at
most K maximal blocks of consecutive 1's across all rows.
- Model with SatisfactionProblem trait, dims=[n;n] permutation space
- CLI create with --matrix (JSON) and --bound-k flags
- Unit tests: creation, evaluation, count_blocks, brute_force,
serialization, invalid permutation, empty matrix
- Paper entry with citations (Kou 1977, Booth 1975, Haddadi 2008)
- Example DB fixture with 2×3 matrix instance
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: remove plan file after implementation
* fix: validate empty CBM permutations
* fix: harden CBM CLI and deserialization
* docs: surface CBM CLI usage
* Fix canonical_model_example_specs for new ModelExampleSpec API
The ModelExampleSpec struct changed on main (build closure -> instance/optimal_config/optimal_value fields).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Run cargo fmt after merge with main
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Use issue #420 Instance 2 (P_6 adjacency matrix) as canonical example
Update canonical_model_example_specs to use the 6x6 path graph
adjacency matrix with K=6 from the issue. Fix paper to use new
optimal_config field format.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix SchedulingWithIndividualDeadlines paper section for new example format
Update from old x.samples.at(0).config to x.optimal_config to match
the current ModelExampleSpec format.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Rename --bound-k CLI flag to --bound for ConsecutiveBlockMinimization
Reuse the existing --bound flag instead of adding a separate --bound-k.
Other models with bound_k fields (RectilinearPictureCompression,
MinimumCardinalityKey, ConsecutiveOnesSubmatrix) already map to --k.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Use i64 for bound_k to match CLI --bound type directly
Avoids type conversion between CLI i64 and model usize.
Negative bounds correctly mean no permutation can satisfy.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Remove contradictory --bound assertion in CLI test
After renaming --bound-k to --bound, the negative assertion became
contradictory with the positive one. Remove since --bound-k no longer exists.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Rename bound_k to bound (i64) across all models
Unify the field name and type for CBM, MinimumCardinalityKey,
ConsecutiveOnesSubmatrix, and RectilinearPictureCompression.
All now use `bound: i64` matching the CLI --bound flag directly.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Xiwei Pan <xiwei.pan@connect.hkust-gz.edu.cn>
Copy file name to clipboardExpand all lines: README.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,17 @@ make cli # builds target/release/pred
42
42
43
43
See the [Getting Started](https://codingthrust.github.io/problem-reductions/getting-started.html) guide for usage examples, the reduction workflow, and [CLI usage](https://codingthrust.github.io/problem-reductions/cli.html).
44
44
45
+
Try a model directly from the CLI:
46
+
47
+
```bash
48
+
# Show the Consecutive Block Minimization model (alias: CBM)
49
+
pred show CBM
50
+
51
+
# Create and solve a small CBM instance (currently with brute-force)
52
+
pred create CBM --matrix '[[true,false,true],[false,true,true]]' --bound 2 \
53
+
| pred solve - --solver brute-force
54
+
```
55
+
45
56
## MCP Server (AI Integration)
46
57
47
58
The `pred` CLI includes a built-in [MCP](https://modelcontextprotocol.io/) server for AI assistant integration (Claude Code, Cursor, Windsurf, OpenCode, etc.).
Given an $m times n$ binary matrix $A$ and a positive integer $K$, determine whether there exists a permutation of the columns of $A$ such that the resulting matrix has at most $K$ maximal blocks of consecutive 1-entries (summed over all rows). A _block_ is a maximal contiguous run of 1-entries within a single row.
2513
+
][
2514
+
Consecutive Block Minimization (SR17 in Garey & Johnson) arises in consecutive file organization for information retrieval systems, where records stored on a linear medium must be arranged so that each query's relevant records form a contiguous segment. Applications also include scheduling, production planning, the glass cutting industry, and data compression. NP-complete by reduction from Hamiltonian Path @kou1977. When $K$ equals the number of non-all-zero rows, the problem reduces to testing the _consecutive ones property_, solvable in polynomial time via PQ-trees @booth1975. A 1.5-approximation is known @haddadi2008. The best known exact algorithm runs in $O^*(n!)$ by brute-force enumeration of all column permutations.
2515
+
2516
+
*Example.* Let $A$ be the #n-rows$times$#n-cols matrix with rows #mat.enumerate().map(((i, row)) => [$r_#i = (#row.map(v=>ifv {$1$} else {$0$}).join($,$))$]).join(", ") and $K = #K$. The column permutation $pi = (#perm.map(p=>str(p)).join(", "))$ yields #total-blocks total blocks, so #total-blocks$<= #K$ and the answer is YES.
2517
+
]
2518
+
]
2519
+
}
2520
+
2487
2521
#{
2488
2522
letx= load-model-example("PaintShop")
2489
2523
letn-cars= x.instance.num_cars
@@ -2765,7 +2799,7 @@ A classical NP-complete problem from Garey and Johnson @garey1979[Ch.~3, p.~76],
let matrix:Vec<Vec<bool>> = serde_json::from_str(matrix_str).map_err(|err| {
1872
+
anyhow::anyhow!(
1873
+
"ConsecutiveBlockMinimization requires --matrix as a JSON 2D bool array (e.g., '[[true,false,true],[false,true,true]]')\n\n{usage}\n\nFailed to parse --matrix: {err}"
0 commit comments