329 points · by eriknstr · 9y ago · 72 comments
JPS by itself (not JPS+ in this video) is notable for not requiring any precomputation to achieve some speedup.
If you're willing to precompute some things, there are lots of other techniques available for unweighted grid maps. http://www.cs.du.edu/~sturtevant/papers/GPPC-2014.pdf has an overview of techniques and some benchmarks that use real-world game maps (Baldur's Gate, Dragon Age).
I believe the "goal bounding" from the video is called "arc flags" in the literature.
https://ad-wiki.informatik.uni-freiburg.de/teaching/Efficien...
It pre-computes all the paths from all nodes to all nodes, and it's incredibly efficient.
Most awesome algorithm ever :D
https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorit...
Mostly used for drone/rover/robot navigation in open environments, with the graphs evolving as the robot discover the environment.
D* can be pathologically slower than repeated A* searches under such conditions.
The pre-computation JPS(+) does is cheating because it's essentially providing a quicker-to-evaluate heuristic than A* gets to use.
So yes, I agree - the title is misleading! However, it's still a pretty cool efficiency for situations where it's applicable.
And of course there's a serious down-side: if the graph changes at runtime (eg. player builds a new door, or blows away a bridge) the preprocessing has to be redone, and it's not cheap.
With respect to the techniques that require precomputation, however, I wonder how they perform with such moving obstacles. Potentially quite terribly, I imagine.
Previous HN thread: https://news.ycombinator.com/item?id=9714774
That being said there's an important gotcha, those techniques require a significant amount of precomputations (especially the bounding box one) so it might not be practical if you have very dynamic maps.
They may not solve all your problems or even any of them (hard to tell knowing nothing about your game, after all), but I was absolutely dumbfounded when I played around with them at how cheaply you can get some rather complex (seeming) behaviors (e.g. put the player and some enemies in a maze, give the players a scent that strongly attracts the enemies, but also give them a slight scent that makes them repulse each other, and they'll automagically split up and surround the player).
At the very least, if you're stuck with what you're doing at the moment, play around with those, and maybe you can at least find a use for them that frees up some processing resources for precise path finding where nothing short of it will do.
All shortest paths are either a straight line, or consist of the straight line from the original location to an outside corner, a series of straight lines between outside corners, and a straight line from an outside corner to the destination. (An outside corner is any 2x2 square with three walkable and one wall tile.)
You can easily find all the outside corners. You can find which pairs of outside corners can be walked between using N^2 ray casts. Once you've done that, you can detect when an outside corner has been removed and drop it from the map, or detect when one has been created and perform N ray casts to add it to your pathing list.
Running A* on the resulting structure is really fast, because it's smaller and more connected than a tile list. The slowest remaining part is finding the corners immediately reachable from your start/end points, which I think could also be sped up but I'd benchmark it before worrying about that.
I would say that you have the causation reversed: we just don't bother doing large matrix multiplications, because they're so expensive (and yet still don't usually cross the intercepts into making the "better" algorithms worth it, due to those algorithms having ridiculous constant coefficients.)
I would love to run Floyd-Warshall on my 40-million point network graph—but it just ain't gonna happen.
Jon Bentley had an article on two string reversal algorithms with the same algorithmic complexity. On a very large string, one would finish almost immediately; the other was pessimal for paged virtual memory and wouldn't finish for hours.
The basic idea of landmarks is that you choose a small number of landmarks (e.g. four corners of a map) and for every landmark, you pre-compute the distances to every node. You can then use this information to get a lower-bound for the distance to the target via the triangle inequality: d(p,t) >= |d(p,LM) - d(t,LM)|.
This is obviously weaker than the goal bounding explained in the video, but the precomputing only takes O(n). We used it quite successfully in a global router (for EDA), where the heuristic lower-bound is often much better than a standard A-star heuristic based on geometric distances, because edges could have wildly different costs.
And yes, A* & landmarks is really nice :) !
Global routing is a high-level routing approach: routing millions of nets (= connections usually between 1 output pin of a gate and N input pins of other gates) on a grid graph with potentially billions of nodes is an extremely difficult Steiner tree problem.
To get good solutions, a common approach is to first solve the problem on a much coarser graph where edges have capacities. I.e. instead of having to place all connections disjointly, edges in the graph can accommodate a number of parallel connections.
A later detailed routing step will produce the actual disjoint routes while following the outline that was obtained during global routing.
There are certainly things you shouldn't delegate to an autorouter, but in the same way, the trend towards hair-shirt-wearing insistence that everything be done manually is a productivity cost.
It's no different to programmers who insist on hand-optimizing assembler: Rarely necessarily any more and usually done more out of ego.
The really competent engineers use the tools for the bulk of the problem, and fix up by hand where it makes sense.
1) This requires expensive precomputation. He mentioned it took 10 hours on one of the large starcraft maps. 2) (I may have misunderstood this point) This does not necessarily respond well to map changes - so in maps where you have the map changing structure (new walls, etc) you will have to run the precomputation again.
With that said, very interesting stuff coming out of Digipen.
Of course, with a specialized heuristics one could get a lot of pruning, but generally, if there is no way to come with a specialized heuristic when there is no way to have a jumping heuristic (one have to take one step at a time) and there is no way to look ahead for a specialized nodes, the A* is still the king.
But in AI almost everything is about finding a good-enough heuristic.
JPS is great. I remembered it from a former talk a while ago.
From the little experience i have with pathfinding, it seems to be an interesting topic with many little details to be explored. Like smoothing a path, smoothing/tuning a path in regards to loss of "speed" when turning, avoiding dynamic obstacles like other "agents", "flocking" of groups, various different ways of representing a "map", and probably many more.
If you want to have the best summary of routing algorithms currently available then read 'Route Planning in Transportation Networks' (2014) https://arxiv.org/abs/1504.05140
And if you want fast implementations for routing algorithms like Dijkstra, A*, CH and Landmarks check out GraphHopper: https://github.com/graphhopper/graphhopper (note: I'm one of the founders)
The boundary checking improvement would be simplified by dividing the map into islands divided by gates (per his closing remarks) limiting the damage to precalculated data from changes to the map (assuming they occur in one island at a time)
There was a paper by Microsoft Research where they find shortest path from one point to another in time equivalent to 5 memory reads + they sped up significantly the precomputation times and lowered memory requirements.