Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please give a PYTHON code for a-c NOT a different language Consider the travelling salesman problem, as described in class. For parts a)-c), write code

image text in transcribed

Please give a PYTHON code for a-c NOT a different language

Consider the travelling salesman problem, as described in class. For parts a)-c), write code to generate 100 random TSP instances involving 7 cities, where cities lie at points in the 2D plane ([0.0,1.0], [0.0,1.0]), sampled uniformly at random. Your code should be correct but will not be marked for style. Use Euclidean distance as your distance measure between cities. a) Solve each TSP exactly by brute-force search over all possible tours. Record and save these costs. In your report, simply state where in your code this is implemented, and state the mean, min, max, and standard deviation of the optimal tour lengths across the 100 instances. b) As a baseline, generate a random tour for each of the 100 instances. What is the mean, min, max, and standard deviation of the tour lengths found? Report the number of instances for which the random tour happens to be the optimal solution (may be zero). c) Implement and apply hill climbing greedy local search using the 2-change neighbourhood function described in class on the 100 instances, using the randomly sampled start state from part b). What is the mean, min, max, and standard deviation of the tour lengths found? Also report the number of instances for which the algorithm found the optimal solution. d) Scale up your experiments! Repeat parts b) and c) using 100 random TSP instances involving 100 cities. Since the number of possible tours is factorial with respect to the number of cities, it may no longer be feasible to compute the costs of the optimal solutions in a reasonable amount of time, so simply omit that part of the table. (If you have extra time, you can find libraries to help you plot and visualize the solutions found by your algorithms, but this is not necessary for the submission.) o Implementation tips: Represent a tour as an array of cities, which are (x,y) coordinates Some useful methods you should write should implement: Computing the cost of a tour Computing the cost between two cities Generating the neighbours of a state Generating a TSP instance If you're using Python, the following modules may be useful: random, itertools (in particular itertools.permutations), statistics O O O

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

How To Make A Database In Historical Studies

Authors: Tiago Luis Gil

1st Edition

3030782409, 978-3030782405

More Books

Students also viewed these Databases questions