This is the end queen's problem.
And I suppose we have a N by n chessboard and we want to put some queens on these chessboard without
attacking each other and we want to maximize the number of queens that we put on these chessboard.
OK, so suppose we want to start this problem and for solving that, what we need to use, uh, some
binary variables.
So UIGEA will tell us if, uh, Queen exists on the cell.
I and J.
Iris representing Rose and J is representing column.
OK, and we want to maximize this summation.
OK, so some rules and on each um column.
For every given column.
For every J.
Um, we can't have more than one, uh, queen on the board.
So this is written as follows.
So the summation of over I over the rows and should be less than one.
And also the same kind of, uh, similar constraint is um here uh, for every, um, given row and the
summation of a J or over the columns should give us less than one queen on each row.
OK, this is another rule, just rule.
And the the other rule is the diagonal rules.
So it means that on every diagonal or a. diagonal, we can't have more than one, uh, queen and some
diagonals.
We can have no queen as well.
OK, so we want to solve these, um, optimization problem in a way that these four constraints are
satisfied.
So there's an objective function.
And for every J and these constraints to satisfy every ideas exercise for every I n j if they are diagonal
or diagonal, these constraints should be satisfied.
OK, so let's have a look at, um, Python code developed for this purpose.
Just a second.
Uh, OK, so this is the Python code.
OK, so first of all, I have to import the required packages like PI en masse, partly because at the
end I want to plot the results.
And also and I have to specify what is the dimension of the board.
So I specify this like that, um, I have defined it mutable because, uh, maybe I need to change the
size of the board.
And also I is representing the set of keys, set of Rosary and J is the set of um.
Columns, but since they are they have the same number of cells, then I have defined them as alias
and model dots, you is a variable is a binary variable representing if a queen exists in that cell
or not.
And I have initialized that with one.
OK, and and we have two rules, one for row, one for column.
So the summation of um uh model does you ija for every J in model J should be less than equal to one
on this row is defined over every eye.
OK, for a given I that summation should be valid and the same, um a similar concept is for every column.
So for every column J summation over I should be less than one.
OK, these two rules and the other two rules are representing the um diagonal and uh on the diagonal.
Um.
A set of rules.
OK, so, um, model, uh, C Diag one is here and it is represented over I and J, but not for every
IFJ those I enjoyed that satisfied this specific, um, relation.
OK, and this is Phosphorylation is, uh, representing the the other diagonal of the uh board.
OK, and the objective function is defined as the summation of the UIGEA for every I and J in the model
and the sense is the maximization.
OK, I rondi cell and then I specify the value of.
And how many cells do we have on all.
Chessell On each side of chessboards we can have a bigger chessboards and then try to solve it.
I solve this problem and show you the results so you can see here that, um, these are the locations
of the Queens on the board.
So here we have only one queen on this row, one queen on this column, one queen on the stroll along,
queen on this column on the final and.
Uh, Taib will save that, um, figure as a pound you find in your directory.
OK, so I can test it for a bigger kind of chessboard, let's say 16.
Mm.
OK.
And if I.
Plotted, you can see here that this is the new kind of, um, allocation of the Queen's thank you very
much.