This formulation seems to be very close to being linearized. I changed
subject to c1 {i in 1..f} : ((sum {q in Z} (if X[2 - i mod 2, 3 - i mod 3, q] then q)) +
(sum {q in Z} (if X[2 - i mod 2 + 1, 3 - i mod 3, q] then q))) =
(sum {j in 1..K} (if S[i,j] then 4+2*j));
to
subject to c1 {i in 1..f} : ((sum {q in Z} (q * X[2 - i mod 2, 3 - i mod 3, q])) +
(sum {q in Z} (q * X[2 - i mod 2 + 1, 3 - i mod 3, q]))) =
(sum {j in 1..K} ((4+2*j) * S[i,j]));
and I changed
subject to c3 {i in 1..n, j in 1..n} : exactly 1 {q in Z} (X[i,j,q]);
to
subject to c3 {i in 1..n, j in 1..n} : sum {q in Z} (X[i,j,q]) = 1;
and similarly for other constraints of the same forms, and then I was able to use a MIP solver as shown in the listing below. I can't guarantee that the result is what you want, but this should give you an idea what you might do.
There seems to be a bug somewhere when JaCoP is used, but I am not sure what it is.
Bob Fourer
am...@googlegroups.com
///////
ampl: option solver gurobi;
ampl: solve;
Gurobi 6.5.1: optimal solution; objective 0
3663 simplex iterations
227 branch-and-cut nodes
ampl: option display_1col 10000, omit_zero_rows 1;
ampl: display X;
X :=
1 1 5 1
1 2 17 1
1 3 7 1
2 1 11 1
2 2 3 1
2 3 5 1
3 1 7 1
3 2 3 1
3 3 23 1
;
ampl: display S;
S :=
1 8 1
2 7 1
3 4 1
4 1 1
5 6 1
6 12 1
7 5 1
8 10 1
9 3 1
10 2 1
11 9 1
12 11 1
;
ampl:
=======