tags:

views:

2159

answers:

8

I've always been intrigued by Map Routing, but I've never found any good introductory (or even advanced!) level writeups talking about it. Does anybody have any pointers, hints, etc?

update: I'm primarily looking for pointer as to how a map system is implemented, data structures, algorithms, etc.

+9  A: 

Take a look at the open street map project 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 wiki containing stuff you might find interesting.

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.

sparkes
+1  A: 

Instead of learning APIs to each map service provider ( like Gmaps, Ymaps api) Its good to learn Mapstraction

"Mapstraction is a library that provides a common API for various javascript mapping APIs"

I would suggest you go to the URL and learn a general API. There is good amount of How-Tos too.

Thej
+3  A: 

By Map Routing, you mean finding the the shortest-path along a street network?

Dijkstra shortest-path algorithm is the best known. Wikipedia has not a bad intro http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

There's a Java applet here where you can see it in action http://www.dgp.toronto.edu/people/JamesStewart/270/9798s/Laffra/DijkstraApplet.html and Google you lead you to source code in just about any language.

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.

John McC
Maps are generally too large to allow for standard shortest path algorithms, you'll have to build some heuristics to select a subgraph. Furthermore you might use completely different, heuristic approaches (e.g. motorways first,..) to find a route.
Don Johe
+1  A: 

I've yet to find a good tutorial on routing but there are lots of code to read:

There are GPL routing applications that use Openstreetmap data, e.g. Gosmore which works on Windows (+ mobile) and Linux. There are a number of interesting [applications using the same data, but gosmore has some cool uses e.g. interface with websites.

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.

Erik Johansson
+2  A: 

Barry Brumitt, one of the engineers of Google maps route finding feature, wrote a post on the topic that may be of interest:

The road to better path-finding 11/06/2007 03:47:00 PM

Mark
+2  A: 

A* is actually far closer to production mapping algorithms. It requires quite a bit less exploration compared to Dijikstra's original algorithm.

Sargun Dhillon
Actually, modified D* is what is generally used as far as I know.
Simucal
+1  A: 

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.

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.

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.

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.

EDIT @ Spikie

As a further explanation of how to implement the pond algorithm - potential data structures needed are highlighted:

You'll need to store the map as a network. This is simply a set of nodes and edges between them. A set of nodes constitute a route. An edge joins two nodes (possibly both the same node), and has an associated cost such as distance or time 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).

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.

Label nodes starting from bottom left, going left to right and up, as A,B,C,D,E,F (F at the top).

Assume the edges can be traversed in either direction. Each edge has a cost of 1 km.

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.

We have a routine say, NextNode, that accepts a node and a cost and calls itself for each node it can travel to.

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 cost. 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.

If we hit our target node then we exit the routine too.

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.

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:

Node A - (Total) Cost 0 - From Node None
Node B - Cost 1 - From Node A
Node C - Cost 2 - From Node B
Node D - Cost 1 - From Node A
Node E - Cost 2 - From Node D / Cost 2 - From Node B (this is an exception as there is equal cost)
Node F - Cost 2 - From Node D

So the shortest route is ADF.

Jonathan Swift
@ jonathan please can you give detail of the stone in the pond algorithm and how can i apply it on a map.let say i am at a point and i want to search around in ripple before moving on to next outer ripple. and dude i know and 2 years late to the conversation
Spikie
A: 

Read up on graphs.

jms

related questions