Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solving the Travelling Salesman Problem in ruby (50+ locations)

I am working in a delivery company. We currently solve 50+ locations routes by "hand".

I have been thinking about using Google Maps API to solve this problem, but I have read that there is a 24 points limit.

Currently we are using rails in our server so I am thinking about using a ruby script that would get the coordinates of the 50+ locations and output a reasonable solution.

What algorithm would you use to approach this problem?

Is Ruby a good programming language to solve this type of problem?

Do you know of any existing ruby script?

like image 375
jfanals Avatar asked Nov 23 '10 22:11

jfanals


People also ask

How do you solve traveling salesperson problems?

To solve the TSP using the Brute-Force approach, you must calculate the total number of routes and then draw and list all the possible routes. Calculate the distance of each route and then choose the shortest one—this is the optimal solution.

Has anyone solved the traveling salesman problem?

Scientists in Japan have solved a more complex traveling salesman problem than ever before. The previous standard for instant solving was 16 “cities,” and these scientists have used a new kind of processor to solve 22 cities. They say it would have taken a traditional von Neumann CPU 1,200 years to do the same task.

How many paths are there in the traveling salesman problem?

However, this is extremely time consuming and as the number of cities grows, brute force quickly becomes an infeasible method. A TSP with just 10 cities has 9! or 362,880 possible routes, far too many for any computer to handle in a reasonable time.

How Travelling salesperson problem can be solved using branch and bound?

In order to solve the problem using branch n bound, we use a level order. First, we will observe in which order, the nodes are generated. While creating the node, we will calculate the cost of the node simultaneously. If we find the cost of any node greater than the upper bound, we will remove that node.


2 Answers

This might be what you are looking for:

Warning:

this site gets flagged by firefox as attack site - but I doesn't appear to be. In fact I used it before without a problem

[Check revision history for URL]

rubyquiz seems to be down ( has been down for a bit) however you can still check out WayBack machine and archive.org to see that page: http://web.archive.org/web/20100105132957/http://rubyquiz.com/quiz142.html

like image 138
konung Avatar answered Sep 20 '22 04:09

konung


Even with the DP solution mentioned in another answer, that's going to require O(10^15) operations. So you're going to have to look at approximate solutions, which are probably acceptable given that you currently do them by hand. Look at http://en.wikipedia.org/wiki/Travelling_salesman_problem#Heuristic_and_approximation_algorithms

like image 27
moinudin Avatar answered Sep 20 '22 04:09

moinudin