[Routing] Getting A* to prefer Motorways

Jon Bright jon at siliconcircus.com
Sat Sep 29 17:48:54 BST 2007


Hi Marcus,

Marcus Wolschon wrote:
> 
> The heuristic at each node is to prefer ways that
> get the router near to the target just by calculating
> the distance.

That would be correct if you were looking for the shortest route.  If 
you're looking for the fastest route, you need to factor speed-of-road 
in to the calculation.  There's the maxspeed tag on some ways - for 
others, I'd suggest 120km/h for motorway, 100km/h for primary, 70km/h 
for secondary, 50km/h for unclassified and 30km/h for residential.  For 
the heuristic (which must always be optimistic), I'd suggest taking the 
haversine distance and using 120km/h (or whatever the top maxspeed is). 
  Then instead of comparing distances, you're comparing times - and the 
motorway gets preferred.

Basically, you need to adapt the heuristic to the type of route you're 
trying to achieve.  If you're trying to achieve a shortest route, your 
heuristic is correct - and so is not taking the motorway...

--
Jon





More information about the Routing mailing list