Search code examples
javaandroidshortest-pathsimulated-annealing

Shortest path using Simulated Annealing using an Android app


I am implementing an android application using different geographic coordinates and I need to solve a problem similar to the traveling salesman.

I found an implementation of the algorithm at http://www.theprojectspot.com/tutorial-post/simulated-annealing-algorithm-for-beginners/6.

I adjusted the code to what I need, and it produces theoretically optimal results. I noticed, however, that each execution produces a different type of result.

I went back to the original code and found that even in the original, there is disagreement as to the results.

Do not understand. Shouldn't the result be unique? After all, we are looking for the smallest path ... perhaps some small variation, but each execution differs by several units from the previous execution.

How could I adjust the algorithm to produce the same result in all runs? Has anyone worked with this?


Solution

  • That's the price you pay for an algorithm like this one: the results obtained might very well be different every time. The algorithm does not "find the shortest path," which is a computationally intractable problem ("travelling salesman"). Instead, it seeks to quickly find a solution that is "short enough." Whether or not it actually does so depends very much on the data ... and, to a non-trivial degree, on random chance.

    And, since the algorithm is comparatively fast, sometimes you do run it several times in a row in order to gauge the variability of the solutions obtained. If (say) three runs each produce results that are "close enough" to one another, there's a good chance that the result is reliable. But if the standard deviation is very large, the algorithm might not be giving you a good answer. (Bear in mind that sometimes the solution will be wrong.)

    So to speak: "you get what you pay for, but you don't pay much for it, and of course that is the point."