File: queens3.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 (21 lines) | stat: -rw-r--r-- 615 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
# $Id: queens3.zpl,v 1.1 2004/11/13 17:28:06 bzfkocht Exp $
#
# This is a formulation of the n queens problem using binary variables.
# variables. Since the number of queens is maximized, the size of the
# board can be set arbitrarily.
#
param columns := 8;

set I   := { 1 .. columns };
set IxI := I * I;

set TABU[<i,j> in IxI] := { <m,n> in IxI with 
   (m != i or n != j) and (m == i or n == j or abs(m - i) == abs(n - j)) };

var x[IxI] binary;

maximize queens: sum <i,j> in IxI : x[i,j];

subto c1: forall <i,j> in IxI do
   card(TABU[i,j]) - card(TABU[i,j]) * x[i,j] >= sum <m,n> in TABU[i,j] : x[m,n];