I am trying to use minizinc to build me a matrix of true/false, where each column satisfies certain conditions (at least 3 true values, and there must be an odd number of true values). So far, so good - but when I add additional constraints to make it so that each column is different (from all other columns), I don't get consistent results:
With the commented out version below, with minizinc 2.1.7 on Ubuntu-on-WSL (Windows), it finds a solution pretty much immediately. However, any version of minizinc (2.1.7, 2.2.0, 2.3.1) on either a Mac, or on an ArchLinux install, can't satisfy the constraints (at least not within a few minutes). All of this is with Gecode.
Chuffed works fine to satisfy the constraints, again with the commented-out version of the code rather than the one below.
However, if I solve to minimize certain values (see second snippet), then Chuffed doesn't find any solution anymore (again, at least not within a few minutes). I would have expected it to at least find the same solution as it finds for "satisfy".
What am I doing wrong? Are there better ways of writing the constraint of "distinct columns" that works more consistently? I wouldn't think this is a particular hard problem for a constraint solver, so I suspect it's really an issue with how I've written the constraints.
I would like to keep the H matrix as a 2d matrix of true/false, as there's other constraints that benefit from having it in that shape.
int: k = 7;
int: n = 47;
array[1..k,1..n] of var bool: H;
array[1..k] of var bool : flip_bits;
predicate all_different_int(array[int] of var int: x) =
forall(i,j in index_set(x) where i < j) ( x[i] != x[j] );
constraint forall(j in 1..n)(
sum(i in 1..k)(
if H[i,j] then 1 else 0 endif
) mod 2 > 0
);
constraint forall(j in 1..n)(
sum(i in 1..k)(
if H[i,j] then 1 else 0 endif
) >= 3
);
%array[1..n] of var int: H_t;
%constraint forall(j in 1..n)(
% H_t[j] = sum(i in 1..k)(
% if H[i,j] then pow(2,i) else 0 endif
% )
%);
%constraint all_different_int(H_t);
constraint all_different_int(
[sum(i in 1..k)(if H[i,j] then pow(2,i) else 0 endif) | j in 1..n]
);
solve satisfy;
var int: z2 = sum(i in 1..k, j in 1..n)(if H[i,j] then 1 else 0 endif);
var int: z1 = max(i in 1..k)(sum (j in 1..n)(if H[i,j] then 1 else 0 endif));
solve minimize z1*1000+z2;
xorall(). This should be much more efficient thanmod 2. - Axel Kemper