File: queens1.zpl

package info (click to toggle)
zimpl 2.07.ds1-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,416 kB
  • ctags: 2,560
  • sloc: ansic: 18,311; yacc: 882; lex: 326; makefile: 232; sh: 219
file content (24 lines) | stat: -rw-r--r-- 734 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# $Id: queens1.zpl,v 1.3 2003/10/29 19:44:46 bzfkocht Exp $
#
# This is a formulation of the n queens problem using general integer
# variables. Please note that this particular formulation only works,
# if a queen can be placed in each row, so queens should be greater
# equal to 4
#
param queens := 8;

set I := { 1 .. queens };
set P := { <i,j> in I * I with i < j };
 
var x[I] integer >= 1 <= queens;

# All x have to be different 
#
subto c1: forall <i,j> in P do vabs(x[i] - x[j]) >= 1;

# Block diagonals => 
# never the same distance between two queens in x and y direction =>
# abs(x[i] - x[j]) != abs(i - j) =>
# a != b modeled as abs(a - b) >= 1
#
subto c2: forall <i,j> in P do vabs(vabs(x[i] - x[j]) - abs(i - j)) >= 1;