Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 0,.., n-1, 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=2
, your code must return
[[0,2,1,4],[0,3]]
For the example above, for k=3
, your code must return
[[0,1,4],[0,2],[0,3]]from pulp import *
def k_tsp_mtz_encoding(n, k, cost_matrix):
# check inputs are OK
assert 1<= k < n
assert len(cost_matrix)== n, f'Cost matrix is not {n}x{n}'
assert all(len(cj)== n for cj in cost_matrix), f'Cost matrix is not {n}x{n}'
prob = LpProblem('kTSP', LpMinimize)
# finish your implementation here
# your code must return a list of k-lists [[0, i1,..., il],[0, j1,...,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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

int diameter = 9 ; double radius = diameter / 2 ;

Answered: 1 week ago

Question

What other visualizations might you use to explore sales revenue?

Answered: 1 week ago

Question

How many customers reside in Texas?

Answered: 1 week ago