Admissibility, and Why A* Is Optimal
Chapter Nineteen
Syllabus topic Module 1, "admissibility"
Pages 96 to 101 of 591
In one line
A heuristic is admissible when it never guesses too high, and that one property is what makes A* return the cheapest route rather than merely a route.
In the wording a student can write in an examination: a heuristic h is admissible if for every node n,
h(n) <= h*(n)
where h(n) is the true cost of the cheapest path from n to a goal. An admissible heuristic therefore never overestimates the remaining cost; it is an optimistic estimate, or a lower bound. With an admissible h, tree-search A is guaranteed to return an optimal solution.
The definition, in three equivalent phrasings
All three appear in papers and all three mean the same thing, and being able to move between them is worth marks.
| Phrasing | Statement |
|---|---|
| Never overestimates | h(n) is at most the true remaining cost |
| Optimistic | it always thinks the goal is at least as near as it really is |
| A lower bound | h(n) is a lower bound on h*(n) |
Two consequences follow at once from the definition and are often asked. h(goal) must be 0, because the true remaining cost at a goal is 0 and nothing is at most 0 except 0 and negatives. And h(n) = 0 for every n is admissible, trivially, which is exactly why uniform cost search is a special case of A* and inherits its optimality.
Where the original word came from
Read the 1968 paper and the word is used the other way round. Hart, Nilsson and Raphael write:
We call an algorithm admissible if it is guaranteed to find an optimal path from s to a preferred goal node of s for any graph
and their Theorem 1 is:
If h(n) <=
h(n) for all n, thenAis admissible
So in the source, the ALGORITHM is what is admissible and the condition on h is the hypothesis that makes it so. Modern usage moved the adjective onto the heuristic, which is what MU prints and what this book uses. A student who reads the original will meet the older usage and should recognise it rather than conclude that something is wrong.
Proving it, on the standing map
Do not assume the straight-line heuristic is admissible. The way to establish it is to compute the true cheapest road distance from every town, which is what a uniform cost search run outwards from the goal gives, and compare.
# Is the straight-line heuristic admissible on the standing map? Do not assume it:
# compute the TRUE cheapest road distance from every town to Jalna and compare.
import heapq
ROAD = {
"Amba": {"Bori": 8, "Chinch": 7, "Erandol": 33},
"Bori": {"Amba": 8, "Chinch": 12, "Devi": 5},
"Chinch": {"Amba": 7, "Bori": 12, "Erandol": 7, "Gokul": 13},
"Devi": {"Bori": 5, "Fanas": 7, "Hivra": 9},
"Erandol": {"Amba": 33, "Chinch": 7, "Fanas": 9, "Gokul": 6},
"Fanas": {"Devi": 7, "Erandol": 9, "Hivra": 2, "Jalna": 5},
"Gokul": {"Chinch": 13, "Erandol": 6, "Jalna": 6},
"Hivra": {"Devi": 9, "Fanas": 2, "Jalna": 16},
"Jalna": {"Fanas": 5, "Gokul": 6, "Hivra": 16},
}
SLD = {"Amba": 20, "Bori": 15, "Chinch": 15, "Devi": 11, "Erandol": 8,
"Fanas": 5, "Gokul": 6, "Hivra": 3, "Jalna": 0}
def cheapest_to(goal):
"""Uniform cost search outwards from the goal: the true h* for every town."""
best = {goal: 0}
frontier = [(0, goal)]
while frontier:
g, node = heapq.heappop(frontier)
if g > best.get(node, float("inf")):
continue
for nxt, c in ROAD[node].items():
if g + c < best.get(nxt, float("inf")):
best[nxt] = g + c
heapq.heappush(frontier, (g + c, nxt))
return best
TRUE = cheapest_to("Jalna")
print("town h(n) h*(n) h <= h*? slack")
worst = None
for n in sorted(ROAD):
ok = SLD[n] <= TRUE[n]
slack = TRUE[n] - SLD[n]
if worst is None or slack > worst[1]:
worst = (n, slack)
print("%-9s %4d %7d %-8s %5d" % (n, SLD[n], TRUE[n], "yes" if ok else "NO", slack))
print()
print("admissible at every one of the %d towns: %s"
% (len(ROAD), all(SLD[n] <= TRUE[n] for n in ROAD)))
print("least accurate: %s, short by %d km" % worst)
print()
print("now break admissibility at ONE town, by 2 km, and run A* again:")
BAD = dict(SLD); BAD["Fanas"] = 7 # the truth is 5
print(" h(Fanas) = %d, h*(Fanas) = %d, admissible? %s"
% (BAD["Fanas"], TRUE["Fanas"], BAD["Fanas"] <= TRUE["Fanas"]))
def a_star(h):
frontier = [(h["Amba"], 0, ["Amba"])]
best = {}
while frontier:
f, g, path = heapq.heappop(frontier)
node = path[-1]
if node in best and best[node] <= g:
continue
best[node] = g
if node == "Jalna":
return g, path
for child, c in sorted(ROAD[node].items()):
heapq.heappush(frontier, (g + c + h[child], g + c, path + [child]))
return None, None
for name, h in (("the straight-line h", SLD), ("h with Fanas over by 2", BAD)):
cost, route = a_star(h)
print(" %-26s returns %d km: %s" % (name, cost, " > ".join(route)))Admissibility, and Why A* Is Optimal
town h(n) h*(n) h <= h*? slack
Amba 20 25 yes 5
Bori 15 17 yes 2
Chinch 15 19 yes 4
Devi 11 12 yes 1
Erandol 8 12 yes 4
Fanas 5 5 yes 0
Gokul 6 6 yes 0
Hivra 3 7 yes 4
Jalna 0 0 yes 0
admissible at every one of the 9 towns: True
least accurate: Amba, short by 5 km
now break admissibility at ONE town, by 2 km, and run A* again:
h(Fanas) = 7, h*(Fanas) = 5, admissible? False
the straight-line h returns 25 km: Amba > Bori > Devi > Fanas > Jalna
h with Fanas over by 2 returns 26 km: Amba > Chinch > Erandol > Gokul > JalnaAdmissibility, and Why A* Is Optimal
Two kilometres of over-optimism at one town out of nine costs the optimal answer. That is how tight the condition is, and it is why the word appears in MU's own label. Admissibility is not a nicety; it is the hypothesis of the theorem, and losing it loses the conclusion immediately.
Why the straight-line distance is admissible without checking every town
The program checked nine towns. The general argument is two lines and is what makes the heuristic safe on a map of nine thousand towns.
Every road between two towns is at least as long as the straight line between them, because a straight line is the shortest path between two points. So any journey by road from n to the goal is at least as long as the straight line from n to the goal. Therefore the straight-line distance is at most the cheapest road distance, which is the definition.
That is the argument the 1968 paper itself gives, in its own example of cities connected by roads, and it is also the general reason relaxation works: the straight line is the exact answer to the relaxed problem in which you may fly.
It depends on a property of the map, not of geometry. If a road could be shorter than the straight line, the argument fails. The standing map was built with every winding factor at least 1 precisely so that it holds, and that construction is declared in Formulating a Problem for Search rather than assumed here.
The proof that A* is optimal
Tree search, admissible h. Proof by contradiction, and it is short enough to reproduce in an examination.
Suppose A returns a suboptimal goal node t, with g(t) greater than C, the cost of an optimal solution.
- Let
nbe a node on an optimal path that is still on the frontier at the momenttis selected. Such annmust exist: the start is on the optimal path, and the optimal path's nodes cannot all have been expanded, because then the optimal goal would have been generated and, being cheaper, would have been selected beforet. - Because
nis on an optimal path,g(n)is the true cheapest cost ton, and the remaining cost fromnish(n). Sog(n) + h(n) = C*. - By admissibility,
h(n) <= h(n). Sof(n) = g(n) + h(n) <= g(n) + h(n) = C*. - For the goal
t,h(t) = 0, sof(t) = g(t), which by assumption is greater thanC*. - Hence
f(n) <= C < f(t), sonhad a strictly smallerfthantandAwould have selectednrather thant. That contradicts the assumption.
Admissibility, and Why A* Is Optimal
Step 3 is the only place admissibility is used, and it is used exactly once. That is the answer to "where does admissibility come in": it is what lets f(n) be bounded above by C* for a node on the optimal path, and everything else is bookkeeping.
Step 4 uses h(goal) = 0. A heuristic that reported a positive value at the goal would break the proof at that step, which is why that requirement is part of the definition and not a convention.
Optimally efficient, which is a different and stronger claim
The 1968 paper proves something beyond optimality, and it is worth knowing because it explains why nothing has replaced A*.
Section III shows that A is not only admissible but optimal in the sense that no other admissible algorithm expands fewer nodes using the same information. The paper's own words: A is not only admissible but optimal, in the sense that no other admissible algorithm expands fewer nodes.
The claim has a condition, the paper's consistency assumption, and that condition is the whole of the next chapter. What it means in practice: given the same heuristic, any algorithm that guarantees an optimal answer must expand every node whose f is below C, because any one of them might hide a cheaper route, and A expands exactly those and no more. There is no cleverer ordering to be found.
What admissibility does not give you
Three things it is routinely assumed to guarantee and does not.
It does not make A fast. The 8-puzzle heuristic h0 = 0 is admissible and makes A into uniform cost search. Admissibility guarantees the answer, not the work.
It does not survive graph search on its own. With a reached set that never reconsiders a settled node, an admissible but inconsistent heuristic can make A* return a suboptimal route. That is the next chapter, and it is why MU prints both words.
It does not mean the estimate is good. Look at the slack column: the heuristic is short by 5 km at Amba and by 4 at three more towns. It is admissible everywhere and mediocre in several places.
Distinctions
| Admissible | Consistent | |
|---|---|---|
| Condition | h(n) <= h*(n) | h(n) <= cost(n, n') + h(n') for every edge |
| A condition on | each node separately | each EDGE |
Guarantees optimality of A* in | tree search | graph search |
| Which is stronger | weaker | stronger: consistency implies admissibility |
h(n) | h*(n) | |
|---|---|---|
| Is | the estimate we compute | the true cheapest remaining cost |
| Known at search time | yes, cheaply | no, that is the whole problem |
| Admissibility says | h is at most h* |
Admissibility, and Why A* Is Optimal
| Admissible heuristic (modern) | Admissible algorithm (1968) | |
|---|---|---|
| The adjective describes | h | the search algorithm |
| Means | never overestimates | guaranteed to find an optimal path |
| Used by | MU's syllabus and this book | Hart, Nilsson and Raphael |
What it does not mean
Admissible does not mean accurate. It means never too high. A heuristic can be admissible and useless, and h = 0 is the extreme case.
It is not a property of the algorithm in modern usage, although it was in 1968. Both usages exist and mean different things.
It does not require h to be a lower bound on the cost of the particular path found. It is a lower bound on the cost of the CHEAPEST remaining path, which is a smaller number and therefore a stronger requirement.
Overestimating a little is not a little wrong. Two kilometres at one town lost the optimal route on a nine-town map. The guarantee is all or nothing.
Admissibility alone is not enough for graph search. The commonest error on this topic, and the reason the next chapter exists.
Quick revision
- Admissible:
h(n) <= h*(n)at every node. Never overestimates; optimistic; a lower bound. - Two consequences:
h(goal) = 0, andh = 0everywhere is admissible, which makes uniform cost search a special case ofA*. - Straight-line distance is admissible because no road is shorter than the straight line, so no road journey is shorter than flying. That argument, and this book's map, are both in the 1968 paper's own example.
- Proved on the standing map by computing
h*at all nine towns. Slack ranges from 0 at Fanas and Gokul to 5 at Amba. - Breaking it by 2 km at one town changes the answer from 25 km to 26 km. The guarantee is all or nothing.
- The proof: if
Areturned a suboptimalt, some nodenon the optimal path is still on the frontier,f(n) = g(n) + h(n) <= g(n) + h(n) = C* < g(t) = f(t), sonwould have been chosen. Admissibility is used once, in the middle inequality. - Optimally efficient: no admissible algorithm using the same heuristic expands fewer nodes, subject to the consistency assumption.
- Admissibility does not give speed, and does not suffice for graph search.
Test yourself
1. Define an admissible heuristic. A heuristic h is admissible if h(n) is at most h*(n), the true cost of the cheapest path from n to a goal, at every node n. It never overestimates the remaining cost.
2. Show that h(n) = 0 for all n is admissible, and say what A becomes. True remaining costs are never negative, so 0 is a lower bound everywhere and the heuristic is admissible. A then orders on g alone, which is uniform cost search.
Admissibility, and Why A* Is Optimal
3. Why is straight-line distance admissible on a road map? Because a straight line is the shortest path between two points, so every road is at least as long as the straight line between its ends, and therefore any road journey from a town to the goal is at least the straight-line distance. The estimate is thus never above the true cost.
4. Prove that A with an admissible heuristic returns an optimal solution in tree search. Suppose it returns t with g(t) greater than the optimal cost C. Some node n on an optimal path remains on the frontier, and for it g(n) + h(n) equals C. By admissibility h(n) is at most h(n), so f(n) is at most C. Since h(t) is 0, f(t) equals g(t), which exceeds C*. So f(n) is less than f(t) and n would have been selected instead, a contradiction.
5. Where exactly is admissibility used in that proof, and what would happen without it? Only in the step bounding f(n) by C. Without it h(n) could exceed h(n), f(n) could exceed C, and there would be nothing to stop A selecting the dearer goal first.
6. This chapter overestimated one town's heuristic by 2 km out of nine towns. What happened, and what does it show? A* returned 26 km by Chinch, Erandol and Gokul instead of the optimal 25 km by Bori, Devi and Fanas. It shows that the guarantee is all or nothing: a small violation at a single node is enough to lose the optimal answer.
7. Does admissibility guarantee that A* is optimal in graph search? Explain. No. With a reached set that never reconsiders a state already settled, an admissible but inconsistent heuristic can cause a suboptimal route to be returned, because a state can be closed by an expensive route before the cheap route to it is found. Graph search needs consistency, or else the ability to reopen closed nodes.
The rest of this subject
These notes are cut from the University's printed syllabus. Open the syllabus itself, or the past papers, for the same subject.