Search code examples
algorithmdijkstraa-star

Coefficients in cost function in A-star


I'd like to expand on this question :

Why does the A-star algorithm need g(n)?

Dijkstra's algorithm uses cost function f(n) = g(n) whereas A* uses cost function f(n) = g(n) + h(n), with g(n) being the cost of the path from the start node to node n, and h(n) is a heuristic function that estimates the cost of the cheapest path from node n to the goal.

It is clear from this question that A* needs its g(n) function in the cost function. My question however is the following. Can one use the cost function :

f(n) = αg(n) + (1-α)h(n)

for some alpha 0<α<1 ?

I ask because in some cases I observed it can be much faster to prioritize (through a coefficient) estimated cost over already traversed cost. I am not sure however if this still results in an optimal trajectory?

EDIT : multiplying the heuristic ℎ(𝑛) by some alpha 0<𝛼<1 is allowed, since this operation still underestimates if ℎ(𝑛) already did (which is necessary to obtain the resulting optimal path). I am more concerned about the multiplying of 𝑔(𝑛).


Solution

  • The global scale factor of f, assuming it is a positive scale, does not matter, because f is only used in a relative sense. Numbers scaled by some positive scale stay in the same order.

    Therefore, f(n) = αg(n) + (1-α)h(n) may be rewritten as f'(n) = g(n) + ((1-α)/α)h(n), which is not equal but equivalent. So while you are interested in scaling g, effectively that is equivalent to scaling h anyway, after factoring out the global scale.

    The effect is scaling the heuristic by some amount, which is OK only as long as (1-α)/α ≤ 1 (so: α ≥ 0.5), and otherwise leads to the same trouble as usual with an inadmissible heuristic.