I need to maximize the number of red towers and blue tower placed on an NxN matrix. However, towers of different colors cant be on the same column, line or diagonal (in any direction). There also must be an equal number of tower for each color on the board. However, after modeling, I am alway getting an empty array (no towers placed) for a an array size of 4x4, when it clearly is possible.
Here is how i formulated the constraints: dim = 1..n
% Control the colors of the towers in each line
constraint
forall(ligne in dim) (
(forall(colonne in dim) (terrain[ligne, colonne] == B \/ terrain[ligne, colonne] == V) \/
forall(colonne in dim) (terrain[ligne, colonne] == R \/ terrain[ligne, colonne] == V) \/
forall(colonne in dim) (terrain[ligne, colonne] == V))
);
% Control the colors of the tower in each row
constraint
forall(colonne in dim) (
(forall(ligne in dim) (terrain[ligne, colonne] == B \/ terrain[ligne, colonne] == V) \/
forall(ligne in dim) (terrain[ligne, colonne] == R \/ terrain[ligne, colonne] == V) \/
forall(ligne in dim) (terrain[ligne, colonne] == V))
);
% Check for main diagonal
constraint
forall (i in dim) (
(forall(j in dim) (
forall(k in 0..min(n-i,n-j)) (terrain[i+k,j+k] == terrain[i,j] \/ terrain[i+k,j+k] == V)
)
)
);
% Check for secondary diagonal
constraint
forall (i in dim) (
(forall(j in dim) (
forall(k in 0..min(i-1,n-j)) (terrain[i-k,j+k] == terrain[i,j] \/ terrain[i-k,j+k] == V)
)
)
);
% Equal nuumber of towers
constraint
sum(i, j in dim)(bool2int(terrain[i, j] = B)) == sum(i, j in dim)(bool2int(terrain[i, j] = R));