Two parameters

An estimate borrowed from an easier problem

On a grid where every step costs one, the straight-line distance to the goal cuts a search from 543 cells to 325. On terrain where steps cost between one and nine it cuts 1,572 to 1,550, because it still believes every step costs one. Four exact distance tables, computed once, cut the same search to 252 — and cost 6,328 reads to build, so they pay for themselves on the fifth query.

The precondition on a function the caller writes measured A* as a dial. A search guided by an estimate of the remaining distance expands fewer vertices than one guided by nothing, returns the same path so long as the estimate never overestimates, and trades path quality for fewer expansions once the estimate is scaled past that point. It left one thing unexamined: where the estimate comes from. Every search on that page used the same one, the straight-line distance on the grid, and it happened to be a good estimate on the grid it was used on.

It is not a good estimate in general, and the reason it is good when it is good is worth stating precisely, because the same reason says what to use instead.

The straight line is the answer to an easier problem

An admissible estimate has to be a lower bound on the true remaining distance from every vertex. The standard way to produce one is to relax the problem — remove a constraint, so that the problem becomes easy to solve exactly — and use the exact answer to the easier problem as the estimate. Removing constraints can only make paths shorter, so the easier problem’s answer is always a lower bound on the harder one’s.

The Manhattan distance on a grid is that construction with two constraints removed. It is the exact shortest path on the same grid with the walls deleted and every step costing one. On a maze whose steps really do cost one, only the first relaxation is doing any damage: the estimate is wrong exactly where a wall forces a detour, and right everywhere else. That is why it works.

The same 30 × 30 grid searched three ways: 543, 325, 71 cells expandedA grid with 254 cells removed, searched from the top-left corner to the bottom-right, shaded by the order in which each cell was taken off the queue — pale early, dark late. The left panel adds nothing to a vertex's key and is Dijkstra's algorithm; it expands 543 cells. The middle adds the straight-line distance to the goal, which can never exceed the true remaining cost, and expands 325 for a path of the same length, 58. The right doubles that estimate, expands 71, and returns a path of 64 — longer, and guaranteed to be within a factor of two.No estimate543 cells expanded · path 58Straight-line estimate325 cells expanded · path 58Estimate doubled71 cells expanded · path 64V = 900, E = 895, every edge costs onethe estimate is a function of the vertex, supplied by the caller
Fig. 1 The case where the straight line is a good estimate: a 30 × 30 grid with 254 cells removed and every step costing one, searched from corner to corner and shaded by the order cells were taken off the queue. Dijkstra’s algorithm, with no estimate, expands 543 cells. Adding the straight-line distance expands 325 and finds the same path of 58. Doubling the estimate expands 71 and returns a path of 64, which is the trade the earlier rung measured.

Once the problem’s costs are not all one, the second relaxation starts doing damage too, and it does it everywhere at once. If a step costs between one and nine, the true remaining distance from any cell is roughly five times the number of steps left, and the straight-line estimate still reports the number of steps. It is admissible — nothing it says is too high — and it is about a fifth of the truth.

An estimate that is uniformly a fifth of the truth guides a search about as much as no estimate at all. A* orders its queue by distance travelled plus estimate remaining, and when the estimate is small against the distance travelled, the order is decided by the distance travelled — which is Dijkstra’s order.

Why a fifth of the truth buys almost nothing

It is worth being precise about why an estimate that is merely too small by a constant factor is nearly useless, because “admissible” sounds like a guarantee of some benefit and gives none.

A* with an admissible estimate expands every vertex whose distance travelled plus estimate is below the cost of the shortest path, CC^*, and possibly some on the boundary. With no estimate that is every vertex closer than CC^* — a disc of radius CC^* around the source, in cost. With an estimate hh, a vertex at distance gg from the source is expanded only if g+h(v)<Cg + h(v) < C^*, so the estimate removes exactly the vertices for which h(v)h(v) is large enough to push g+h(v)g + h(v) over the line.

If hh is a fifth of the true remaining distance, a vertex is pruned only if its distance from the source plus a fifth of its distance to the goal exceeds the whole path’s cost. Almost no vertex in the disc satisfies that. The ones that do are far from the goal and nearly as far from the source as the goal is — a thin crescent on the far side of the disc — and that crescent is the 22 cells the straight line saved on this terrain.

