How to model the n-queens problem using linear programming

Image by Arturo Añez from Unsplash

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?


This problem can be formulated as a binary optimization model. Do you dare to try it?


Would you like to keep exploring the world of Operations Research? Discover more posts on the topic here.




If you found this useful, please cite this as:

Martín-Campo, F. Javier (Dec 2025). How to model the n-queens problem using linear programming. https://www.fjmartincampo.com/blog/2025/queens/.

or as a BibTeX entry:

@misc{martín-campo2025how-to-model-the-n-queens-problem-using-linear-programming,
  title   = {How to model the n-queens problem using linear programming},
  author  = {Martín-Campo, F. Javier},
  year    = {2025},
  month   = {Dec},
  url     = {https://www.fjmartincampo.com/blog/2025/queens/}
}



Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • A crime has been committed... in a sudoku!
  • The harmony of digits in solving Kakuro
  • Killer Sudoku, the empty board challenge that math can solve
  • Solving the Number Sums board using mathematical optimization
  • Building bridges with linear optimization, the Hashi puzzle