In this homework, you will implement a Python script that solves the
quadratic assignment problem using CPLEX. The quadratic assignment prob-
lem is an integer problem defined as follows: as with the assignment problem,
we consider the problem as related to two sets of objects S and T. S and
T both have the same number of members, which are indexed from 1 to N.
The problem is to assign each member of S to exactly one member of T to
achieve some objective. There are two sorts of conditions we must fulfill:
each member of S must be assigned to exactly one member of T, and
each member of T must have exactly one member of S assigned to it.
Binary variables x_(ij) can be introduced with the following interpretations:
x_(ij)={(1 if i( a member of S) is assigned to j( a member of T),),(0 otherwise. ):}
Conditions are imposed by the following two types of constraints:
sum_(j=1)^N x_(ij)=1,i=1,dots,N,
sum_(i=1)^N x_(ij)=1,j=1,dots,N.
The objective is more complex than with the assignment problem. We have
cost coefficients c_(ijkl), which have the following interpretations. c_(ijkl) is the
cost incurred by assigning i (a member of S ) to j (a member of T ) at the
same time as assigning k (a member of S ) to l (a member of T ). This cost
will clearly be incurred only if x_(ij)=1 and x_(kl)=1, that is, if the product
x_(ij)x_(kl)=1. The objective becomes a quadratic expression in binary variables:
minimizez=sum_(i=1)^N sum_(j=1)^N sum_(k=1)^N sum_(l=1)^N c_(ijkl)x_(ij)x_(kl)It is very common for the coefficients c_(ijkl) to be derived from the product of
other coefficients t_(ik) and d_(jl) so that c_(ijkl)=t_(ik)d_(jl).
Firstly, we consider S to be a set of N factories and T to be a set of N
cities. The problem is to locate one factory in each city and to minimize total
communication costs between factories. The communication costs depend on
(i) the frequency of communication between each pair of factories, and (ii)
the distances between the two cities where each pair of factories is located.
Clearly, some factories will have little to do with each other and can be
located far apart at little cost. On the other hand, some factories may
need to communicate a lot. The cost of communication will depend on the
distance apart. In this application, we can interpret the coefficients t_(ik) and
d_(jl) as follows: t_(ik) is the frequency of communication between factories i and
k;d_(jl) is the cost per unit of communication between cities j and l (clearly,
this will be related to the distance between j and l ). Obviously, the cost
of communication between the factories i and k, located in cities j and l,
will be given by c_(ijkl)=t_(ik)d_(jl). The total cost is therefore represented by the
objective function.
This problem will be represented using two .txt files, namely, frequencies . txt
and distances.txt. The first file contains the frequencies (i.e., t_(ik) ) in N
lines with N values. It contains the following lines for an example problem:
frequencies.txt
25,63,34,52
63,39,21,57
34,21,10,66
525766,63
The second file contains the distances (i.e., d_(jl) ) in N lines with N values.
It contains th
It is very common for the coefficients ci to be derived from the product of other coefficients ti and dj so that ci = tid. Firstly, we consider S to be a set of N factories and T to be a set of N cities. The problem is to locate one factory in each city and to minimize total communication costs between factories. The communication costs depend on i the frequency of communication between each pair of factories, and (ii the distances between the two cities where each pair of factories is located Clearly, some factories will have little to do with each other and can be located far apart at little cost. On the other hand, some factories may need to communicate a lot. The cost of communication will depend on the distance apart. In this application, we can interpret the coefficients ti and dj as follows: ti is the frequency of communication between factories i and k; d, is the cost per unit of communication between cities j and I (clearly this will be related to the distance between j and l). Obviously, the cost of communication between the factories i and k, located in cities j and l will be given by cij = tidjr. The total cost is therefore represented by the objective function.
This problem will be represented using two .txt files, namely, frequencies .txt and distances.txt. The first file contains the frequencies (i.e., ti) in N lines with N values. It contains the following lines for an example problem: frequencies.txt
2563 3452 63 39 21 57 34 21 10 66 5257 66 63
The second file contains the distances i.e., d in N lines with N values. It contains the following lines for an example problem: distances.txt
44 26 68 66 26 52 51 62 68 51 96 60 66 62 60 83
The optimum solution of the example problem is as follows:
x=0 x=1 x=0 x=0
=0 =0 x3=0 x2=1
x=0 x=0 x3=1 43=0
x4=1 x4=0 x=0 4=0.
Implement your algorithm to solve the quadratic assignment problem in a single interactive Python notebook using Azure Lab Services. Your notebook should include at least the following function definition that takes the file paths of two input files as parameters and returns the solution found.
def quadratic_assignment_problem(frequencies_file, distances_file): # your implementation starts below
# your implementation ends above return(x_star)