The tempting repair is to scale the estimate up by the average step cost, five, so that it is about right on average. That estimate is no longer admissible: along any route through cheap cells it overestimates, and the search may return a longer path. It is exactly the weighted search the earlier rung measured, with the weight chosen by looking at the terrain — faster, and within a factor of five of optimal rather than optimal. The largest admissible scaling of the straight line is by the cheapest step cost, which here is one, so no scaling of it helps without giving up the path. An estimate that is too small in a way that varies across the graph cannot be repaired by a constant, and the variation is the terrain.

On weighted terrain it collapses, and a landmark table does not

The same 50 × 50 grid searched three ways: 1572, 1550, 252 cells expandedA grid with 699 cells removed, every step into an open cell costing between one and nine, searched from the top-left corner to the bottom-right and shaded by the order in which each cell was taken off the queue — pale early, dark late. No estimate: 1572 cells expanded, a path of 356. Straight-line estimate: 1550 cells expanded, a path of 356. A*, landmarks: 252 cells expanded, a path of 356, after 6,328 reads building its table. The shortest path costs 356. The ringed cells are the landmarks.No estimate1572 cells expanded · path 356Straight-line estimate1550 cells expanded · path 356A*, landmarks252 cells expanded · path 356V = 2500, E = 2532, steps cost one to ninethe estimate is a function of the vertex, supplied by the caller
Fig. 2 A 50 × 50 grid with 699 cells removed and every step into an open cell costing between one and nine, searched three ways. With no estimate, 1,572 cells expanded. With the straight-line estimate, 1,550 — twenty-two fewer, for a path of the same cost, 356. With an estimate read from exact distance tables to four landmarks, 252 cells, after 6,328 reads building the tables. The ringed cells are the landmarks.

The middle panel is the collapse. Its shading is almost identical to the left panel’s: the straight-line search expands cells in nearly the order Dijkstra does, sweeping out a disc of equal cost from the corner, because the estimate is too small to pull the frontier towards the goal.

The right panel uses a different estimate, and it expands a sixth as many cells.

The estimate is built from landmarks. Choose a few vertices and compute, with an ordinary Dijkstra search from each, the exact distance from that landmark to every vertex in the graph. That table costs one full search per landmark, once. Afterwards, for any vertex vv and goal tt and any landmark LL, the triangle inequality gives

d(v,t)    d(L,t)d(L,v),d(v, t) \;\ge\; \lvert\, d(L, t) - d(L, v) \,\rvert,

because a path from LL to tt could go through vv, and a path from LL to vv could go through tt. Each landmark therefore gives a lower bound on the remaining distance, and the estimate is the largest of those bounds. It is admissible for the same reason the straight line is: it is the exact answer to an easier problem — the shortest distance between two vertices if every route had to be measured along a landmark’s shortest-path tree — and it can only be too low.

What makes it good on terrain is that the easier problem kept the terrain in it.

It is also worth seeing that the construction is not special to landmarks. Every admissible estimate used in practice is the exact solution of some relaxed problem: the straight line relaxes walls and costs, a puzzle solver’s pattern database relaxes the puzzle to a smaller puzzle and stores its exact solution, and a road router’s landmark tables relax “the best route” to “the best route measured through a landmark”. What distinguishes a good estimate from a poor one is how much of the structure that makes the real problem expensive the relaxed problem kept. The straight line kept the grid and discarded the costs; on a terrain whose difficulty is entirely in the costs it kept nothing that mattered. Two parameters are not enough either made the same observation from the other end — that a graph’s cost for an algorithm often lives in structure its size parameters do not describe — and an estimate is a summary of structure in exactly that sense. The tables were computed on the real graph with the real costs, so a landmark’s estimate knows that a region is expensive to cross, which is exactly the knowledge the straight line threw away. This collection’s theme for results of this shape is that the cost model is an input rather than a background assumption: the straight line hard-codes a cost model of one per step, and a landmark table reads the cost model from the graph.

