Question: Complete the implementation of the function k _ tsp _ mtz _ encoding ( n , k , cost _ matrix ) below using PULP.
Complete the implementation of the function k
tsp
mtz
encoding
n
k
cost
matrix
below using PULP. It follows the same input convention as the code supplied in the notes. The input n denotes the size of the graph with vertices labeled
n
k is the number of salespeople, and cost
matrix is a list of lists wherein cost
matrix
i
j
is the edge cost to go from i to j for i
j
Your code must avoid accessing cost
matrix
i
i
to avoid bugs. These entries will be supplied as None in the test cases.
Your code must return a list lst that has exactly k
lists in it
wherein lst
j
represents the locations visited by the jth
salesperson.
For the example above, for k
your code must return
For the example above, for k
your code must return
from pulp import
def k
tsp
mtz
encoding
n
k
cost
matrix
:
# check inputs are OK
assert
k
n
assert len
cost
matrix
n
fCost matrix is not
n
x
n
assert all
len
cj
n for cj in cost
matrix
fCost matrix is not
n
x
n
prob
LpProblem
kTSP
LpMinimize
# finish your implementation here
# your code must return a list of k
lists
i
il
j
jl
wherein
# the ith entry in our list of lists represents the
# tour undertaken by the ith salesperson
# your code here
raise NotImplementedError
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
