A* Algorithm for very large graphs, any thoughts on caching shortcuts?

前端 未结 9 1302
鱼传尺愫
鱼传尺愫 2021-01-30 12:37

I\'m writing a courier/logistics simulation on OpenStreetMap maps and have realised that the basic A* algorithm as pictured below is not going to be fast enough for large maps (

相关标签:
9条回答
  • 2021-01-30 13:06

    Usually A* comes along with too much memory consumption rather than time stuggles.

    However I think it could be useful to first only compute with nodes that are part of "big streets" you would choose a highway over a tiny alley usually.

    I guess you may already use this for your weight function but you can be faster if you use some priority Queue to decide which node to test next for further travelling.

    Also you could try reducing the graph to only nodes that are part of low cost edges and then find a way from to start/end to the closest of these nodes. So you have 2 paths from start to the "big street" and the "big street" to end. You can now compute the best path between the two nodes that are part of the "big streets" in a reduced graph.

    0 讨论(0)
  • 2021-01-30 13:13

    GraphHopper does two things more to get fast, none-heuristic and flexible routing (note: I'm the author and you can try it online here)

    1. A not so obvious optimization is to avoid 1:1 mapping of OSM nodes to internal nodes. Instead GraphHopper uses only junctions as nodes and saves roughly 1/8th of traversed nodes.
    2. It has efficient implements for A*, Dijkstra or e.g. one-to-many Dijkstra. Which makes a route in under 1s possible through entire Germany. The (none-heuristical) bidirectional version of A* makes this even faster.

    So it should be possible to get you fast routes for greater London.

    Additionally the default mode is the speed mode which makes everything an order of magnitudes faster (e.g. 30ms for European wide routes) but less flexible, as it requires preprocessing (Contraction Hierarchies). If you don't like this, just disable it and also further fine-tune the included streets for car or probably better create a new profile for trucks - e.g. exclude service streets and tracks which should give you a further 30% boost. And as with any bidirectional algorithm you could easily implement a parallel search.

    0 讨论(0)
  • 2021-01-30 13:16

    I think it's worth to work-out your idea with "quadrants". More strictly, I'd call it a low-resolution route search.

    You may pick X connected nodes that are close enough, and treat them as a single low-resolution node. Divide your whole graph into such groups, and you get a low-resolution graph. This is a preparation stage.

    In order to compute a route from source to target, first identify the low-res nodes they belong to, and find the low-resolution route. Then improve your result by finding the route on high-resolution graph, however restricting the algorithm only to nodes that belong to hte low-resolution nodes of the low-resolution route (optionally you may also consider neighbor low-resolution nodes up to some depth).

    This may also be generalized to multiple resolutions, not just high/low.

    At the end you should get a route that is close enough to optimal. It's locally optimal, but may be somewhat worse than optimal globally by some extent, which depends on the resolution jump (i.e. the approximation you make when a group of nodes is defined as a single node).

    0 讨论(0)
提交回复
热议问题