<p>I've always been intrigued by Map Routing, but I've never found any good introductory (or even advanced!) level tutorials on it. Does anybody have any pointers, hints, etc?</p>

<p><strong>Update:</strong> I'm primarily looking for pointers as to how a map system is implemented (data structures, algorithms, etc).</p>

[{'answer_id': 2803, 'author': 'sparkes', 'author_id': 269, 'author_profile': 'https://Stackoverflow.com/users/269', 'pm_score': 5, 'selected': True, 'text': '<p>Take a look at the <a href="http://www.openstreetmap.org/" rel="noreferrer">open street map project</a> to see how this sort of thing is being tackled in a truely free software project using only user supplied and licensed data and have a <a href="http://wiki.openstreetmap.org/index.php/Main_Page" rel="noreferrer">wiki containing stuff you might find interesting</a>.</p>\n\n<p>A few years back the guys involved where pretty easy going and answered lots of questions I had so I see no reason why they still aren\'t a nice bunch.</p>\n'}, {'answer_id': 3369, 'author': 'Thejesh GN', 'author_id': 482, 'author_profile': 'https://Stackoverflow.com/users/482', 'pm_score': 2, 'selected': False, 'text': '<p>Instead of learning APIs to each map service provider ( like Gmaps, Ymaps api) Its good to learn <a href="http://www.mapstraction.com/doc/" rel="nofollow noreferrer">Mapstraction</a></p>\n\n<p>"Mapstraction is a library that provides a common API for various javascript mapping APIs"</p>\n\n<p>I would suggest you go to the URL and learn a general API. There is good amount of How-Tos too.</p>\n'}, {'answer_id': 11963, 'author': 'John Mac', 'author_id': 1050, 'author_profile': 'https://Stackoverflow.com/users/1050', 'pm_score': 3, 'selected': False, 'text': '<p>By Map Routing, you mean finding the shortest path along a street network?</p>\n\n<p>Dijkstra shortest-path algorithm is the best known. Wikipedia has not a bad intro: <a href="http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm</a></p>\n\n<p>There\'s a Java applet here where you can see it in action: <a href="http://www.dgp.toronto.edu/people/JamesStewart/270/9798s/Laffra/DijkstraApplet.html" rel="nofollow noreferrer">http://www.dgp.toronto.edu/people/JamesStewart/270/9798s/Laffra/DijkstraApplet.html</a> and Google you lead you to source code in just about any language.</p>\n\n<p>Any real implementation for generating driving routes will include quite a bit of data on the street network that describes the costs associate with traversing links and nodes—road network hierarchy, average speed, intersection priority, traffic signal linking, banned turns etc.</p>\n'}, {'answer_id': 81155, 'author': 'Erik Johansson', 'author_id': 15307, 'author_profile': 'https://Stackoverflow.com/users/15307', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve yet to find a good tutorial on routing but there are lots of code to read:</p>\n\n<p>There are GPL routing applications that use Openstreetmap data, e.g. <a href="http://wiki.openstreetmap.org/index.php/Gosmore" rel="nofollow noreferrer">Gosmore</a> which works on Windows (+ mobile) and Linux. There are a number of interesting [applications using the same data, but gosmore has some cool uses <a href="http://tile.openstreetmap.nl/~lambertus/routing-world/index.php" rel="nofollow noreferrer"> e.g. interface with websites</a>.</p>\n\n<p>The biggest problem with routing is bad data, and you never get good enough data. So if you want to try it keep your test very local so you can control the data better.</p>\n'}, {'answer_id': 81204, 'author': 'Mark', 'author_id': 3915, 'author_profile': 'https://Stackoverflow.com/users/3915', 'pm_score': 2, 'selected': False, 'text': '<p>Barry Brumitt, one of the engineers of Google maps route finding feature, wrote a post on the topic that may be of interest:</p>\n\n<p><a href="http://googleblog.blogspot.com/2007/11/road-to-better-path-finding.html" rel="nofollow noreferrer">The road to better path-finding</a>\n11/06/2007 03:47:00 PM</p>\n'}, {'answer_id': 130557, 'author': 'Sargun Dhillon', 'author_id': 10432, 'author_profile': 'https://Stackoverflow.com/users/10432', 'pm_score': 3, 'selected': False, 'text': "<p>A* is actually far closer to production mapping algorithms. It requires quite a bit less exploration compared to Dijikstra's original algorithm.</p>\n"}, {'answer_id': 139714, 'author': 'Guillermo Phillips', 'author_id': 441661, 'author_profile': 'https://Stackoverflow.com/users/441661', 'pm_score': 2, 'selected': False, 'text': "<p>From a conceptual point of view, imagine dropping a stone into a pond and watching the ripples.  The routes would represent the pond and the stone your starting position.  </p>\n\n<p>Of course the algorithm would have to search some proportion of n^2 paths as the distance n increases.  You would take you starting position and check all available paths from that point.  Then recursively call for the points at the end of those paths and so on.</p>\n\n<p>You can increase performance, by not double-backing on a path, by not re-checking the routes at a point if it has already been covered and by giving up on paths that are taking too long.</p>\n\n<p>An alternative way is to use the ant pheromone approach, where ants crawl randomly from a start point and leave a scent trail, which builds up the more ants cross over a given path.  If you send (enough) ants from both the start point and the end points then eventually the path with the strongest scent will be the shortest.  This is because the shortest path will have been visited more times in a given time period, given that the ants walk at a uniform pace.</p>\n\n<p><strong>EDIT @ Spikie</strong></p>\n\n<p>As a further explanation of how to implement the pond algorithm - potential data structures needed are highlighted:</p>\n\n<p>You'll need to store the map as a network.  This is simply a set of <code>nodes</code> and <code>edges</code> between them. A set of <code>nodes</code> constitute a <code>route</code>.  An edge joins two nodes (possibly both the same node), and has an associated <code>cost</code> such as <code>distance</code> or <code>time</code> to traverse the edge. An edge can either either be bi-directional or uni-directional. Probably simplest to just have uni-directional ones and double up for two way travel between nodes (i.e. one edge from A to B and a different one for B to A).</p>\n\n<p>By way of example imagine three railway stations arranged in an equilateral triangle pointing upwards. There are also a further three stations each halfway between them. Edges join all adjacent stations together, the final diagram will have an inverted triangle sitting inside the larger triangle.</p>\n\n<p>Label nodes starting from bottom left, going left to right and up, as A,B,C,D,E,F (F at the top).</p>\n\n<p>Assume the edges can be traversed in either direction. Each edge has a cost of 1 km.</p>\n\n<p>Ok, so we wish to route from the bottom left A to the top station F.  There are many possible routes, including those that double back on themselves, e.g. ABCEBDEF.</p>\n\n<p>We have a routine say, <code>NextNode</code>, that accepts a <code>node</code> and a <code>cost</code> and calls itself for each node it can travel to. </p>\n\n<p>Clearly if we let this routine run it will eventually discover all routes, including ones that are potentially infinite in length (eg ABABABAB etc).  We stop this from happening by checking against the <code>cost</code>. Whenever we visit a node that hasn't been visited before, we put both the cost and the node we came from against that node.  If a node has been visited before we check against the existing cost and if we're cheaper then we update the node and carry on (recursing).  If we're more expensive, then we skip the node.  If all nodes are skipped then we exit the routine.  </p>\n\n<p>If we hit our target node then we exit the routine too.</p>\n\n<p>This way all viable routes are checked, but crucially only those with the lowest cost.  By the end of the process each node will have the lowest cost for getting to that node, including our target node.</p>\n\n<p>To get the route we work backwards from our target node.  Since we stored the node we came from along with the cost, we just hop backwards building up the route. For our example we would end up with something like:</p>\n\n<p>Node A - (Total) Cost 0 - From Node None<br>\nNode B - Cost 1 - From Node A<br>\nNode C - Cost 2 - From Node B<br>\nNode D - Cost 1 - From Node A<br>\nNode E - Cost 2 - From Node D / Cost 2 - From Node B (this is an exception as there is equal cost)<br>\nNode F - Cost 2 - From Node D<br></p>\n\n<p>So the shortest route is ADF.</p>\n"}, {'answer_id': 7464631, 'author': 'Geof', 'author_id': 951678, 'author_profile': 'https://Stackoverflow.com/users/951678', 'pm_score': 1, 'selected': False, 'text': '<p>Another thought occurs to me regarding the cost of each traversal, but would increase the time and processing power required to compute.  </p>\n\n<p><strong>Example:</strong> There are 3 ways I can take (where I live) to go from point A to B,  according to the GoogleMaps. Garmin units offer each of these 3 paths in the <code>Quickest</code> route calculation. After traversing each of these routes many times and averaging (obviously there will be errors depending on the time of day, amount of caffeine etc.), I feel the algorithms could take into account the number of bends in the road for high level of accuracy, <strong>e.g.</strong> <em>straight road of 1 mile will be quicker than a 1 mile road with sharp bends in it</em>.\nNot a practical suggestion but certainly one I use to improve the result set of my daily commute.</p>\n'}, {'answer_id': 11495655, 'author': 'Graham Asher', 'author_id': 623048, 'author_profile': 'https://Stackoverflow.com/users/623048', 'pm_score': 1, 'selected': False, 'text': '<p>From my experience of working in this field, A* does the job very well. It is (as mentioned above) faster than Dijkstra\'s algorithm, but is still simple enough for an ordinarily competent programmer to implement and understand.</p>\n\n<p>Building the route network is the hardest part, but that can be broken down into a series of simple steps: get all the roads; sort the points into order; make groups of identical points on different roads into intersections (nodes); add arcs in both directions where nodes connect (or in one direction only for a one-way road).</p>\n\n<p>The A* algorithm itself is <a href="http://en.wikipedia.org/wiki/A%2a" rel="nofollow">well documented on Wikipedia</a>. The key place to optimise is the selection of the best node from the open list, for which you need a high-performance priority queue. If you\'re using C++ you can use the STL priority_queue adapter.</p>\n\n<p>Customising the algorithm to route over different parts of the network (e.g., pedestrian, car, public transport, etc.) of favour speed, distance or other criteria is quite easy. You do that by writing filters to control which route segments are available, when building the network, and which weight is assigned to each one.</p>\n'}]
['https://Stackoverflow.com/questions/2798', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/116/']