http://www.jlcomp.demon.co.uk/faq/shortest_distance.html

Thanks,

Frank

]]>Lucas

]]>3 +3+3+3 StRita/JCampbl/StRita/SisTheresa 9

3 +3+5+1 StRita/JCampbl/BrockHS/SisTheresa 9

4 +3+3+5+1 StRita/JCampbl/StRita/BrockHS/SisTheresa 12

5 +3+3+6+1+1 StRita/JCampbl/StRita/JrHigh/BrockHS/SisTheresa 14

As you can see, St Rita appears twice in the route. Any suggestions would be a great help. Thanks

]]>Greetings

Karl ]]>

The most famous algorithm to solve this problem is developed by Dijkstra.

The graph in the article is too simple to show the benefit of the algorithm, so I created my own to explain the basics of the algorithm:

http://technology.amis.nl/blog/wp-content/images/routeplangraafjeroen2.gif

First we have to pick a random path to start with. It’s not completely random (but if you implement this with a computer it is). Let’s take ABEG (yes, I know ADG is the shortest)

The length of ABEG is 5. This is the shortest path so far. From B we can also branch to H. But 1+5>5, that path is to long, no matter what it does after point H. So we can stop here.

The algorithm also deals with cycles. Take ABEIJ for example. We can loop infinitely in the cycle EIJ, but at a certain moment it’s longer than 5 and we can stop (note that you still need some kind of cycle detection if this is the branch you started with, but a simple maximum length would do the trick because you can guess that the shortest path is not more than 20)

Let’s take the ADG now. ADG is length 3, it’s less than 5 so our new shortest path is 3. When we take the branch AC it’s 3, so we can stop immediately and conclude the shortest path is 3.

But the article still can be very useful for other problems or when you need the lengths of all routes (ie. for routing algorithms of computer networks)

]]>