Question: In this homework, you will implement a Python script that solves the non - attacking knights problem using CPLEX. The task is to find the
In this homework, you will implement a Python script that solves the nonattacking knights problem using CPLEX. The task is to find the maximum number of knights that can be placed on an M times N chessboard such that no knight attack some other knight. The decision variables can be formulated as
if a knight is placed at location ij xij otherwise.
The integer linear programming formulation of this problem becomes
NM maximize z xij
i j
subject to: xij xkl i j k l where i j and k l are attacking locations
xij in i M; j N
An example of the nonattacking knights problem with a times chessboard can be given as
maximize subject to:
zxxxxxxxxxxxx xx
x x
x x
x x x x x x x x x x x in x in
x in x in
x in x in
x in x in
x in x in
x in x in
An optimum solution of the example problem with a times chessboard is as follows: x x x x x x
x x x x x x
An example of the nonattacking knights problem with a times chessboard can be given as
maximize zxxxxxxxxx subject to: x x
NMZNM
MNZMN
x x x
x x x
x x x
x x x x x x x x x x x x x x x in x in x in
x in x in x in
x in x in x in
An optimum solution of the example problem with a times chessboard is as follows:
ZNZ NMN ZNZ
Implement your algorithm to solve the nonattacking knights problem in a single interactive Python notebook using Azure Lab Services. Your notebook should include at least the following function definition that takes the number of rows and columns as parameters and returns the solution found.
def nonattackingknightsproblemM N:
#implement your algorithm here
returnXstar, objstar
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
