Chess is one of the oldest and most celebrated board games in history, with origins dating back over a thousand years. Traditionally played on an $8 \times 8$ board, chess involves strategy, tactics, and deep thinking, as each piece moves according to specific rules. Beyond the game itself, the chessboard and its pieces have inspired a variety of logic puzzles and mathematical challenges.
One of the most famous of these is the eight queens problem, which asks how to place eight queens on a standard chessboard so that no two queens threaten each other—meaning that no two queens share the same row, column, or diagonal. This puzzle has fascinated mathematicians and enthusiasts alike, as it combines combinatorial reasoning with spatial visualization.
The problem can also be generalized to place the maximum number of queens on a board of different dimensions, $m \times n$, creating a family of logic challenges with increasing complexity.
Do you dare to solve it logically for a standard chessboard $8 \times 8$ before taking on the model?
Solution to the challenge
For the eight queens problem on a standard chessboard, one solution is presented below. For this case, there are a total of 92 distinct solutions, making this a rich and engaging puzzle for anyone interested in logic, mathematics, and chess.
This problem can be formulated as a binary optimization model. Do you dare to try it?
To model this problem as a binary linear optimization problem, we need to first define all the components of the model.
Sets of indices
\(\mathcal{R}\): Rows of the board.
\(\mathcal{C}\): Columns of the board.
Parameters
There are no additional parameters, since the board is initially considered empty.
Decision variables
\(x_{rc} = 1\) if there is a queen located at coordinate $(r,c)$ of the board, and 0 otherwise, $\forall r \in \mathcal{R}, \; \forall c \in \mathcal{C}$.
The objective is to place the maximum number of queens on the chessboard.
Martín-Campo, F. Javier (2025). How to model the n-queens problem using binary linear optimization. https://www.fjmartincampo.com/blog/2025/queens/
As a BibTeX entry:
@misc{martín-campo2025how-to-model-the-n-queens-problem-using-binary-linear-optimization,title={How to model the n-queens problem using binary linear optimization},author={Martín-Campo, F. Javier},year={2025},month={dec},url={https://www.fjmartincampo.com/blog/2025/queens/}}