Travelling Salesman Problem (TSP) Using Reduced Matrix Method


The travelling salesman problem is a popular topic in AI and operational research. Since its first articulation, a plethora of publications have been written providing various solutions to this problem. Furthermore, a slew of novel formulations has been presented by associated practitioners in an attempt to broaden the application of the fundamental TSP.

Travelling Salesman Problem: Definition

Formally defined, the travelling salesman problem (TSP) is as follows -

Discover the shortest way that covers each city "precisely once and returns to the initial city" when provided with a collection of cities and distances between each city.

More On The Problem

The TSP receives a collection of n cities, where n is a positive integer bigger than 2. Each city is given a unique identification, and the physical distances connecting cities are supplied in a distance matrix, with the ith member in the matrix representing the distance from city i to j.

The TSP generates a permutation of the cities as its output, indicating the proper sequence for visiting each city. Summarizing the lengths across each subsequent couple of cities within the permutation, the route's length is determined. The aim is to identify the permutation that reduces the total distance of the route to the shortest possible length.

We will use a basic example involving four distinct towns, A, B, C, and D, for the objective of this essay. This example's distance matrix is as follows -

A

B

C

D

A

0

4

8

7

B

4

0

2

3

C

8

2

0

6

D

7

3

6

0

In this case, the TSP needs to determine the shortest path to visit each city precisely once and then return to the initial location. A to D to B to C to A is one possible path, of total length of 7 + 3 + 2 + 8 = 20. This indicates that we travel from city A to city D, next to city B, followed by city C, and ultimately back to city A.

Reduced Matrix

This method is comparable to what is known as the Branch and Bound method. The decision on the path's cost and the bound in this instance is made using the matrix reduction approach. These presumptions pertain to a reduced matrix -

  • If and only if a cost adjacency matrix row or column has a minimum of one zero element while all of its other entries are greater than or equal to zero, it is said to be reduced.

  • Only a matrix is decreased if every column and row is reduced.

  • "Tour length (old) − Total value reduced = Tour length (new)"

  • We initially replace all diagonal entries in the initial cost adjacency matrix from 0 to Infinity.

Solving TSP Using Reduced Matrix Method

The primary principle behind resolving the problem is as follows -

  • The beginning distance of reducing the matrix is the lowest feasible distance to address the "travelling salesman problem".

  • Next, in each stage, one must determine the lowest distance if that route is trailed.

  • One might do this by substituting the jth column and ith row distance by infinity, then shrinking the matrix and combining the additional distance for a decrease in the previously determined minimal route distance.

  • When a minimum of a single route distance is discovered, it is utilised as the "upper bound" of distance for applying "the branch and bound" approach to the remaining pathways, and the higher limit is restored every time another route with a reduced distance turns up.

Example

Following are the implementations of the above approach in various programming languages −

#include<iostream>
using namespace std;
int tsp_g[10][10] = {
   {17, 30, 33, 10, 25},
   {66, 22, 19, 15, 18},
   {89, 13, 8, 25, 15},
   {33, 25, 16, 30, 3},
   {25, 33, 35, 24, 37}
};
int visited[10], n = 5, cost = 0;
void travellingsalesman(int c){
   int adj_vertex = 999;
   int min_val = 999;
   visited[c] = 1;
   cout<<c + 1<<" ";
   for(int k = 0; k<n; k++){
      if (tsp_g[c][k] != 0 and visited[k] == 0){
         if (tsp_g[c][k] < min_val){
            min_val = tsp_g[c][k];
         }
            adj_vertex = k;
      }
   }
   if (min_val != 999){
      cost += min_val;
   }
   if (adj_vertex == 999){
      adj_vertex = 0;
      cout<<adj_vertex + 1;
      cost += tsp_g[c][adj_vertex];
      return;
   }
   travellingsalesman(adj_vertex);
}
int main(){
   cout<<"Shortest Path: ";
   travellingsalesman(0);
   cout<<"\nMinimum Cost: ";
   cout<<cost;
}

Output

According to the above code

Shortest Path: 1 5 4 3 2 1
Minimum Cost: 129
tsp_g = [
   [17, 30, 33, 10, 25],
   [66, 22, 19, 15, 18],
   [89, 13, 8, 25, 15],
   [33, 25, 16, 30, 3],
   [25, 33, 35, 24, 37]
]
visited = [0] * 10
n = 5
cost = 0
def travellingsalesman(c):
    global cost
    adj_vertex = 999
    min_val = 999
    visited[c] = 1
    print(c + 1, end = " ")
    for k in range(n):
        if (tsp_g[c][k] != 0 and visited[k] == 0):
            if (tsp_g[c][k] < min_val):
                min_val = tsp_g[c][k]
                adj_vertex = k
    if (min_val != 999):
        cost = cost + min_val
    if (adj_vertex == 999):
        adj_vertex = 0
        print(adj_vertex + 1, end = " ")
        cost += tsp_g[c][adj_vertex]
        return
    travellingsalesman(adj_vertex)
print("Shortest Path: ", end = " ")
travellingsalesman(0)
print("\nMinimum Cost: ", cost)

Output

Shortest Path:  1 4 5 2 3 1 
Minimum Cost:  154

The Travelling Salesman Problem: Practical Applications

The TSP has been used in the following significant ways -

  • Vehicle Routing - The TSP is commonly utilised in transportation and delivery route optimisation. This issue is important in the context of delivery firms since it helps to cut fuel use, lessen the number of trucks needed, and ensure the timely delivery of products.

  • Biology - TSP is utilised to investigate protein folding to fold into its ultimate three-dimensional structure.

  • Circuit Design - It helps identify the shortest path that minimises the circuit's overall resistance and capacitance.

Conclusion

The Travelling Salesman issue is a popular-studied optimisation issue described as determining the shortest path that visits a group of cities precisely once before returning to the starting point. There are several algorithms to solve the TSP, all have a distinct set of benefits and drawbacks. Each of these cases highlights the TSP's adaptability and its usability to tackle various situations.

Updated on: 02-Nov-2023

568 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements