0% found this document useful (0 votes)
196 views

U08282 - Algorithm and Advance Data Structure

The document discusses solving the traveling salesman problem using different methods. It describes the history and development of the problem and categorizes it into three types: Euclidean symmetric, asymmetric, and random distance matrix problems. It then explains two approaches to solving the problem - tour construction methods like nearest neighbor and greedy algorithms, and local search heuristics. The body of the document focuses on minimum spanning tree based heuristics and nearest neighbor heuristics to solve the traveling salesman problem.

Uploaded by

italiandude604
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
196 views

U08282 - Algorithm and Advance Data Structure

The document discusses solving the traveling salesman problem using different methods. It describes the history and development of the problem and categorizes it into three types: Euclidean symmetric, asymmetric, and random distance matrix problems. It then explains two approaches to solving the problem - tour construction methods like nearest neighbor and greedy algorithms, and local search heuristics. The body of the document focuses on minimum spanning tree based heuristics and nearest neighbor heuristics to solve the traveling salesman problem.

Uploaded by

italiandude604
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 16

B O KS R O E

U IV R IT N E S Y

OF R XO D

BACHELOR OF SCIENCE Honours Computer and Information System

COURSEWORK SUBMISSION FORM


Instructions 1. Please complete the form using Capital Letters. 2. Coursework must be submitted through the Service counter and it is the responsibility of the student to complete the Coursework Submission Log Book. Name of Student: E-mail Address: Name of Lecturer: Student ID: Subject Code: U08282 Algorithms and Advanced Data Structures Dr Namasivayam Krishnamoorthy Class Code: Assignment U08282 T3 2012 Contact No:

No. of pages including this cover page :

Other Specifications:

Enclosed CD: Yes Attached turnitin.com Report: Yes

Submission Date: Due Date: Declaration : Signature : I declare that this assignment is my original work and that I have acknowledged any use of published or unpublished works of other people. I understand that I will be penalized for plagiarism and late submission.

Question Marker Internal Moderator External Moderator Marker's Comment:

Total

T312 U08282 CW QPMS

Page 1 of 16

OXFORD BROOKES UNIVERSITY BACHELOR OF SCIENCE (HONOURS) U08282 ALGORITHMS AND ADVANCED DATA STRUCTURES
TERM 3, 2012

T312 U08282 CW QPMS

Page 2 of 16

Table of Contents
EnclosedCD:Yes ........................................................................................................................................... 1 Attachedturnitin.comReport:Yes ............................................................................................................. 1 TableofContents .................................................................................................................................................... 3 Introduction ............................................................................................................................................................. 4 HistoryandDevelopment ..................................................................................................................................... 4 SolvingMethods ..................................................................................................................................................... 6 MinimumSpanningTreeBasedHeuristics ........................................................................................................ 7 NearestNeighbourHeuristic .............................................................................................................................. 12 Comparison ........................................................................................................................................................... 13 Conclusion ............................................................................................................................................................. 15 Appendix ............................................................................................................................................................... 16

T312 U08282 CW QPMS

Page 3 of 16

Introduction
Traveling Salesman Problem is a mathematical point of view of the following problem taken from the everyday life. The purpose of Traveling Salesman Problem is a traveling salesman has to visit exactly once each one of a list of n cities and then return to the home city. In this case, salesman known the cost of traveling from current city to another city but he doesnt know total cost of tour. Thus Traveling Salesman Problem was born to solve the problem.

History and Development


The origins of the traveling salesman problem are unclear. The travelling salesman problem was defined in the nineteen century by the Irish mathematician William Rowan Hamilton and by the British mathematician Thomas Kirkman. The general case of TSP has been researched by mathematicians during in the nineteenthirty, especially is Karl Menger who defines the problem, consider and find out nearest neighbor algorithm is not optimal. During nineteen-fifty and nineteen-sixty, the problem become popular in the world of scientific research at Europe and United States. In nineteen-seventy-two, Richard M. Karp had proved that Hamiltonian Cycle problem was NP-complete which implies the NP-hardness of TSP. Follow the development of scientific world, the TSP has been solved in many ways until now. Traveling Salesman Problem can be modelled as an undirected weight graph include cities are the graphs vertices, paths are the graph edges and path distance is the edge length. The problem can be imagine as salesman begin from a random city, delivery a packet through another city and go back the first city. In this case, each city can only visit once at each time and the distance has been known. The problem is he need to find out a shortest route that satisfied all conditions.
INCLUDEPICTURE "http://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Weighted_K4.svg/180px

Weighted_K4.svg.png"

\*

MERGEFORMATINET

INCLUDEPICTURE INCLUDEPICTURE INCLUDEPICTURE


Page 4 of 16

"http://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Weighted_K4.svg/180pxWeighted_K4.svg.png" Weighted_K4.svg.png"
T312 U08282 CW QPMS

\* \*

MERGEFORMATINET MERGEFORMATINET