The same comparison as a count, and what the table cost

3 searches on one grid: from 1,572 cells expanded down to 252One 50 × 50 grid with 28% of its cells removed, every step costing between one and nine, searched from corner to corner. The shortest path costs 356. No estimate: 1,572 expanded · path 356. Straight-line estimate: 1,550 expanded · path 356. A*, landmarks: 252 expanded · path 356 · 6,328 reads to build.cells expandedNo estimate1,572 expanded · path 356Straight-line estimate1,550 expanded · path 356A*, landmarks252 expanded · path 356 · 6,328 reads to buildV = 2,500, steps cost one to nine, seed 20260910shortest path 356
Fig. 3 The same three searches on the same terrain as bars. No estimate: 1,572 cells expanded. The straight-line estimate: 1,550. Landmarks: 252, and a note that building the tables took 6,328 reads. All three return the shortest path, of cost 356.

As bars, the result is stark and it is also incomplete, because one of the three searches did work before it began that the bar does not show.

The four landmark tables are four complete Dijkstra searches over the grid — 6,328 reads, where a read is a vertex settled with its adjacency scanned, the same unit an expansion is counted in. So a single query answered with landmarks cost 252 expansions plus 6,328 reads of preprocessing, which is four times what the plain Dijkstra query cost.

3 searches on one grid: from 1,572 cells expanded down to 252One 50 × 50 grid with 28% of its cells removed, every step costing between one and nine, searched from corner to corner. The shortest path costs 356. No estimate: 1,572 expanded · path 356. Straight-line estimate: 1,550 expanded · path 356. A*, landmarks: 252 expanded · path 356 · 6,328 reads to build. Each bar includes the reads spent building the estimate before the search began.cells expandedreads building the estimateNo estimate1,572 expanded · path 356Straight-line estimate1,550 expanded · path 356A*, landmarks252 expanded · path 356 · 6,328 reads to buildV = 2,500, steps cost one to nine, seed 20260910shortest path 356
Fig. 4 The same three searches with the reads spent building each estimate added to its bar. The landmark search’s bar is now the longest on the plate: 252 expansions plus 6,328 reads of preprocessing, against 1,572 for Dijkstra and 1,550 for the straight line, which needed no preprocessing at all. Charged honestly, the best estimate is the worst choice for a single query.

That is the right way to draw it for one query, and it changes the question from “which estimate is best” to “how many queries will there be”. Each landmark query saves about 1,320 expansions against Dijkstra on this terrain, and the tables cost 6,328 once, so the tables have paid for themselves after about five queries between arbitrary points — and every query after that is a sixth of the cost.

The structure paid for before the first query is this collection’s name for exactly this accounting in a different field, and where the table starts paying finds the crossing for a precomputed table in text search. Both land on the same shape as this one: a preprocessing cost proportional to the size of the data, a per-query saving, and a break-even count that is a property of the workload rather than of the method. A route planner answering millions of queries on one road network is far past the crossing. A game computing one path on a map that changes every turn is never going to reach it.

More landmarks, fewer expansions, and faster growing costs

2 searches on one grid: from 1,572 cells expanded down to 199One 50 × 50 grid with 28% of its cells removed, every step costing between one and nine, searched from corner to corner. The shortest path costs 356. No estimate: 1,572 expanded · path 356. A*, landmarks: 199 expanded · path 356 · 25,312 reads to build. Each bar includes the reads spent building the estimate before the search began.cells expandedreads building the estimateNo estimate1,572 expanded · path 356A*, landmarks199 expanded · path 356 · 25,312 reads to buildV = 2,500, steps cost one to nine, seed 20260910shortest path 356
Fig. 5 Sixteen landmarks instead of four, with preprocessing charged. The search now expands 199 cells rather than 252, and building the tables took 25,312 reads — four times as many. Quadrupling the tables removed a fifth of the remaining expansions.

The obvious next question is whether more landmarks help, and the answer is that they help less than they cost. Sixteen tables give a tighter estimate, since the maximum over more lower bounds can only be larger, and the search expands 199 cells instead of 252. But every table is a full search and a full array of distances, so the preprocessing grew in proportion to the landmark count while the per-query saving grew by 53 expansions.

