Processing math: 100%
Download

A possible encoding as a maxCSP:

variables:

a variable Vi for each number i in {1,,n2} and a variable Q for the queen.

domains:

the domains of all these variables are the possible cells on the n x n chessboard.

hard constraints:

an alldiff constraint on the n2 Vi variables. for each pair Vi,Vi+1 of variables, a binary constraint allowing only the pairs of cells being the start and end of a knight move.

soft constraints:

for each prime p, a binary constraint involving Q and Vp, allowing only the pairs of cells being the start and end of a queen move.

goal:

minimize the number of soft constraints violated.