"http://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Weighted_K4.svg/180px-

"http://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Weighted_K4.svg/180pxWeighted_K4.svg.png" \* MERGEFORMATINET INCLUDEPICTURE "http://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Weighted_K4.svg/180px-

Weighted_K4.svg.png" \* MERGEFORMATINET

According to the research on the TSP we have categorizes the problems of TSP into three types: a) Euclidian Symmetric In this term, we can calculate the distance between two points. But the problem is the distance in both direction is equal such as distance from city A to city B is equal city B to city A. In other words, symmetric Euclidian problem is undirected graphs. b) Asymmetric Opposite with Euclidian symmetric, asymmetric problem has been defined as the distance is not equal from City A to City B and City B to City A. Asymmetric problem can be imagined as directed graphs c) Random distance matrixes This problem is unable calculate the distance and it called Random distance matrix problems.

T312 U08282 CW QPMS

Page 5 of 16

Solving Methods
Follow the research on the TSP, we learnt that there are many ways to solve TSP problem. Under my studying, I will make some explanation about two different methods way to solve TSP problem in the categories below. And I will discuss some methods that related to each category 1) Tour Construction Method This is a simple method that can create tour by using an unordered collection of city from TSP. Although it can create the tour but it does not improve the quality of tour. More than that, this method also depend on which construction heuristic using. There are few construction that will be categorized below: Nearest Neighbor: in this construction heuristic, the salesman starts at a city and then visits the city nearest to the starting city. After that, the salesman will be continued to visit the nearest city that was not visited until the salesman visited all cities and returned back to the starting point city Greedy: this construction heuristic is a simple construction by growing Hamiltonian cycle in the graph with one time visited only. Firstly, the algorithm will pick the shortest edge and then add this shortest edge to the tour until all the cities are included in the tour. 2) Local Search Heuristics A local search method will accept the tour of some construction heuristic as an input and using some heuristic algorithm to make a change in the tour such as produce a tour shorter the previous one. In case if it does not found any improvement, it will try to obtain a new modification of solution Depend on my topic, I will need to explain the Traveling Salesman Problem in two ways of solving the problem include: Minimum Spanning Tree Based Heuristic

T312 U08282 CW QPMS

Page 6 of 16

Nearest Neighbour Heuristic

Minimum Spanning Tree Based Heuristics


1) Definition At first, I will explain what is spanning tree. A spanning tree is a sub-graph of a given undirected and connected graph. This spanning tree will connect all the vertices together. A single graph can have many different spanning trees and these spanning trees will contain every vertex of graph.

And among all the spanning trees of a weighted and connected graph, the spanning tree with the least total weight is called Minimum Spanning Tree. Below is an example of minimum spanning tree:

T312 U08282 CW QPMS

Page 7 of 16

The first algorithm had been found in nineteen-twenty-six by a Czech scientist named Otakar Boruvka and his name had been named for the algorithm. But now, there are two common algorithms that usually used are Prims Algorithm This is a minimum spanning tree has been grown from the current spanning tree by adding the nearest vertex and the edge connecting the nearest vertex to the minimum spanning tree Kruskals Algorithm This minimum spanning tree grown from a forest of spanning tree by adding the smallest edge connecting two spanning tree In my opinion, I will use Prims Algorithm as the solution for my Traveling Salesman Problem. Because Kruskals Algorithm allows to join both new vertex to new vertex and old vertex to old vertex to get connected, so Kruskals Algorithm has a larger complexity than Prims Algorithm 2) Prims Algorithm At first, a point will be choose randomly as a vertex for the tree and I will name it P1 as the assignment requirement. P1 will have the coordinate as x1 and y1 and the limitation of x1 and y1 between from 0 to 999. The S set will contain all the points as the roots of the Spanning Tree. As because the P1 has been attached to the tree so the S in this explanation will contain all the rest of points as the rest of cities. The formula will be as the salesman will visit all the cities and return back to starting point P1

T312 U08282 CW QPMS

Page 8 of 16

In every execution, a new point will be attached to the tree without numbering order. When a new point attached to graph tree, it will be deleted from set S until all the points attach to the graph. In other meaning, the salesman must visit all the cities. After all the cities has been visited and salesman returns back to the starting point, the algorithm will stop and output the minimum spanning tree.

3) Implementation and Statistic To implement the algorithm, we will construct files such as Cities and Travel to collect information of cities. In this Cities.java, it include coordinates of cities

T312 U08282 CW QPMS

Page 9 of 16

Next is Travel.java, this is also a graph for cities information. This file also include the distance between each cities. The picture below will explain this more clearly

After prepare necessary file, I will begin to exploit the algorithm. At first, I will pick up a random number as a root tree by using the code in the picture below:

T312 U08282 CW QPMS

Page 10 of 16

Next, I will insert the math formula to show the coordinates and distance of the tour into the code by using the code below:

At last, the algorithm need to repeat ten times to finish the experiment

Statistics of the experiment with one-hundred cities:

T312 U08282 CW QPMS

Page 11 of 16

Nearest Neighbour Heuristic


1) Definition This algorithm also called Greedy Algorithm was the first algorithm has been used to solve Traveling Salesman Problem. In this algorithm, the salesman will start at a random city and keep visiting to the nearest cities until all cities have been visited. And at last, the salesman returns back to the start. This nearest neighbor algorithm is easy to implement and have quickly executive, but it can miss shorter routes sometimes. This algorithm might be find a short tour in faster way but it is not the optimal way 2) Nearest Neighbour Algorithm The next is the nearest neighbor algorithms. Most of the step, the nearest neighbor nearly have same formula with Minimum Spanning Tree but the nearest neighbor will find the nearest point with the current point and keep connect until all the points visited. I will list the steps for better viewing about the algorithm: Pick up a random city as the starting city Next, the salesman will visit the nearest city with the current point Besides that, the graph will delete the first point to the list and update new city as current city for looping the action At last, the salesman will back to the first starting point when he visit all the cities in list 3) Implementation and Statistics

T312 U08282 CW QPMS

Page 12 of 16

Most of the step the nearest algorithm is as same as minimum spanning tree algorithm but there is only one step is different from minimum spanning tree

Statistic of the experiment with one-hundred cities:

Comparison
In this section, I will compare between two algorithms in different number of cities. The comparison will follow include: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 cities. Each of the comparison will repeat ten times and show the average length of tour and average execution time for statistics The comparison will be shown in the table below: Cities No N = 100 average length of tour : 9465 average execution time : 48ms N = 200 average length of tour : 12508 average length of tour : 16798 average length of tour : 11739 average execution time : 46ms Minimum Spanning Tree average execution time : 18ms Nearest Neighbor Heuristic average execution time : 18ms

T312 U08282 CW QPMS

Page 13 of 16

average execution time : 65ms N = 300 average length of tour : 15188 average execution time : 114ms N = 400 average length of tour : 17567 average execution time : 173ms N = 500 average length of tour : 19207 average execution time : 252ms N = 600 average length of tour : 20741 average execution time : 372ms N = 700 average length of tour : 22382 average execution time : 516ms N = 800 average length of tour : 23813 average execution time : 723ms N = 900 average length of tour : 25642 average execution time : 957ms N = 1000 average length of tour : 26747

average execution time : 56ms average length of tour : 20700 average execution time : 81ms average length of tour : 23072 average execution time : 104ms average length of tour : 26031 average execution time : 111ms average length of tour : 28257 average execution time : 121ms average length of tour : 30609 average execution time : 133ms average length of tour : 32922 average execution time : 151ms average length of tour : 34313 average execution time : 166ms average length of tour : 36252

As the comparison has shown that nearest neighbor heuristic had the execution time lower compare with minimum spanning tree because the algorithm is not more complex than minimum spanning tree. And we can see that spanning tree with higher execution time but it had found the shorter route compare with nearest neighbor heuristic. Minimum spanning tree had satisfied the condition of traveling salesman problem so this algorithm will be a better solution for salesman traveling problem.

T312 U08282 CW QPMS

Page 14 of 16

Conclusion
Through this assignment and especially the traveling salesman problem, I have learnt more knowledge about Algorithms. More than that, I have more experience about using Java Language. In this assignment, although these two algorithms are common algorithms using on the world but after a lot of works and comparison I had found out that the Prims Algorithm or Minimum Spanning Tree Algorithm is powerful than Nearest Neighbor Algorithm. That algorithm can give the shortest path for salesman that business can save more time and cost for delivery on different places.

T312 U08282 CW QPMS

Page 15 of 16

Appendix

http://en.wikipedia.org/wiki/Nearest_neighbour_algorithm http://en.wikipedia.org/wiki/Travelling_salesman_problem http://en.wikipedia.org/wiki/Minimum_spanning_tree http://algs4.cs.princeton.edu/43mst/ http://www.people.vcu.edu/~gasmerom/MAT131/mst.html http://www.javamex.com/tutorials/random_numbers/#.UNM2u29vMww http://www.java2s.com/Tutorial/Java/CatalogJava.htm http://www.baseball-reference.com/travel/class/nearest.html http://en.wikipedia.org/wiki/Prim's_algorithm http://students.ceid.upatras.gr/~papagel/project/prim.htm http://weierstrass.is.tokushima-u.ac.jp/ikeda/suuri/dijkstra/Prim.shtml http://www.cprogramming.com/tutorial/computersciencetheory/mst.html http://lcm.csa.iisc.ernet.in/dsa/node183.html http://www.brpreiss.com/books/opus4/html/page577.html http://profesores.elo.utfsm.cl/~agv/elo320/animation/prim/prim_kruskal.html http://math.wikia.com/wiki/Proof_of_Prim's_algorithm

T312 U08282 CW QPMS

Page 16 of 16

You might also like