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 non-attacking 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
1 if a knight is placed at location (i,j), xij =0 otherwise.
The integer linear programming formulation of this problem becomes
NM maximize z = xij
i=1 j=1
subject to: xij + xkl <=1(i, j, k, l) where (i, j) and (k, l) are attacking locations
xij in {0,1} i =1,2,...,M; j =1,2,...,N.
An example of the non-attacking knights problem with a 2\times 6 chessboard can be given as
maximize subject to:
z=x11+x12+x13+x14+x15+x16+x21+x22+x23+x24+x25+x26 x11+x23<=1
x12+ x24<=1
x13+ x25<=1
x13+ x21<=1 x14+ x26<=1 x14+ x22<=1 x15+ x23<=1 x16+ x24<=1 x11 in {0,1} x21 in {0,1}
x12 in {0,1} x22 in {0,1}
x13 in {0,1} x23 in {0,1}
x14 in {0,1} x24 in {0,1}
x15 in {0,1} x25 in {0,1}
x16 in {0,1} x26 in {0,1}.
An optimum solution of the example problem with a 2\times 6 chessboard is as follows: x11=1 x12=1 x13=0 x14=0 x15=1 x16=1
x21=1 x22=1 x23=0 x24=0 x25=1 x26=1
An example of the non-attacking knights problem with a 3\times 3 chessboard can be given as
maximize z=x11+x12+x13+x21+x22+x23+x31+x32+x33 subject to: x11+ x32<=1
NM0ZNM
MNZ0MN
1
x11=0 x21=1 x31=0
x12=1 x22=1 x32=1
x13=0 x23=1 x33=0
x11+ x23<=1 x12+ x33<=1 x12+ x31<=1 x13+ x32<=1 x13+ x21<=1 x21+ x33<=1 x23+ x31<=1 x11 in {0,1} x21 in {0,1} x31 in {0,1}
x12 in {0,1} x22 in {0,1} x32 in {0,1}
x13 in {0,1} x23 in {0,1} x33 in {0,1}.
An optimum solution of the example problem with a 3\times 3 chessboard is as follows:
ZNZ NMN ZNZ
Implement your algorithm to solve the non-attacking 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 nonattacking_knights_problem(M, N):
#implement your algorithm here
return(X_star, obj_star)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related General Management Questions!