Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem, we wish to solve TSP with additional constraints. Suppose we are given a TSP instance in the form of a times

In this problem, we wish to solve TSP with additional constraints. Suppose we are given a TSP instance in the form of a \times
matrix
representing a complete graph.
We wish to solve a TSP but with additional constraints specified as a list [(0,0),...,(,)]
wherein each pair (,)
in the list specifies that vertex
must be visited in the tour before vertex
. Assume that the tour starts/ends at vertex 0
and none of the vertices in the constraint list is 0
. I.e,!=0,!=0
for all 0<=<=
.
Modify one of the ILP encodings we have presented to solve TSP with extra constraints. Implement your solution in the function tsp_with_extra_constraints(n, cost_matrix, constr_list) where the extra argument constr_list is a list of pairs [(i0,j0),....,(ik, jk)] that specify for each pair (il,jl) that vertex il must be visited before jl. Assume that the problem is feasible (no need to handle infeasible instances). Your code should output the optimal tour as a list.
Example
Consider again the graph with 5
nodes and the following cost matrix from problem 1:
The optimal TSP tour will be [0,3,1,4,2]
with total cost 10
.
Suppose we added the constraints [(4,3),(1,2)]
we note that the tour satisfies the constraint (1,2)
since it visits vertex 1
before vertex 2
but it unfortunately, (4,3)
is violated since vetex 3
is visited before 4
in the tour.def tsp_with_extra_constraints(n, cost_matrix, constraints):
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}'
assert all(1<= i < n and 1<= j < n and i != j for (i,j) in constraints)
# TODO: encode the problem in pulp (a) decision variables; (b) constraints; (c) objective; (d) solve and extract
# solution. This is going to be very close to the MTZ encoding that we have presented in our notes. You can use
# our code as a starting point.
# 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 Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions