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:
- 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.
- There is a queen in row i: ∑j′xi,j′≥1
- There is a queen in column j:∑i′xi′,j≥1
- There is a queen in the same diagonal. The diagonal is described by (i′,j′) such that i′−j′=i−j. So we have: ∑i′,j′|i′−j′=i−jxi′,j′≥1 If you prefer you can write this as ∑i′|1≤i′−i+j≤nxi′,i′−i+j≥1
- 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′,j′≥1 This can also be written as ∑i′|1≤i+j−i′≤nxi′,i+j−i′≥1
We can write these conditions in one big constraint. So we can write:
Minimum Dominating Set of Queens Problem |
---|
minz=∑i,jxi,j∑j′xi,j′+∑i′xi′,j+∑i′,j′|i′−j′=i−jxi′,j′+∑i′,j′|i′+j′=i+jxi′,j′≥1∀i,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: ∑j′xi,j′+∑i′|i′≠ixi′,j+∑i′,j′|i′−j′=i−j,i′≠i,j′≠jxi′,j′+∑i′,j′|i′+j′=i+j,i′≠i,j′≠jxi′,j′≥1∀i,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: ∑j′xi,j′+∑i′xi′,j+∑i′,j′|i′−j′=i−jxi′,j′+∑i′,j′|i′+j′=i+jxi′,j′−3xi,j≥1∀i,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.absgap | Number of solutions |
---|---|
0 | 2 |
0.5 | 4860 |
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
- Chess and solution pool, http://yetanothermathprogrammingconsultant.blogspot.com/2018/11/chess-and-solution-pool.html.
- Weisstein, Eric W., Queens Problem, http://mathworld.wolfram.com/QueensProblem.html
- 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.
- 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.
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".
ReplyDeleteFor 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).