-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Motivation
CONSECUTIVE BLOCK MINIMIZATION (P165) from Garey & Johnson, A4 SR17. An NP-complete problem from the domain of storage and retrieval. Given a binary matrix, find a column permutation that minimizes the total number of maximal blocks of consecutive 1's across all rows. This problem arises in information retrieval (consecutive file organization), scheduling, production planning, the glass cutting industry, and data compression.
Associated rules:
- R111: Hamiltonian Path -> Consecutive Block Minimization (as target)
Definition
Name: ConsecutiveBlockMinimization
Canonical name: CONSECUTIVE BLOCK MINIMIZATION
Reference: Garey & Johnson, Computers and Intractability, A4 SR17
Mathematical definition:
INSTANCE: An m x n matrix A of 0's and 1's and a positive integer K.
QUESTION: Is there a permutation of the columns of A that results in a matrix B having at most K blocks of consecutive 1's? (A block of consecutive 1's in row i is a maximal run of consecutive 1-entries b_{i,j}, b_{i,j+1}, ..., b_{i,j+l} = 1.)
Variables
- Count:
num_colsvariables, one per column, representing the column's position in the permutation. - Per-variable domain: Each column variable takes a value in {0, ..., num_cols - 1}, forming a permutation.
dims():vec![num_cols; num_cols]— each of the n columns is assigned a position in the permutation.evaluate(): Interpret the configuration as a column permutation pi. Reorder the matrix columns by pi, count the total number of maximal blocks of consecutive 1's across all rows. Returntrueiff the total is <= bound_k and the configuration is a valid permutation (all values distinct).
Schema (data type)
Type name: ConsecutiveBlockMinimization
Variants: None
| Field | Type | Description |
|---|---|---|
matrix |
Vec<Vec<bool>> |
The m x n binary matrix A |
bound_k |
usize |
The positive integer K (upper bound on total number of 1-blocks) |
Size fields (getter methods for overhead expressions and declare_variants!):
num_rows()— returnsmatrix.len()(m)num_cols()— returnsmatrix[0].len()(n)bound_k()— returns K
Notes:
- This is a satisfaction (decision) problem:
Metric = bool, implementingSatisfactionProblem. - A "1-block" is a maximal contiguous run of 1's in a row. The total count is summed over all rows.
- When K equals the number of non-all-zero rows, the problem reduces to testing the consecutive ones property, which is polynomial-time solvable via PQ-trees.
Complexity
- Best known exact algorithm: O(n! * m * n) brute-force over all column permutations. For practical instances, ILP formulations and metaheuristics (iterated local search, exponential neighborhood search) are used.
- NP-completeness: NP-complete [Kou, 1977]. Transformation from HAMILTONIAN PATH.
- Approximation: 1.5-approximation algorithm exists [Haddadi & Layouni, 2008]. Polynomial-time local-improvement algorithms also known.
declare_variants!complexity string:"num_cols^num_cols * num_rows * num_cols"(brute-force over all n! column permutations, bounded by n^n, times O(m*n) to count blocks).- Circular variant: The variant where we count blocks allowing wrap-around (i.e., the first and last column are adjacent) is also NP-complete [Booth, 1975].
- References:
- L. T. Kou (1977). "Polynomial complete consecutive information retrieval problems." SIAM Journal on Computing, 6(1):67-75.
- S. Haddadi, Z. Layouni (2008). "Consecutive block minimization is 1.5-approximable." Information Processing Letters, 108(3):161-163.
- K. S. Booth (1975). "PQ Tree Algorithms." Ph.D. thesis, University of California, Berkeley.
Extra Remark
Full book text:
INSTANCE: An m x n matrix A of 0's and 1's and a positive integer K.
QUESTION: Is there a permutation of the columns of A that results in a matrix B having at most K blocks of consecutive 1's, i.e., having at most K entries bij such that bij = 1 and either bi,j+1 = 0 or j = n?
Reference: [Kou, 1977]. Transformation from HAMILTONIAN PATH.
Comment: Remains NP-complete if "j = n" is replaced by "j = n and bi1 = 0" [Booth, 1975]. If K equals the number of rows of A that are not all 0, then these problems are equivalent to testing A for the consecutive ones property or the circular ones property, respectively, and can be solved in polynomial time.
How to solve
- It can be solved by (existing) bruteforce -- enumerate all n! column permutations and count blocks of consecutive 1's in each row.
- It can be solved by reducing to integer programming -- ILP with binary variables x_{c,p} for column c at position p, and constraints counting 1-blocks.
- Other: Metaheuristics (iterated local search, simulated annealing); 1.5-approximation; polynomial-time local-improvement.
Example Instance
Instance 1 (NO instance):
Matrix A (3 x 6):
Row 0: [1, 0, 1, 0, 1, 0]
Row 1: [0, 1, 0, 1, 0, 1]
Row 2: [1, 1, 0, 0, 1, 1]
K = 2
With identity column order, Row 0 has three 1-blocks ({0},{2},{4}), Row 1 has three 1-blocks ({1},{3},{5}), Row 2 has two 1-blocks ({0,1},{4,5}). Total = 3+3+2 = 8 > 2.
The optimal permutation is pi = (2, 0, 4, 1, 5, 3):
Row 0: [1, 1, 1, 0, 0, 0] -> 1 block
Row 1: [0, 0, 0, 1, 1, 1] -> 1 block
Row 2: [0, 1, 1, 1, 1, 0] -> 1 block
Total = 1+1+1 = 3 > 2.
Answer: NO (minimum achievable is 3 for this matrix)
Instance 2 (YES instance with Hamiltonian path connection):
Matrix A (adjacency matrix of a path graph P_6), 6 x 6:
v0 v1 v2 v3 v4 v5
v0: [ 0, 1, 0, 0, 0, 0]
v1: [ 1, 0, 1, 0, 0, 0]
v2: [ 0, 1, 0, 1, 0, 0]
v3: [ 0, 0, 1, 0, 1, 0]
v4: [ 0, 0, 0, 1, 0, 1]
v5: [ 0, 0, 0, 0, 1, 0]
K = 6 (one block per row)
Column permutation pi = (0, 2, 4, 1, 3, 5) achieves the optimum:
v0: [0, 0, 0, 1, 0, 0] -> 1 block
v1: [1, 1, 0, 0, 0, 0] -> 1 block
v2: [0, 0, 0, 1, 1, 0] -> 1 block
v3: [0, 1, 1, 0, 0, 0] -> 1 block
v4: [0, 0, 0, 0, 1, 1] -> 1 block
v5: [0, 0, 1, 0, 0, 0] -> 1 block
Total = 6 = K. Answer: YES.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status