 <p>This is not a trivial problem at all.</p> <p>One method you might find useful is pre-processing the data so that it can be represented in the form of a directed graph. You then assign appropriate costs to each leg depending on the desirability of taking that path from the point of view of the user (eg. how much does it cost to travel on the path in terms of dollars, time, distance, etc.) Having done this, you can apply algorithms such as Dijkstra's Algorithm to determine the best path for the user to take.</p>