this repo has no description
1int: n;
2array [1..n] of var 1..n: q; % 在第i列的皇后在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% 可选的布尔模型:
13% 映射每一个位置 i,j到一个布尔变量上来表示在i,j上是否有一个皇后
14array[1..n,1..n] of var bool: qb;
15
16% 连通约束
17constraint forall (i,j in 1..n) ( qb[i,j] <-> (q[i]=j) );
18
19% 字典排序对称性破缺
20constraint
21 lex_lesseq(array1d(qb), [ qb[j,i] | i,j in 1..n ])
22/\ lex_lesseq(array1d(qb), [ qb[i,j] | i in reverse(1..n), j in 1..n ])
23/\ lex_lesseq(array1d(qb), [ qb[j,i] | i in 1..n, j in reverse(1..n) ])
24/\ lex_lesseq(array1d(qb), [ qb[i,j] | i in 1..n, j in reverse(1..n) ])
25/\ lex_lesseq(array1d(qb), [ qb[j,i] | i in reverse(1..n), j in 1..n ])
26/\ lex_lesseq(array1d(qb), [ qb[i,j] | i,j in reverse(1..n) ])
27/\ lex_lesseq(array1d(qb), [ qb[j,i] | i,j in reverse(1..n) ])
28;
29
30% 搜索
31solve :: int_search(q, first_fail, indomain_min, complete)
32 satisfy;
33output [ if fix(q[j]) == i then "Q" else "." endif ++
34 if j == n then "\n" else "" endif | i,j in 1..n]