Path-finding simulator for grid based games
qiao.github.com
qiao.github.com
A*, Chebyshev, Allow Diagonal:
WWWWWW
GWR
WWWWW
Optimal path should go underneath, but the simulator chooses to go over.This is a fantastic learning tool in many ways.
Edit: never mind, I didn't see all the options. Using Manhattan distance when diagonal moves are allowed causes the heuristic to be invalid, so you can make it take an L path instead of a diagonal if the diagonal path would force it to move slightly backwards at the start.
BBBBBBBBBBBBBBBB
GBR
BBBBBBBBBBBBBBBB
(switch off diagonal for stronger effect)
Shows how badly A* and best first algorithms suffer from open spaces problem and would benefit from that change. I realize that computing such heuristic exactly would be costly but even something like 2x weight for nodes already visited in straight line to the target would improve it a lot.
Dijkstra, or also known as Uniform Cost Search, will pick nodes with the lowest path cost from the queue first. This works well on graphs, but not so well on open spaces. It should be mentioned that this algorithm is complete, and optimal. That is, it will find a path if one exists, and it will find the path of lowest path cost (note there may be many such paths of equal path cost).
Then we have A, which is also complete and optimal. This uses the sum of path cost and distance heuristic. This means it will nodes closer to the goal, but long-windy paths will confuse it.
Finally we have Best First Search. It should be mentioned this is actually a family, of which Dijkstra and A are members. In this program, it only considers distance heuristic. So nodes that are geometrically closer to the goal are evaluated first. It should be mentioned that it isn't optimal - it might not find the path of lowest cost. If the optimal path requires at first winds away form the goal, these nodes aren't considered until later, or maybe never.
Can someone explain the difference here?
In this website, Best-First Search uses only the heuristic distance function (distance from current node to goal, in terms of coordinates). This means it will prioritise nodes geometrically closest to the target first. In most cases this works well, but paths with lots of twists that are close to the goal will get longer paths. This also means it isn't optimal (returns the path of lowest cost), whereas A* and Dijkstra/Uniform Cost Search are optimal.
Now Dijkstra/Uniform Cost Search only considers path cost to prioritise nodes, and A* considers the sum of path cost and heuristic. This means they do find the path of lowest cost.
As for internet routing, I do think they use Dijkstra and Bellman–Ford quite a bit.
One could use travel time (smaller roads are slower) or some more complicated weighting which could take into account the size of the road, speed limit, and even include parameters that allow the user to adjust how much it biases towards large roads (for example).
Here, Best-First Search uses geometric distance (estimated with a heuristic) from the goal to prioritise nodes. UCS uses pathcost only and A* uses the sum of pathcost and heuristic. This means this implementation of Best-First Search will expand nodes that are closest to the goal first, even if it has a high path cost. A simple example is a straight path and a path with lots of twists, with the straight path starting a few nodes further away from the goal. Best-First Search will proceed on the path with twists first, till it reaches the goal. The result of this Best-First Search isn't optimal, since the straight path is shorter. Both A* and UCS will get the shorter path (there are conditions though, UCS needs strictly positive path weights, and the distance heuristic must be an underestimate).
(That said, which one functions best as a heuristic can vary problem to problem.)