Log in

WORHP Kata of July 2023: Queens puzzle ⌚ 2023-07-01

A kata (in the context of programming) is a small training unit to practise coding. In this series of WORHP Katas we present standard problems of optimization which you can use to get familiar with optimization (and our optimization software WORHP).

Kata: The queens puzzle is the problem of placing queens on an chessboard.
As an NLP, this could be formulated as follows:
  1. The optimization variables are the entries of a matrix , where for
    1. means, there is a queen on position on the checkboard, and
    2. means, there is no queen on that position.
  2. The first set of constraints has to make sure, that in each column and in each row
    1. the sum of the entries is 1,
    2. (at least) one of the entries is 1.
  3. The second set of constraints has to make sure, that in each diagonal and subdiagonal
    1. the sum of the entries is not larger than 1.
    Of course we need a differentiable formulation of the constraints.
Formulate the queens puzzle as an NLP and solve it for , (and with a non-trivial initial guess) for , and .

A solution will be provided with the next WORHP Kata.


Solution of last WORHP Kata: The common approximations of the partial derivatives simplify on the given grid with spacing 1:
The discretized optimization problem is now with the data points :
For we found this solution: