06 Traveling-Salesman-Problem-Malabago

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Keziah C.

Malabago

Traveling Salesman Problem (TSP)

I. Introduction:

The Traveling Salesman Problem or the TSP is a representative of a large class of


problems known as combinatorial optimization problems. In the ordinary form of the TSP, a map
of cities is given to the salesman and he has to visit all the cities only once to complete a tour
such that the length of the tour is the shortest among all possible tours for this map. The data
consist of weights assigned to the edges of a finite complete graph, and the objective is to find a
Hamiltonian cycle, a cycle passing through all the vertices, of the graph while having the
minimum total weight. In the TSP context, Hamiltonian cycles are commonly called tours. For
example, given the map shown in the figure, the lowest cost route would be the one written (A,
B, C, E, D, A), with the cost 31.

II. Kinds of TSP:

1. Symmetric TSP (STSP) - there is only one way between two adjacent
cities, i.e., the distance between cities A and B is equal to the
distance between cities B and A (refer to the figure above)

2. Asymmetric TSP (ATSP)- there is not such symmetry and it is possible to have two different
costs or distances between two cities.
III. Methods of solving TSP
Greedy Algorithm

The main idea behind a greedy algorithm is local optimization. That is, the algorithm
picks what seems to be the best thing to do at the particular time, instead of considering the
global situation.

Hence it is called "greedy" because a greedy person grabs anything good he can at the
particular time without considering the long-range implications of his actions.

In some situations, when the optimal solution is too expensive, a greedy algorithm may
be able to come up with an OK solution.

A Hamiltonian cycle of a graph G is a cycle which visits every vertex of G exactly once. For
example, given the graph:

We have 3 different possible Hamiltonian cycles:

Interestingly enough, they all have the same cost, 22, so they're all minimal. The travelling
salesman problem is to figure out a Hamiltonian cycle that is minimal.

Example of TSP using Greedy Algorithm:

Given the road map:


The greedy algorithm for an approximate solution to the travelling salesman problem is:

1. Find a minimum spanning tree T of G.

T=

2. Construct a cycle P by a clockwise traversal of T.

P=

3. Transform P into a Hamiltonian cycle C by cutting corners to avoid revisiting any vertices:

C=

The shortcut edges must exist because the graph is assumed to be complete, and the triangle
inequality guarantees that cutting corners cannot increase the cost, so c(C) <= c(P) = 2c(T).

Take any minimum Hamiltonian cycle Cmin. Deleting any edge e of Cmin gives a (skew) spanning
tree of G. Since T is a minimum spanning tree,

c(T) <= c(Cmin - {e})


<= c(Cmin)
and so c(C) <= 2c(Cmin). In other words, the Hamiltonian cycle C has no more than twice the
minimum possible cost.

Nearest Neighbour Algorithm

The nearest neighbour algorithm was one of the first algorithms used to determine a solution
to the travelling salesman problem. In it, the salesman starts at a random city and repeatedly
visits the nearest city until all have been visited. It quickly yields a short tour, but usually not the
optimal one.

These are the steps of the algorithm:

1. start on an arbitrary vertex as current vertex.


2. find out the shortest edge connecting current vertex and an unvisited vertex V.
3. set current vertex to V.
4. mark V as visited.
5. if all the vertices in domain are visited, then terminate.
6. Go to step 2.
The sequence of the visited vertices is the output of the algorithm.

You might also like