In reply to sparsh.gupta:
I think the best approach would be to constrain zero elements not to be adjacent.
constraint not_neighbor { foreach (mat[i][j]) {
i>0 && j>0 -> mat[i][j] || mat[i-1][j-1];
i>0 -> mat[i][j] || mat[i-1][j];
i>0 && j< $size(mat,2)-1 -> mat[i][j] != { mat[i-1][j+1];
... // I'll let you fill this in. You need one line for each side and corner
i<$size(mat,1)-1 && j< $size(mat,2)-1 -> mat[i][j] != { mat[i+1][j+1];
} }