AI Wiki中文/EN

Admissible heuristics

可采纳与一致启发式

Construct and audit lower bounds, separate admissibility from consistency, and combine estimates without double counting.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

A useful estimate needs a promise

A route planner says the destination is “at least four minutes away.” That claim has a different job from predicting an average arrival time. A search algorithm may use it to discard a route. One overestimate can make that discarded route the best one.

An admissible heuristic is a lower bound on the cheapest remaining cost. Its value can be inaccurate in the downward direction. Zero is safe for nonnegative costs, though it gives the search little guidance. Berkeley’s CS188 notes introduce this lower-bound condition and combine admissible estimates with a maximum. CS188, sections 1.4.4–1.4.5

This chapter studies how to construct and check that promise. The mechanics of expanding a priority queue are in A*. A good exercise here is to invent a heuristic, then try to break it before giving it to a solver.

Global lower bounds and local consistency

Use a finite directed graph with nonnegative edge costs c(u,v)c(u,v) and one goal GG. Let h∗(u)h^*(u) denote the true cheapest cost from uu to GG, with infinity for an unreachable goal. We require finite nonnegative estimates and h(G)=0h(G)=0. Admissibility means

0≤h(u)≤h∗(u).0\le h(u)\le h^*(u).

Consistency adds an inequality for each directed edge:

h(u)≤c(u,v)+h(v).h(u)\le c(u,v)+h(v).

The local condition implies the global one. Apply it repeatedly along any route to GG: intermediate estimates cancel, leaving h(u)h(u) no larger than that route’s cost plus h(G)h(G). Minimize over routes. For unreachable vertices the upper bound is infinity, so any finite estimate passes admissibility, even if it gives no clue about the dead end. Poole and Mackworth discuss the edge condition as the monotone restriction and connect it to safe multiple-path pruning. Foundations of Computational Agents, section 3.7.2

The converse fails. Take S→A with cost 3, S→B with cost 1, B→A with cost 1, and A→G with cost 2. Our chosen values are:

Vertexh∗h^*hh
S44
B33
A20
G00

Every estimate is a lower bound. But S→A violates 4≤3+04\le3+0, and B→A violates 3≤1+03\le1+0. A* implementations that permanently close expanded states need stronger conditions than this heuristic supplies; a version that reopens improved states can still use an admissible inconsistent heuristic under its search assumptions.

There is a useful algebraic check. Define a reweighted edge cost:

ch(u,v)=c(u,v)+h(v)−h(u).c_h(u,v)=c(u,v)+h(v)-h(u).

Consistency says exactly that every reweighted edge is nonnegative. On a route PP from S to G, the estimate terms telescope:

ch(P)=c(P)+h(G)−h(S).c_h(P)=c(P)+h(G)-h(S).

All routes between these fixed endpoints receive the same offset, so their cost ordering is preserved. For the inconsistent example, the two offending reweighted edges have costs −1 and −2. This explains why importing Dijkstra’s settled-state argument without checking consistency can fail. Reweighting is an interpretation of the condition, not permission to run ordinary Dijkstra on negative edges.

Audit a finite graph against exact distances

The complete program below computes distances to the goal with Dijkstra on reversed edges. It then reports overestimating vertices and inconsistent original edges separately. Costs and estimates are nonnegative Python integers; booleans, floats and a nonzero goal estimate are rejected. Missing estimates default to zero. Neighbor sequences must be repeatable because the graph is inspected twice.

Vertices may occur as keys, edge destinations, heuristic keys, or the supplied goal. A heuristic-only vertex is treated as isolated. The serial heap counter avoids comparing different vertex-ID types when distances tie. X is an isolated vertex in the example; its estimate 99 is admissible because its true goal distance is infinity.

from heapq import heappop, heappush
from itertools import count
from math import inf


