if you want your heuristic to be valid, you must have h(n) <=h*(n)
for each node n
, where h*
is the real value of the target. In your case, you want:
h(A) <= 4
h(C) <= 3
h(G) <= 0
, , h(G) = 0
h(n) <= cost(n, c) + h(c)
, node c
node c
. ,
h(A) <= 1 + h(C)
h(C) <= 3 + h(G) = 3
, h(C) <= 3
, h(A) > 1 + h(C)
. , , :
h(A) > 1 + h(C)
h(C) <= 3
h(G) = 0
.
h(A) = 4
h(C) = 1
h(G) = 0
.