Processing math: 100%

Saturday, December 8, 2018

More queens problems

In [1] the famous n-queens problem was discussed: how many queens can we place on a chess-board such that non of them are attacked by others. Interestingly, we had some non-obvious problem with Cplex enumerating the different configurations (due to tolerance issues).

A different problem is the Minimum Dominating Set of Queens Problem:
Find the minimum number of queens needed such that they dominate each square.
Here dominate means: either a square is under attack by at least one queen, or it is occupied by a queen.

To develop a Mixed Integer Programming model, we introduce the familiar binary variables:

xi,j={1if square (i,j) is occupied by a queen0otherwise

A square (i,j) is dominated if:

  1. xi,j=1: a queen is located here. This case will be covered by the following other cases, so we don't have to worry about this.
  2. There is a queen in row i: jxi,j1
  3. There is a queen in column j:ixi,j1
  4. There is a queen in the same diagonal. The diagonal is described by (i,j) such that ij=ij. So we have: i,j|ij=ijxi,j1 If you prefer you can write this as i|1ii+jnxi,ii+j1 
  5. There is a queen in the same anti-diagonal. The anti-diagonal is described by (i,j) such that i+j=i+j. So we have: i,j|i+j=i+jxi,j1 This can also be written as i|1i+jinxi,i+ji1


We can write these conditions in one big constraint. So we can write:

Minimum Dominating Set of Queens Problem
minz=i,jxi,jjxi,j+ixi,j+i,j|ij=ijxi,j+i,j|i+j=i+jxi,j1i,jxi,j{0,1}

For an 8×8 board, we need 5 queens. Here are two solutions:


You can verify that every unoccupied square is under attack.

Note that this formulation actually does a bit of double counting. E.g. when we look at the constraint for cell (2,3) we see:


e(2,3)..  x(1,2) + x(1,3) + x(1,4) + x(2,1) + x(2,2) + 4*x(2,3) + x(2,4)
     
      + x(2,5) + x(2,6) + x(2,7) + x(2,8) + x(3,2) + x(3,3) + x(3,4) + x(4,1)
     
      + x(4,3) + x(4,5) + x(5,3) + x(5,6) + x(6,3) + x(6,7) + x(7,3) + x(7,8)
     
      + x(8,3) =G= 1 ; (LHS = 0, INFES = 1 ****)


We see that x(2,3) has a coefficient 4. This is harmless. However it looks a bit unpolished. With a little bit more careful modeling we can get rid of this coefficient 4. A complicated way would be: jxi,j+i|iixi,j+i,j|ij=ij,ii,jjxi,j+i,j|i+j=i+j,ii,jjxi,j1i,j The first summation includes xi,j while the other three summations exclude explicitly an occurrence of xi,j. Simpler is just to subtract 3xi,j: jxi,j+ixi,j+i,j|ij=ijxi,j+i,j|i+j=i+jxi,j3xi,j1i,j Here we just compensate for the double counting.

Now we see:


e(2,3)..  x(1,2) + x(1,3) + x(1,4) + x(2,1) + x(2,2) + x(2,3) + x(2,4) + x(2,5)
     
      + x(2,6) + x(2,7) + x(2,8) + x(3,2) + x(3,3) + x(3,4) + x(4,1) + x(4,3)
     
      + x(4,5) + x(5,3) + x(5,6) + x(6,3) + x(6,7) + x(7,3) + x(7,8) + x(8,3)

      =G= 1 ; (LHS = 0, INFES = 1 ****)


When we ask: how many different solution are there?, we use again the Cplex solution pool. And again, we have our tolerance problem:


pool.absgapNumber of solutions
02
0.54860

As the objective is integer valued, in some sense an absolute gap tolerance of 0.5 seems the safest. With this we find the correct number of solutions [2]. See [1] for a more in-depth discussion of this tolerance problem.

References


  1. Chess and solution pool, http://yetanothermathprogrammingconsultant.blogspot.com/2018/11/chess-and-solution-pool.html.
  2. Weisstein, Eric W.,  Queens Problem, http://mathworld.wolfram.com/QueensProblem.html
  3. Henning Fernau, minimum dominating set of queens: A trivial programming exercise?, Discrete Applied Mathematics, Volume 158, Issue 4, 28 February 2010, Pages 308-318. This is about programming instead of modeling. The issues are very different.
  4. Saad Alharbi and, Ibrahim Venkat, A Genetic Algorithm Based Approach for Solving the Minimum Dominating Set of Queens Problem, Hindawi Journal of Optimization, Volume 2017. I am not sure why a meta-heuristic is a good choice for solving this problem: you will not find proven optimal solutions. 

1 comment:

  1. I just tried to do the same thing with 9 queens instead of 8 (on a 9x9 board), for which it is known that there are 352 solutions. After setting the pool intensity to 4, the pool capacity to the maximum possible value (2.1e9) , the integrality tolerance to 0, and the absolute gap for the pool to 0.01 I only got 348 solutions (i.e. 4 are missed); however, when I reduce the absolute gap even further, to 0.005, I get all 352 solutions. It seems that the issue is that the CPLEX pool stores all the solutions it encounters, because with a tolerance of 0.01 the status (in CLI) is displayed as "Populate - Populate solution limit exceeded, integer optimal", whereas with a tolerance of 0.005 it is displayed as "Populate - All reachable solutions enumerated, pool tolerance (1e+75/0.005), integer optimal".

    For comparison, when I tried this in Gurobi (with default settings, except the pool size was set to 1000) there didn't seem to be a problem, and it happily listed the 352 solutions with objective value 9 as well as 648 solutions with objective value 8 (if I understand correctly, Gurobi's pool size reflects only the retained solutions, not all enumerated ones).

    ReplyDelete