问题
Having Manhattan distance heuristic and a heuristic which takes the
greater value of (square root(x1-x2),square root(y1-y2))
How would you consider their informedness and are they admissable in searching the shortest path in a grid from a to b, where only horizontal and vertical movements are allowed ?
While testing them in all the cases the second heuristic always takes the diagonal ways and sometimes its number of discovered nodes is significantly smaller than Manhattan. But this is not always the case and this is what confuses me.
回答1:
Given current point a = (x1, y1)
and goal b = (x2, y2)
. I'll let dist1(a, b)
denote the Manhattan distance, and dist2(a, b)
denote that other heuristic which you propose. We have:
dist1(a, b) = |x1 - x2| + |y1 - y2|
dist2(a, b) = max(sqrt(|x1 - x2|), sqrt(|y1 - y2|))
Note that I changed your new proposed heuristic a bit to take the square root of absolute differences, instead of just differences, since taking the square root of a negative number would lead to problems. Anyway, it should be easy to see that, for any a
and b
, dist1(a, b) >= dist2(a, b)
.
Since both heuristics are admissible in the case of a grid with only vertical and horizontal movement allowed, this should typically mean that the greatest heuristic of the two (the Manhattan distance) is more effective, since it'll be closer to the truth.
In the OP you actually mentioned that you're measuring the ''number of nodes discovered'', and that this is sometimes smaller (better) for the second heuristic. With this, I'm going to assume that you mean that you're running the A* algorithm, and that you're measuring the number of nodes that are popped off of the frontier/open list/priority queue/whatever term you want to use.
My guess is that what's happening is that you have bad tie-breaking in cases where multiple nodes have an equal score in the frontier (often referred to as f
). The second heuristic you proposed would indeed tend to prefer nodes along the diagonal between current node and goal, whereas the Manhattan distance has no such tendency. A good tie-breaker when multiple nodes in the frontier have an equal (f
) score, would be to prioritize nodes with a high real cost (often referred to as g
) so far, and a low heuristic cost (often referred to as h
). This can either be implemented in practice by explicitly comparing g
or h
scores when f
scores are equal, or by simply multiplying all of your heuristic scores by a number slightly greater than 1
(for instance, 1.0000001
). For more on this, see http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html#breaking-ties
来源:https://stackoverflow.com/questions/42625661/distance-metric-heuristic-informedness