Answered step by step
Verified Expert Solution
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
wherein each pair
in the list specifies that vertex
must be visited in the tour before vertex
Assume that the tour startsends at vertex
and none of the vertices in the constraint list is
I.e
for all
Modify one of the ILP encodings we have presented to solve TSP with extra constraints. Implement your solution in the function tspwithextraconstraintsn costmatrix, constrlist where the extra argument constrlist is a list of pairs ijik jk that specify for each pair iljl 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
nodes and the following cost matrix from problem :
The optimal TSP tour will be
with total cost
Suppose we added the constraints
we note that the tour satisfies the constraint
since it visits vertex
before vertex
but it unfortunately,
is violated since vetex
is visited before
in the tour.def tspwithextraconstraintsn costmatrix, constraints:
assert lencostmatrix n f'Cost matrix is not nxn
assert alllencj n for cj in costmatrix f'Cost matrix is not nxn
assert all i n and j n and i j for ij 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started