The diminishing return has a geometric explanation. A landmark’s bound d(L,t)d(L,v)\lvert d(L,t) - d(L,v)\rvert is tight when vv lies on a shortest path from LL to tt — roughly, when the landmark is behind the source or behind the goal, so that the search is moving along the landmark’s tree. The first few landmarks, chosen far apart around the edge of the graph, already put one roughly behind most source-goal pairs; further landmarks mostly duplicate directions the first ones cover.

2 searches on one grid: from 1,550 cells expanded down to 284One 50 × 50 grid with 28% of its cells removed, every step costing between one and nine, searched from corner to corner. The shortest path costs 356. Straight-line estimate: 1,550 expanded · path 356. A*, landmarks: 284 expanded · path 356 · 1,582 reads to build.cells expandedStraight-line estimate1,550 expanded · path 356A*, landmarks284 expanded · path 356 · 1,582 reads to buildV = 2,500, steps cost one to nine, seed 20260910shortest path 356
Fig. 6 And one landmark against the straight line. A single table, built in 1,582 reads, already cuts the search from 1,550 cells to 284 — most of what four tables achieve. The landmark chosen is the vertex farthest from the source, which on this grid lies near the opposite corner, just behind the goal.

One landmark gets most of the way. The table is one Dijkstra search, the estimate is a single subtraction, and it cuts the search to under a fifth. It works this well on this query because the landmark was chosen as the vertex farthest from the source — which, for a search from one corner towards the other, lands very close behind the goal. A landmark behind the goal gives an almost exact estimate for every cell along the way.

That is also where the method’s weakness is. The landmarks are chosen once, and a query whose goal is not near any landmark’s line gets a much looser bound. The farthest-point rule used here works greedily: the first landmark is the vertex farthest from the source, each later one is the vertex farthest from all landmarks chosen so far, and “farthest” is measured by the same exact distances the tables hold, so choosing a landmark costs nothing beyond computing its table. The rule spreads landmarks towards the extremities of the graph, which is where a landmark can be behind the most source-goal pairs. The farthest-point rule used here spreads landmarks around the boundary of the graph so that most queries have some landmark roughly in line; a workload that concentrates its queries in one region would do better with landmarks chosen for that region, which is a statement about the queries rather than about the graph.

A different grid

3 searches on one grid: from 1,813 cells expanded down to 124One 50 × 50 grid with 28% of its cells removed, every step costing between one and nine, searched from corner to corner. The shortest path costs 360. No estimate: 1,813 expanded · path 360. Straight-line estimate: 1,790 expanded · path 360. A*, landmarks: 124 expanded · path 360 · 7,252 reads to build. Each bar includes the reads spent building the estimate before the search began.cells expandedreads building the estimateNo estimate1,813 expanded · path 360Straight-line estimate1,790 expanded · path 360A*, landmarks124 expanded · path 360 · 7,252 reads to buildV = 2,500, steps cost one to nine, seed 7shortest path 360
Fig. 7 Another terrain, from a different seed, with preprocessing charged. Dijkstra expands 1,813 cells and the straight line 1,790; four landmarks expand 124 after 7,252 reads of preprocessing. The shortest path costs 360. On this grid the landmark search examines one fifteenth of what the others do, and pays back its tables in about four queries.

The second terrain is included to check that the result is not a property of one map. The straight line again buys almost nothing — 23 cells out of 1,813 — for the same reason as before, since the terrain’s costs are drawn from the same range. The landmark estimate does even better, and the break-even count is slightly lower, because the tables cost about the same while the saving is larger.

What varies between the two grids is how well the four landmarks happen to line up with the one query. That variation is the honest error bar on the claim: a landmark estimate expands somewhere between a sixth and a fifteenth of the cells on these two maps, for this pair of corners, and nothing on this page says what the distribution over all pairs of vertices looks like.

Why the landmark estimate is consistent, not merely admissible

There is a stronger property than admissibility that the landmark estimate has, and it matters for the next rung. An estimate hh is consistent if for every arc from uu to vv with cost ww, h(u)w+h(v)h(u) \le w + h(v) — the estimate never drops by more than the cost of a step. Consistency implies admissibility, and it is what guarantees that A* never needs to take a vertex off the queue twice.

Each landmark’s bound is consistent because distances satisfy the triangle inequality: d(L,u)w+d(L,v)d(L,u) \le w + d(L,v) and d(L,v)w+d(L,u)d(L,v) \le w + d(L,u) for any arc of cost ww, so the difference d(L,t)d(L,)\lvert d(L,t) - d(L,\cdot)\rvert can change by at most ww across the arc. And the maximum of consistent estimates is consistent. So the landmark estimate inherits consistency from the metric it is computed in, which is the property a distance that is not a distance found missing from string costs that break the triangle inequality — and a search built on such a cost would lose this guarantee along with it.

The straight-line estimate is consistent too, since a step changes the Manhattan distance by exactly one and every step costs at least one. Both estimates on this page are therefore the well-behaved kind. What happens to a search with an estimate that is admissible but not consistent is a different measurement, and it is not a small change.

What the measurement leaves out

Memory. Four landmark tables on a grid of 2,500 vertices are 10,000 distances, held for as long as the estimate is wanted. On a road network with tens of millions of vertices that is the dominant cost, and landmark methods are usually described in terms of it rather than in terms of preprocessing time. The table nobody has to keep is the reminder that a precomputed table is space before it is time.

A changing graph. The tables are exact distances on the graph as it was when they were computed. If a cost rises, a landmark bound may overestimate, and an overestimating bound is no longer admissible — so a landmark method on a changing graph needs either recomputation or bounds that are deliberately loosened. The straight line has no such problem, because it never read the costs.

Search from one corner to another. Every query here crosses the whole grid, which is the case where estimates matter most. A short query between neighbouring regions expands few cells under any method, and the break-even count rises accordingly.

The unit of preprocessing. A read of a vertex during preprocessing and an expansion during a query are counted alike, which is the counted-primitive convention counting on a graph established. A real preprocessing pass is sequential and a real query is scattered, and on a machine that makes scattered access dear the break-even count falls further.

The queue. Every search on this page uses the same binary heap, and the counted work includes its comparisons. The queue decides the class showed that the queue can dominate a shortest-path search’s cost on a sparse graph, and a better estimate shrinks the queue as well as the number of expansions, since fewer vertices are ever inserted. The saving from landmarks is therefore slightly larger in comparisons than in expansions, and the plates report expansions.

Where this ladder goes next: an estimate is a reweighting

The last section named a property both estimates here have — consistency — and said what it buys: A* with a consistent estimate never takes a vertex off its queue twice. That is usually presented as a lemma. It is actually an identity, and it is worth a rung.

Replace every arc’s cost w(u,v)w(u,v) by w(u,v)+h(v)h(u)w(u,v) + h(v) - h(u). Along any path the hh terms telescope, so every path’s new cost is its old cost plus a constant that depends only on the endpoints, and shortest paths do not move. The new costs are all non-negative exactly when hh is consistent — which is exactly Dijkstra’s precondition. So A with a consistent estimate is Dijkstra’s algorithm on reweighted arcs*, and the equivalence can be checked expansion for expansion rather than argued.

The interesting half is what happens when the estimate is admissible but inconsistent. Some reweighted arcs go negative, Dijkstra’s precondition fails, and a search that does not allow vertices to be reopened can return a path that is not the shortest. The next rung measures that failure on a stated grid, measures what reopening costs to fix it, and connects the reweighting to the one the bound with a precondition needed — where the same telescoping trick, with the estimate computed rather than supplied, is what makes negative arcs safe for Dijkstra at all.

What this makes readable

Essays that name this one as a prerequisite.

Named alongside this one

Essays reaching for the same objects. Nobody chose these; they are what the concept index makes visible.

What links here

Every essay whose body links to this one.

The objects this essay names

Each one links to every other essay that touches it.

AdmissibilityBreak-evenDijkstra's algorithmHeuristic searchLandmarkLower boundPreprocessingSearch frontierShortest pathTime space tradeoffTrade offTriangle inequality