| 1 |
/*** |
| 2 |
!Test |
| 3 |
expected: |
| 4 |
- !Result |
| 5 |
solution: !Solution |
| 6 |
q: [2, 4, 6, 8, 3, 1, 7, 5] |
| 7 |
- !Result |
| 8 |
solution: !Solution |
| 9 |
q: [2, 5, 7, 1, 3, 8, 6, 4] |
| 10 |
- !Result |
| 11 |
solution: !Solution |
| 12 |
q: [2, 5, 7, 4, 1, 8, 6, 3] |
| 13 |
- !Result |
| 14 |
solution: !Solution |
| 15 |
q: [2, 6, 1, 7, 4, 8, 3, 5] |
| 16 |
- !Result |
| 17 |
solution: !Solution |
| 18 |
q: [2, 6, 8, 3, 1, 4, 7, 5] |
| 19 |
- !Result |
| 20 |
solution: !Solution |
| 21 |
q: [2, 7, 3, 6, 8, 5, 1, 4] |
| 22 |
- !Result |
| 23 |
solution: !Solution |
| 24 |
q: [2, 7, 5, 8, 1, 4, 6, 3] |
| 25 |
- !Result |
| 26 |
solution: !Solution |
| 27 |
q: [2, 8, 6, 1, 3, 5, 7, 4] |
| 28 |
***/ |
| 29 |
|
| 30 |
% n-queens example in Zinc using CP techniques |
| 31 |
% By Reza Rafeh July 2005 |
| 32 |
% MiniZinc version |
| 33 |
% Peter Stuckey September 30 2006 |
| 34 |
|
| 35 |
int: n = 8; |
| 36 |
|
| 37 |
array [1..n] of var 1..n: q :: add_to_output; |
| 38 |
|
| 39 |
|
| 40 |
constraint |
| 41 |
alldifferent(q) % rows |
| 42 |
/\ |
| 43 |
alldifferent(i in 1..n)(q[i] + i-1) % diagonals |
| 44 |
/\ |
| 45 |
alldifferent(i in 1..n)(q[i] + n-i); |
| 46 |
|
| 47 |
constraint q[1] = 2; |
| 48 |
%constraint q[2] = 1; |
| 49 |
|
| 50 |
include "alldifferent.mzn"; |
| 51 |
|
| 52 |
|
| 53 |
solve :: |
| 54 |
int_search( |
| 55 |
q, |
| 56 |
first_fail, |
| 57 |
indomain_min, |
| 58 |
complete |
| 59 |
) |
| 60 |
satisfy; |