Presenting the Travelling Salesman Problem (TSP) OpenGL Graphics Program in C++ language.

Many students looking for OpenGL Graphics Program for Travelling Salesman Problem (TSP), so we came up with it.

### What is Travelling Salesman Problem (TSP)?

The Traveling Salesman Problem is problem where a traveler (or salesman) have to visit given no of cities, with known distance. Salesman have to visit each city once with and return to origin city with shortest possible distance.

The TSP is np-hard problem, where we have to optimized all the possible combinations.

In Computational world we solve this problem with two techniques - 1. Brute Force Approach and 2. Dynamic Programming.

Read the Dynamic Programming Approach for TSP.

The TSP is np-hard problem, where we have to optimized all the possible combinations.

**Solutions****How to solve this problem?**

In Computational world we solve this problem with two techniques - 1. Brute Force Approach and 2. Dynamic Programming.

**1. Brute Force Approach**- If we have n, no of cities then by brute force approach we will get (n-1)! permutations. We calculate cost (distance) of every permutation and record minimum cost for it. Finally return the permutation with minimum cost. The time complexity for this method is n!.**2. Dynamic Programming -**In this method we create the cost matrix and find the minimum cost.Read the Dynamic Programming Approach for TSP.

### Our Travelling Salesman Problem OpenGL Program

In our program we have restricted ourself to a maximum of 10000 cities. So, at begining user have to input the no of cities subjected to restriction, as mentioned. Each cities are represented as points. Lines joining the cities represent the distance. In initial setup the program creates sequence from the input, then distance is calculated. The swap and iterations are performs on the cities to find out the minimum distance.
You can see the image below -

### User Interaction

The initial distance is calculate at the beginning after user enter the no of cities in command line.

Next, there is two options for user -

**key 's'**and**key 'a'**.
When key

**'s'**is pressed, two cities are selected randomly and swapped only when distance is minimum. This is performed as many times as**'s'**is pressed and distance calculated after swamp is shown in command line.
Pressing

**'a'**, the swapping performed as many times for different cities(all). After performing each iterations the distance is shown in command line and finally it shows the minimum possible distance. Though this may not be the shortest path or minimum distance covered but optimal solution.
Download the source code from the Github. Watch Video Demo below.