def audit_heuristic(graph, goal, heuristic):
    # Finite graph; repeatable edges; nonnegative integer costs and estimates.
    nodes = set(graph) | {goal} | set(heuristic)
    reverse = {}
    for u, edges in graph.items():
        for v, cost in edges:
            if type(cost) is not int or cost < 0:
                raise ValueError('edge costs must be nonnegative integers')
            nodes.add(v)
            reverse.setdefault(v, []).append((u, cost))
    h = {u: heuristic.get(u, 0) for u in nodes}
    if any(type(value) is not int or value < 0 for value in h.values()):
        raise ValueError('estimates must be nonnegative integers')
    if h[goal] != 0:
        raise ValueError('the goal estimate must be zero')
    distance = {u: inf for u in nodes}
    distance[goal] = 0
    serial = count()
    heap = [(0, next(serial), goal)]
    while heap:
        d, _, v = heappop(heap)
        if d != distance[v]:
            continue
        for u, cost in reverse.get(v, ()):
            candidate = d + cost
            if candidate < distance[u]:
                distance[u] = candidate
                heappush(heap, (candidate, next(serial), u))
    over = {u for u in nodes if h[u] > distance[u]}
    violations = [(u, v, cost) for u, edges in graph.items()
                  for v, cost in edges if h[u] > cost + h[v]]
    return {'distance': distance, 'overestimates': over,
            'inconsistent_edges': violations}


graph = {'S': [('A', 3), ('B', 1)], 'B': [('A', 1)],
         'A': [('G', 2)], 'G': [], 'X': []}
h = {'S': 4, 'B': 3, 'A': 0, 'G': 0, 'X': 99}
report = audit_heuristic(graph, 'G', h)
assert report['distance'] == {'S': 4, 'B': 3, 'A': 2, 'G': 0, 'X': inf}
assert report['overestimates'] == set()
assert set(report['inconsistent_edges']) == {('S', 'A', 3), ('B', 'A', 1)}
assert audit_heuristic(graph, 'G', {'A': 3})['overestimates'] == {'A'}
print('Admissible, but inconsistent on two edges.')

The output identifies an admissible heuristic with two inconsistent edges. It also checks that setting A’s estimate to 3 is an actual overestimate. An empty inconsistency list certifies every edge of the supplied graph, provided the graph and estimates stay fixed. Passing a sample of edges would certify only that sample.

For VV vertices and EE stored edges, this implementation takes O((V+E)log⁡(V+E+2))O((V+E)\log(V+E+2)) time under constant-time arithmetic and hash operations. Its lazy heap can retain outdated entries, so reverse adjacency, heap and output together can require O(V+E)O(V+E) auxiliary storage. On an implicit puzzle too large to enumerate, computing h∗h^* first would defeat the point of a heuristic. Use a construction proof there; reserve exhaustive audits for small instances and regression checks.

Build bounds that survive composition

One construction is to remove a constraint. In a sliding-tile puzzle, allow a tile to move to an adjacent square even when that square is occupied. Count moves of the numbered tiles, excluding the empty square. The resulting Manhattan-distance sum is a lower bound: every real move moves just one numbered tile by one grid step. The relaxed task can finish earlier, but cannot require more work than the original task. Korf and Felner describe both the relaxation and independent-subproblem interpretations. Disjoint Pattern Database Heuristics, section 2.1

For a more general abstraction ϕ\phi, check that each original transition has an abstract counterpart costing no more, and that the real goal maps to an abstract goal. Every real solution then maps to an abstract solution of no greater cost. Exact abstract goal distances give an admissible heuristic; their shortest-path inequalities also give consistency. “A simpler problem” needs this correspondence, not just fewer state variables.

For two admissible estimates, the following maximum stays below the same true cost:

hmax⁡(u)=max⁡{h1(u),h2(u)}≤h∗(u).h_{\max}(u)=\max\{h_1(u),h_2(u)\}\le h^*(u).

If both estimates are consistent, choose the index ii attaining the maximum at uu. Then hmax⁡(u)=hi(u)≤c(u,v)+hi(v)≤c(u,v)+hmax⁡(v)h_{\max}(u)=h_i(u)\le c(u,v)+h_i(v)\le c(u,v)+h_{\max}(v), so the maximum is consistent too. Direct addition has no such guarantee: two estimates of 4 for a true remaining cost of 5 sum to an invalid 8. Adding subproblem costs requires an account of which real action each subproblem charges. Pattern databases develops that account with an executable puzzle.

