this repo has no description
1int: n;
2array [1..n] of var 1..n: q; % queen in column i is in row q[i]
3
4include "alldifferent.mzn";
5
6constraint alldifferent(q); % distinct rows
7constraint alldifferent([ q[i] + i | i in 1..n]); % distinct diagonals
8constraint alldifferent([ q[i] - i | i in 1..n]); % upwards+downwards
9
10include "lex_lesseq.mzn";
11
12% Symmetry breaking
13constraint symmetry_breaking_constraint(
14let {
15 % Alternative Boolean model:
16 % Map each position i,j to a Boolean telling us whether there is a queen at i,j
17 array[1..n,1..n] of var bool: qb;
18} in
19 % Channeling constraint
20 forall (i,j in 1..n) ( qb[i,j] <-> (q[i]=j) )
21 % Lexicographic symmetry breaking constraints
22/\ lex_lesseq(array1d(qb), [ qb[j,i] | i,j in 1..n ])
23/\ lex_lesseq(array1d(qb), [ qb[i,j] | i in reverse(1..n), j in 1..n ])
24/\ lex_lesseq(array1d(qb), [ qb[j,i] | i in 1..n, j in reverse(1..n) ])
25/\ lex_lesseq(array1d(qb), [ qb[i,j] | i in 1..n, j in reverse(1..n) ])
26/\ lex_lesseq(array1d(qb), [ qb[j,i] | i in reverse(1..n), j in 1..n ])
27/\ lex_lesseq(array1d(qb), [ qb[i,j] | i,j in reverse(1..n) ])
28/\ lex_lesseq(array1d(qb), [ qb[j,i] | i,j in reverse(1..n) ])
29);
30
31% search
32solve :: int_search(q, first_fail, indomain_min)
33 satisfy;
34output [ if fix(q[j]) == i then "Q" else "." endif ++
35 if j == n then "\n" else "" endif | i,j in 1..n]