A set of benchmarks to compare a new prototype MiniZinc implementation
1include "regular.mzn"; 2int: X; 3int: Y; 4 5int: maxlen; 6 7array [1..Y,1..maxlen] of int: rows; 8 9array [1..X,1..maxlen] of int: cols; 10 11array[1..2, 1..2, 1..2] of 0..1: nonmul = 12 array3d(1..2, 1..2, 1..2, 13 [0, 0, 1, 1, 14 1, 0, 0, 1] 15 ); 16 17array[1..2, 1..2, 1..2] of 0..1: nonadd = 18 array3d(1..2, 1..2, 1..2, 19 [0, 0, 0, 1, 20 1, 0, 0, 1] 21 ); 22 23% variables 24% 25array[1..Y, 1..X] of var 1..2: A; 26 27% All variables in a region must be different 28% Ordering to ensure each variable is handled exactly once 29predicate nonogram_row( 30 array[1..Y, 1..X] of var 1..2: A, 31 array[int] of 0..1: cons, 32 int: row) = 33 nonogram([A[row, v] | v in 1..X], cons); 34 35predicate nonogram_col( 36 array[1..Y, 1..X] of var 1..2: A, 37 array[int] of 0..1: cons, 38 int: col) = 39 nonogram([A[v,col] | v in 1..Y], cons); 40 41predicate nonogram(array[int] of var 1..2: A, array [int] of int: cons) = 42 let { 43 int: n = if cons[1] = 0 then 0 else max(index_set(cons)) endif, 44 array [1..n + 1, 1..2] of int: consarr = 45 if cons[1] = 0 then [|1, 0|] 46 else array2d(1..n + 1, 1..2, 47 [1, 2] ++ 48 [ i * nonmul[cons[i - 1] + 1, cons[i] + 1, s] + 49 nonadd[cons[i - 1] + 1, cons[i] + 1, s] 50 | i in 2..n, s in 1..2 51 ] ++ 52 [n+1,0] 53 ) 54 endif 55 } in ( 56 regular(A, n + 1, 2, consarr, 1, {n + 1}) 57 ); 58 59constraint forall(i in 1..Y) ( 60 nonogram_row(A, [rows[i, j] | j in 1..maxlen where rows[i, j] >= 0], i) 61); 62 63constraint forall(i in 1..X) ( 64 nonogram_col(A, [cols[i, j] | j in 1..maxlen where cols[i, j] >= 0], i) 65); 66 67solve :: int_search(array1d(1..X*Y,A),input_order,indomain_max,complete) satisfy; 68 69output [ 70 if fix(A[r, c]) = 1 then " " else "." endif ++ 71 if c = Y then "\n" else " " endif 72 | r in 1..X, c in 1..Y 73];