You are on page 1of 2

ECE 242 Project 5

Prof. Tilman Wolf and Prof. Lixin Gao Due: Thursday 12/8/11 at 11:30 p.m.

Introduction
In this project assignment, you will implement a program that determines in what order to visit a set of cities so that the overall length of the tour is minimized. Your program will read in the coordinates of 48 cities and determine the distance between each pair of cities. (These cities correspond to the capitals of the 48 states in the contiguous United States.) The output of your program should provide the sequence in which cities are visited and the total length of the tour. (For those who would like to put this project into a festive context, imaging your program is used by Santa Claus to minimize the distance traveled while covering a set of places that need to be visited. In this case, Santa Claus only visits the 48 state capitals.)

Overview
For this project, we use city coordinates based on the ATT48 data set from TSPLIB. The data set provided in cityCoordinates.txt consists of x and y coordinates for 48 cities in a normalized coordinate system. Based on these coordinates, your program should compute the Euclidean distance between any two cities. The result of this computation is a complete distance matrix between all cities. You can view this as a fully connected graph that has an edge between all node pairs. Your program should then nd a tour that traverses all cities. This tour may start at any city, but has to return to that city in its nal step (i.e., the tour is a cycle in the graph that contains all cities). The length of the tour is the sum of all edges in the tour. Your goal is to nd a tour that is as short as possible. The problem of nding the shortest possible tour is a well-known problem that has no computationally ecient solution. Due to the large number of possible tours, it is not feasible to enumerate all possible tours and pick the shortest. Thus, you need to come up with a heuristic that solves this problem. That is, you should aim to nd a valid solution that is good, but not necessarily optimal. Since it is easy to nd a valid solution that is not very good, the grading of this assignment takes into account the quality of the tour reported by your program (see details below). The output of your program should show (1) the distance matrix you have computed and (2) the tour you have found (length and order of cities) in the following format (shown for a 5-city example): Distance matrix: 0 1716 400 1277 1608 1716 0 2115 439 763 400 2115 0 1676 1964 1277 439 1676 0 744 1608 763 1964 744 0 tour (length=4886): 3 1 4 0 2 3

If you develop multiple dierent algorithms to nd a tour, you may print out the results from all of them (one per line). For grading, the result with the shortest length tour will be used.

Details
You may use any approach you like to solve this problem. You may modify any of the code given to you. You must add a brief description of your algorithm as a comment in your code so it is possible to understand what approach you are taking. Your solution must complete computation in a reasonable amount of time (a minute or so on a typical computer). It is important that you keep track of which cities are already part of your tour. You must visit all 48 cities to have a valid tour. You may visit a city more than once in a tour. However, since the graph is fully connected, this is not necessary. You can always skip the second visit to a city and go directly from the previous node to the next. This will lead to a shorted tour based on the triangle inequality. (For example, if you have a tour ..., 7, ..., 15, 7, 40, ..., you could skip the second visit to 7 and go directly between 15 and 40.) As a point of reference, the optimal tour for this problem has a length of 10,628. It is unlikely that any straightforward algorithm can nd a tour that is comparably short. For this assignment, it is sucient to get a reasonable solution. See the grading guidelines below to determine how good your solution is.

How to Start?
Modify the provided code to compute and store the distance matrix. Then, create a tour by choosing a suitable data structure (e.g., linked list) to keep track of the sequence of visited cities. Initially, create any valid tour. Examine the tour (e.g., distance between cities in each step) and think about possible improvements. Rene your algorithm so that you can nd a shorter tour.

Grading
You should submit your complete code in a .zip le on SPARK. This zip le should also contain a le named output.txt that contains the output of your program for one run. You will receive 45 points for your code running correctly, up to 25 points for the quality of solution, and 25 points for the thoroughness and usefulness of the comments included in your code. The breakdown of points is: Program prints out correct distance matrix: 15 Program prints out valid tour: 25 Program prints out correct length of tour: 10 Quality of solution: Tour Tour Tour Tour length length length length of of of of 100,000 or above: 5 points 45,000 to 100,000: 10 points 40,200 to 45,000: 20 points 40,200 or below: 25 points

Note: Solutions that provide dierent results for each run (e.g., due to randomization) will be run three times and the median value of the length will be used for grading. Comment describing your algorithm to nd tour: 10 Comments describing the overall code: 15 Note that all submissions must adhere to the course policies posted on the course web site.

You might also like