Try these four checks before opening the answers.

1. Does multiplying an admissible estimate by 1.5 preserve admissibility?

Answer: No. If the true cost and estimate are both 4, the new value is 6. Multiplication by a factor between 0 and 1 preserves a nonnegative lower bound. It also preserves consistency for nonnegative edge costs: scaling the old edge inequality leaves a scaled edge cost no larger than the original one.

2. An estimate has very low test-set prediction error. Is that a certificate?

Answer: No. An average error can hide a single overestimate, and unseen states are not covered. A mathematical lower-bound construction or a complete check of the intended finite graph establishes a different claim from average predictive accuracy.

3. Can an unreachable isolated vertex have estimate 99?

Answer: Yes under this definition: its true cost is infinity, and it has no outgoing edge on which to violate consistency. This does not make the solver aware that it is unreachable. The conclusion changes if the graph gains an outgoing route.

4. Repair the table without changing S, B or G.

Answer: Set A to 2. S→A now satisfies 4 ≤ 3+2, B→A satisfies 3 ≤ 1+2, and A→G satisfies 2 ≤ 2+0. S→B was already consistent. All estimates now equal their true goal distances.

A larger lower bound is not a runtime measurement

Pointwise dominance means one admissible heuristic is at least as large as another at every state. It says the lower bound is tighter. Actual search time also includes evaluating that bound, maintaining tables, handling equal-priority nodes and reopening states. Comparisons of expanded-node counts need a specified A* variant and tie rules, especially at the optimal-cost boundary.

Units matter too. Straight-line distance in meters is not a lower bound on travel time in minutes. Dividing by a valid upper bound on speed can produce a time lower bound under the route model. An average speed has no such universal guarantee.

The code uses exact integer comparisons deliberately. Floating-point tolerances change what “no violations” means. A learned heuristic or a changing road network needs a clear statement of the states, costs and version covered by its certificate. On an infinite graph, admissibility alone also does not establish termination; finite branching and cost assumptions must be considered by the search algorithm.

From a certificate to a solver

Uniform-cost search supplies the exact finite-graph audit. A* uses an estimate to order a frontier. IDA* uses it to choose cost contours. Pattern databases turns a collection of small exact problems into reusable bounds. Keep the construction proof beside the implementation: changing a move cost or an abstract goal can invalidate a previously correct table.

Make a prediction, then check

The true remaining cost is5 and two admissible estimates both equal4.Which combination remains a guaranteed lower bound?

Choose one answer

Learning objectives

  • Distinguish global lower bounds from edge consistency and prove implications by telescoping paths.
  • Audit finite-graph counterexamples and justify maximum combination and abstraction conditions.

Prerequisites & connections

Explore related knowledge →

References

  1. CS188 Textbook — Informed Search
    UC Berkeley CS188 course contributors
  2. Artificial Intelligence: Foundations of Computational Agents,3rd edition —3.7 Pruning the Search Space
    David L. Poole; Alan K. Mackworth
  3. Disjoint Pattern Database Heuristics — author manuscript dated2001-09-05
    Richard E. Korf; Ariel Felner · 2001

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-05 · Codex technical check:primary source locations,independent finite-graph and complete six-cell puzzle oracles,executed examples and bilingual comparison;no independent human peer review.

  • Compared both languages paragraph by paragraph for integer contracts,unreachable vertices,reverse distances,two inconsistent edges,reweighting,maximum proof,scaling answer and complexity conditions.
  • Ran7new independent tests:729nonnegative three-vertex graphs with16estimates each versus Floyd;full-permutation projections and Bellman table oracles;all360reachable boards and their edges.
  • Structural comparison confirms paired code,display equations,six section anchors and four answered exercises.No independent human peer review.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.