Search Projects

Friday, April 6, 2018

OpenGL Code Traffic Signals

Presenting to you another OpenGL Code on Traffic Signals. We have already seen the Advance Traffic Signal OpenGL Program, now we will see another good program for same.


OpenGL Code Traffic Signals

Features 

The OpenGL Code  we presenting have many of the good features. Some of the features is listed below -

  1. Light Options - As in any traffic signal you will see the three lights - red, yellow and green. All the options has been implemented.
  2. Vehicles - To keep the OpenGL Code simple for all only three vehicles has been added. Though, if you like to add more do it, you are welcome.
  3. Lanes -  The right and left lane options is implemented in the program.
  4. User Interactions - Both mouse and keyboard interaction has been added to the OpenGL Code. All the user interactions has been listed in the post below.
  5. There is options to speed up the traffic is also in the code.
  6. Program has include the front page for introduction.

User Interactions

As mentioned earlier both mouse and keyboard user interaction has been added to this OpenGL Code. 
  • Keyboard Interactions
  1. Enter - From First Introduction screen to screen press Enter key at beginning.
  2. Help -  Press 'h'to get the help screen.
  3. Left to right movement - press 'l' to allow only left to right movement of traffic.
  4. Right to left movement - press 'r' to allow only right to left movement of traffic.
  5. Speed up - To speed up the traffic press 's'.
  • Mouse Interactions
  1. Left Mouse Button - This will stop the traffic as Red light gets on.
  2. Right Mouse Button (on hold) - Press right mouse button and keep on hold for yellow light. 
  3. Right Mouse Button (released) - After releasing the right mouse button the light changes from yellow to green and traffic moves.

Video Demo


Downloads

You can download the OpenGL Code from the Google Drive link.

Tuesday, April 3, 2018

Simple Travelling Salesman Problem (TSP) OpenGL Graphics Program

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.

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.